class EbanqApi::Client
This class represents client functionality.
Constants
- ERROR_CODES
Public Class Methods
new()
click to toggle source
Requests service_token for current user.
# File lib/ebanq_api/client.rb, line 28 def initialize auth_login_response = auth.login_with_token(EbanqApi.token, EbanqApi.secret) @auth_token = auth_login_response['token'] end
Public Instance Methods
accounts()
click to toggle source
Declares an accounts instance.
# File lib/ebanq_api/client.rb, line 68 def accounts @accounts ||= EbanqApi::Accounts.new(self) end
auth()
click to toggle source
Declares an auth instance.
# File lib/ebanq_api/client.rb, line 58 def auth @auth ||= EbanqApi::Auth.new(self) end
cards()
click to toggle source
Declares an cards instance.
# File lib/ebanq_api/client.rb, line 83 def cards @cards ||= EbanqApi::Cards.new(self) end
make_request(method, url, params = {})
click to toggle source
Makes a request to Ebanq REST Api.
Attributes¶ ↑
-
method
- :get or :post value -
url
- name of endpoint -
values
- values from request
Returns full body of response if no errors are found, raise error otherwise.
# File lib/ebanq_api/client.rb, line 43 def make_request(method, url, params = {}) path = "#{EbanqApi.base_url}/#{url}" response = case method when :get then get(path, headers, params) when :post then post(path, headers, params) when :put then put(path, headers, params) when :delete then delete(path, headers) else raise 'Error' end process_raw_response(response) rescue RestClient::ResourceNotFound, SocketError, Errno::ECONNREFUSED => e raise e end
messages()
click to toggle source
Declares an messages instance.
# File lib/ebanq_api/client.rb, line 78 def messages @messages ||= EbanqApi::Messages.new(self) end
news()
click to toggle source
Declares an news instance.
# File lib/ebanq_api/client.rb, line 73 def news @news ||= EbanqApi::News.new(self) end
profile()
click to toggle source
Declares an profile instance.
# File lib/ebanq_api/client.rb, line 63 def profile @profile ||= EbanqApi::Profile.new(self) end
reports()
click to toggle source
Declares an reports instance.
# File lib/ebanq_api/client.rb, line 93 def reports @reports ||= EbanqApi::Reports.new(self) end
requests()
click to toggle source
Declares an requests instance.
# File lib/ebanq_api/client.rb, line 88 def requests @requests ||= EbanqApi::Requests.new(self) end
settings()
click to toggle source
Declares an settings instance.
# File lib/ebanq_api/client.rb, line 98 def settings @settings ||= EbanqApi::Settings.new(self) end
templates()
click to toggle source
Declares an templates instance.
# File lib/ebanq_api/client.rb, line 103 def templates @templates ||= EbanqApi::Templates.new(self) end
transactions()
click to toggle source
# File lib/ebanq_api/client.rb, line 107 def transactions @transactions ||= EbanqApi::Transactions.new(self) end
Private Instance Methods
delete(path, headers)
click to toggle source
# File lib/ebanq_api/client.rb, line 132 def delete(path, headers) RestClient.delete path, headers end
get(path, headers, params = {})
click to toggle source
# File lib/ebanq_api/client.rb, line 117 def get(path, headers, params = {}) RestClient::Request.execute(method: :get, url: path, timeout: 10, headers: headers .merge!(params: params)) end
headers()
click to toggle source
# File lib/ebanq_api/client.rb, line 150 def headers headers = { content_type: 'application/x-www-form-urlencoded', accept: 'application/json' } headers.merge!(services_token: @auth_token) if @auth_token headers end
parse_failed(response)
click to toggle source
# File lib/ebanq_api/client.rb, line 145 def parse_failed(response) error = ERROR_CODES[response['code']].new(response) raise error, error.message end
post(path, headers, params = {})
click to toggle source
# File lib/ebanq_api/client.rb, line 124 def post(path, headers, params = {}) RestClient.post(path, params, headers) end
process_raw_response(raw_response)
click to toggle source
# File lib/ebanq_api/client.rb, line 136 def process_raw_response(raw_response) !raw_response.body.empty? ? process_response_body(raw_response) : {} end
process_response_body(raw_response)
click to toggle source
# File lib/ebanq_api/client.rb, line 140 def process_response_body(raw_response) result = JSON.parse(raw_response.body) success?(result['code']) ? wrap(result['response']) : parse_failed(result) end
put(path, headers, params = {})
click to toggle source
# File lib/ebanq_api/client.rb, line 128 def put(path, headers, params = {}) RestClient.put path, params, headers end
success?(code)
click to toggle source
# File lib/ebanq_api/client.rb, line 113 def success?(code) code.to_i >= 200 && code.to_i < 300 end