Class: Belvo::Link

Inherits:
Resource show all
Defined in:
lib/belvo/resources.rb

Overview

A Link is a set of credentials associated to a end-user access

Defined Under Namespace

Classes: AccessMode

Instance Attribute Summary

Attributes inherited from Resource

#endpoint

Instance Method Summary collapse

Methods inherited from Resource

#clean, #delete, #detail, #list, #resume

Constructor Details

#initialize(session) ⇒ Link

Returns a new instance of Link.



71
72
73
74
# File 'lib/belvo/resources.rb', line 71

def initialize(session)
  super(session)
  @endpoint = 'links/'
end

Instance Method Details

#register(institution:, username:, password:, password2: nil, options: nil) ⇒ Hash

Register a new link

Parameters:

  • institution (String)

    Institution name

  • username (String)

    End-user username

  • password (String)

    End-user password

  • password2 (String, nil) (defaults to: nil)

    End-user secondary password, if any

  • options (LinkOptions) (defaults to: nil)

    Configurable properties

Returns:

  • (Hash)

    created link details

Raises:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/belvo/resources.rb', line 84

def register(
  institution:,
  username:,
  password:,
  password2: nil,
  options: nil
)
  options = LinkOptions.from(options)
  options.certificate = Utils.read_file_to_b64(options.certificate)
  options.private_key = Utils.read_file_to_b64(options.private_key)
  body = {
    institution: institution,
    username: username,
    password: password,
    password2: password2,
    token: options.token,
    encryption_key: options.encryption_key,
    access_mode: options.access_mode || AccessMode::SINGLE,
    username_type: options.username_type,
    certificate: options.certificate,
    private_key: options.private_key
  }.merge(options)
  body = clean body: body
  @session.post(@endpoint, body)
end

#update(id:, password: nil, password2: nil, options: nil) ⇒ Hash

Allows to change password, password2 or setting a custom encryption key

Parameters:

  • id (String)

    Link UUID

  • password (String) (defaults to: nil)

    End-user password

  • password2 (String, nil) (defaults to: nil)

    End-user secondary password, if any

  • options (LinkOptions) (defaults to: nil)

    Configurable properties

Returns:

  • (Hash)

    link details

Raises:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/belvo/resources.rb', line 117

def update(id:, password: nil, password2: nil, options: nil)
  options = LinkOptions.from(options)
  options.certificate = Utils.read_file_to_b64(options.certificate)
  options.private_key = Utils.read_file_to_b64(options.private_key)
  body = {
    password: password,
    password2: password2,
    token: options.token,
    encryption_key: options.encryption_key,
    username_type: options.username_type,
    certificate: options.certificate,
    private_key: options.private_key
  }.merge(options)
  body = clean body: body
  @session.put(@endpoint, id, body)
end