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



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

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

#detail(id:) ⇒ Hash

Show specific resource details

Parameters:

  • id (String)

    Resource UUID

Returns:

  • (Hash)

Raises:



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

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

#list(params: nil) {|Hash| ... } ⇒ Array

List all results

Parameters:

  • params (Hash) (defaults to: nil)

    Extra parameters sent as query strings.

Yields:

  • (Hash)

    Each result to be processed individually.

Returns:

  • (Array)

    List of results when no block is passed.

Raises:



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

def list(params: nil)
  @session.list(@endpoint, params: params)
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:



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

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