Class: Bankin::User

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

Constant Summary collapse

RESOURCE_PATH =
'/v2/users'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

auth_delegate, collections, #collections, #fields, fields, has_collection, has_fields, has_resource, #initialize, resources, #resources

Constructor Details

This class inherits a constructor from Bankin::Resource

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/bankin/resources/user.rb', line 3

def token
  @token
end

Class Method Details

.authenticate(email, password) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/bankin/resources/user.rb', line 49

def self.authenticate(email, password)
  response = Bankin.api_call(:post, '/v2/authenticate',
    { email: email, password: password })
  user = new(response['user'])
  user.token = response['access_token']
  user
end

.create(email, password) ⇒ Object



43
44
45
46
47
# File 'lib/bankin/resources/user.rb', line 43

def self.create(email, password)
  response = Bankin.api_call(:post, RESOURCE_PATH,
    { email: email, password: password })
  new(response)
end

.delete_allObject



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

def self.delete_all
  Bankin.api_call(:delete, RESOURCE_PATH)
end

.list(options = {}) ⇒ Object



34
35
36
37
# File 'lib/bankin/resources/user.rb', line 34

def self.list(options = {})
  response = Bankin.api_call(:get, RESOURCE_PATH, options)
  Collection.new(response, self)
end

Instance Method Details

#add_item_url(redirect_url = nil, params = {}) ⇒ Object



21
22
23
24
# File 'lib/bankin/resources/user.rb', line 21

def add_item_url(redirect_url = nil, params = {})
  authenticate if token.nil?
  Item.add_url(token, redirect_url, params)
end

#delete(password) ⇒ Object



17
18
19
# File 'lib/bankin/resources/user.rb', line 17

def delete(password)
  Bankin.api_call(:delete, resource_uri, { password: password })
end

#item_connect_url(bank_id, redirect_url = nil) ⇒ Object



26
27
28
# File 'lib/bankin/resources/user.rb', line 26

def item_connect_url(bank_id, redirect_url = nil)
  Item.connect_url(token, bank_id, redirect_url)
end

#pro_confirmation_urlObject



30
31
32
# File 'lib/bankin/resources/user.rb', line 30

def pro_confirmation_url
  Item.pro_confirmation_url(token)
end