class Belvo::Link

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

Public Class Methods

new(session) click to toggle source
Calls superclass method Belvo::Resource::new
# File lib/belvo/resources.rb, line 71
def initialize(session)
  super(session)
  @endpoint = 'links/'
end

Public Instance Methods

patch( id:, options: nil ) click to toggle source

Patch an existing link @param id [String] Link UUID @param options [LinkOptions] Configurable properties @return [Hash] created link details @raise [RequestError] If response code is different than 2XX

# File lib/belvo/resources.rb, line 142
def patch(
  id:,
  options: nil
)
  options = LinkOptions.from(options)
  body = {
    access_mode: options.access_mode
  }.merge(options)
  body = clean body: body
  resource_path = format('%<path>s%<id>s/', path: @endpoint, id: id)
  @session.patch(resource_path, body)
end
register( institution:, username:, password:, options: nil ) click to toggle source

Register a new link @param institution [String] Institution name @param username [String] End-user username @param password [String] End-user password @param options [LinkOptions] Configurable properties @return [Hash] created link details @raise [RequestError] If response code is different than 2XX

# File lib/belvo/resources.rb, line 83
def register(
  institution:,
  username:,
  password:,
  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,
    access_mode: options.access_mode
  }.merge(options)
  body = clean body: body
  @session.post(@endpoint, body)
end
token(id:, scopes:) click to toggle source

Allows to create a token with client-specified scope and short TTL. @param id [String] Link UUID @param scopes [String] Configurable scopes eg: “read_links,write_links” @return [Hash] with a “refresh” and “access” token @raise [RequestError] If response code is different than 2XX

# File lib/belvo/resources.rb, line 130
def token(id:, scopes:)
  body = {
    scopes: scopes
  }
  @session.token(@endpoint, id, body)
end
update(id:, password: nil, password2: nil, options: nil) click to toggle source

Allows to change password, password2 @param id [String] Link UUID @param password [String] End-user password @param password2 [String, nil] End-user secondary password, if any @param options [LinkOptions] Configurable properties @return [Hash] link details @raise [RequestError] If response code is different than 2XX

# File lib/belvo/resources.rb, line 109
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,
    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