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.



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

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

Instance Method Details

#patch(id:, options: nil) ⇒ Hash

Patch an existing link

Parameters:

  • id (String)

    Link UUID

  • options (LinkOptions) (defaults to: nil)

    Configurable properties

Returns:

  • (Hash)

    created link details

Raises:



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/belvo/resources.rb', line 135

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) ⇒ Hash

Register a new link

Parameters:

  • institution (String)

    Institution name

  • username (String)

    End-user username

  • password (String)

    End-user password

  • options (LinkOptions) (defaults to: nil)

    Configurable properties

Returns:

  • (Hash)

    created link details

Raises:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/belvo/resources.rb', line 82

def register(
  institution:,
  username:,
  password:,
  options: nil
)
  options = LinkOptions.from(options)
  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:) ⇒ Hash

Allows to create a token with client-specified scope and short TTL.

Parameters:

  • id (String)

    Link UUID

  • scopes (String)

    Configurable scopes eg: “write_links,delete_links”

Returns:

  • (Hash)

    with a “refresh” and “access” token

Raises:



123
124
125
126
127
128
# File 'lib/belvo/resources.rb', line 123

def token(id:, scopes:)
  body = {
    scopes: scopes
  }
  @session.token(@endpoint, id, body)
end

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

Allows to change password, password2

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:



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/belvo/resources.rb', line 106

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