Class: Belvo::Resource

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

Overview

Represents a consumable REST resource from Belvo API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • session (APISession)

    current Belvo API session



15
16
17
# File 'lib/belvo/resources.rb', line 15

def initialize(session)
  @session = session
end

Instance Attribute Details

#endpointString (readonly)

Resource API endpoint

Returns:

  • (String)

    the API endpoint



12
13
14
# File 'lib/belvo/resources.rb', line 12

def endpoint
  @endpoint
end

Instance Method Details

#clean(body:) ⇒ Hash

Remove nil values from a request body

Parameters:

  • body (Hash)

    request body

Returns:

  • (Hash)

    body without nil values



22
23
24
# File 'lib/belvo/resources.rb', line 22

def clean(body:)
  body.delete_if { |_key, value| value.nil? }
end

#delete(id:) ⇒ Boolean

Delete existing resource

Parameters:

  • id (String)

    Resource UUID

Returns:

  • (Boolean)

    true if resource is successfully deleted else false



47
48
49
# File 'lib/belvo/resources.rb', line 47

def delete(id:)
  @session.delete(@endpoint, id)
end

#detail(id:) ⇒ Hash

Show specific resource details

Parameters:

  • id (String)

    Resource UUID

Returns:

  • (Hash)

Raises:



40
41
42
# File 'lib/belvo/resources.rb', line 40

def detail(id:)
  @session.detail(@endpoint, id)
end

#list(params: nil) ⇒ Array

List all results

Parameters:

  • params (Hash) (defaults to: nil)

    Extra parameters sent as query strings.

Returns:

  • (Array)

Raises:



30
31
32
33
34
# File 'lib/belvo/resources.rb', line 30

def list(params: nil)
  results = []
  @session.list(@endpoint, params: params) { |item| results.push item }
  results
end

#resume(session_id:, token:, link: nil) ⇒ Object

Resume data extraction session. Use this method after you have received a

HTTP 428 response.

Parameters:

  • session_id (String)

    Session UUID included in the 428 response

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

    Link UUID

Raises:



56
57
58
59
# File 'lib/belvo/resources.rb', line 56

def resume(session_id:, token:, link: nil)
  data = { session: session_id, token: token, link: link }
  @session.patch(@endpoint, data)
end