Module: Bankin
- Defined in:
- lib/bankin/base.rb,
lib/bankin/error.rb,
lib/bankin/version.rb,
lib/bankin/resource.rb,
lib/bankin/collection.rb,
lib/bankin/configuration.rb,
lib/bankin/resources/bank.rb,
lib/bankin/resources/item.rb,
lib/bankin/resources/user.rb,
lib/bankin/resources/account.rb,
lib/bankin/resources/transaction.rb
Defined Under Namespace
Classes: Account, Bank, Collection, Configuration, Error, Item, Resource, Transaction, User
Constant Summary
collapse
- BASE_URL =
'https://sync.bankin.com'
- API_VERSION =
'2018-06-15'
- RATELIMIT_FIELDS =
%w(limit remaining reset)
- VERSION =
"1.0.2"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
10
11
12
|
# File 'lib/bankin/base.rb', line 10
def configuration
@configuration
end
|
Class Method Details
.api_call(method, path, params = {}, token = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/bankin/base.rb', line 24
def api_call(method, path, params = {}, token = nil)
url = Bankin.const_get(:BASE_URL) + path
log_message("#{method.upcase} #{url}")
params.each do |k, v|
next if k =~ /password/
log_message("* #{k}: #{v}")
end
request_params = {
method: method,
url: url,
headers: {
'Bankin-Version': Bankin.const_get(:API_VERSION),
params: {
client_id: Bankin.configuration.client_id,
client_secret: Bankin.configuration.client_secret
}.merge(params)
}
}
request_params[:headers][:Authorization] = "Bearer #{token}" if token
begin
response = RestClient::Request.execute(request_params)
set_rate_limits(response.)
return {} if response.empty?
data = JSON.parse(response)
return data
rescue StandardError => e
response = JSON.parse(e.response)
raise Error.new(response['type'], response['message'])
end
end
|
20
21
22
|
# File 'lib/bankin/base.rb', line 20
def configure
yield(configuration)
end
|
.log_message(msg) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/bankin/base.rb', line 68
def log_message(msg)
return if msg.nil? || msg.empty?
logger = Bankin.configuration.logger
return if logger.nil?
logger.info(msg)
end
|
.rate_limits ⇒ Object
16
17
18
|
# File 'lib/bankin/base.rb', line 16
def rate_limits
@rate_limits ||= Hash[RATELIMIT_FIELDS.map { |f| [f, nil] }]
end
|
.set_rate_limits(headers) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/bankin/base.rb', line 60
def set_rate_limits()
@rate_limits ||= {}
RATELIMIT_FIELDS.each do |field|
@rate_limits[field] = ["ratelimit_#{field}".to_sym]
end
end
|