Class: Fintoc::Client
- Inherits:
-
Object
show all
- Includes:
- Utils
- Defined in:
- lib/fintoc/client.rb
Instance Method Summary
collapse
Methods included from Utils
#flatten, #pick, #pluralize, #snake_to_pascal
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
12
13
14
15
16
17
18
19
|
# File 'lib/fintoc/client.rb', line 12
def initialize(api_key)
@api_key = api_key
@user_agent = "fintoc-ruby/#{Fintoc::VERSION}"
@headers = { "Authorization": @api_key, "User-Agent": @user_agent }
@link_headers = nil
@link_header_pattern = '<(?<url>.*)>;\s*rel="(?<rel>.*)"'
@default_params = {}
end
|
Instance Method Details
#delete ⇒ Object
25
26
27
|
# File 'lib/fintoc/client.rb', line 25
def delete
request('delete')
end
|
#delete_link(link_id) ⇒ Object
63
64
65
|
# File 'lib/fintoc/client.rb', line 63
def delete_link(link_id)
delete.call("links/#{link_id}")
end
|
#fetch_next ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/fintoc/client.rb', line 44
def fetch_next
next_ = ['next']
Enumerator.new do |yielder|
while next_
yielder << get.call(next_)
next_ = ['next']
end
end
end
|
#get ⇒ Object
21
22
23
|
# File 'lib/fintoc/client.rb', line 21
def get
request('get')
end
|
#get_account(link_token, account_id) ⇒ Object
67
68
69
|
# File 'lib/fintoc/client.rb', line 67
def get_account(link_token, account_id)
get_link(link_token).find(id: account_id)
end
|
#get_link(link_token) ⇒ Object
54
55
56
57
|
# File 'lib/fintoc/client.rb', line 54
def get_link(link_token)
data = { **_get_link(link_token), "link_token": link_token }
build_link(data)
end
|
#get_links ⇒ Object
59
60
61
|
# File 'lib/fintoc/client.rb', line 59
def get_links
_get_links.map { |data| build_link(data) }
end
|
#request(method) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/fintoc/client.rb', line 29
def request(method)
proc do |resource, **kwargs|
parameters = params(method, **kwargs)
response = make_request(method, resource, parameters)
content = JSON.parse(response.body, symbolize_names: true)
if response.status.client_error? || response.status.server_error?
raise_custom_error(content[:error])
end
@link_headers = response..get('link')
content
end
end
|
#to_s ⇒ Object
71
72
73
74
75
76
|
# File 'lib/fintoc/client.rb', line 71
def to_s
visible_chars = 4
hidden_part = '*' * (@api_key.size - visible_chars)
visible_key = @api_key.slice(0, visible_chars)
"Client(🔑=#{hidden_part + visible_key}"
end
|