class Oma::Ruby::Client
Client
class
Attributes
password[R]
url[R]
user[R]
Public Class Methods
new(url:, user:, password:)
click to toggle source
# File lib/oma-ruby/client.rb, line 15 def initialize(url:, user:, password:) @url = url @user = user @password = password end
Private Instance Methods
api()
click to toggle source
# File lib/oma-ruby/client.rb, line 29 def api @api ||= Faraday.new(url: url) do |connection| connection.request :json connection.adapter Faraday.default_adapter end end
api_credentials()
click to toggle source
# File lib/oma-ruby/client.rb, line 63 def api_credentials @api_credentials ||= { user: user, password: password } end
check_api_error!(response)
click to toggle source
# File lib/oma-ruby/client.rb, line 55 def check_api_error!(response) body = Oj.load(response.body) return if body['success'] raise api_error(body['error_number']), body['error'] end
check_http_error!(response)
click to toggle source
# File lib/oma-ruby/client.rb, line 49 def check_http_error!(response) return if response.status == 200 raise http_error(response.status) end
format_params(params)
click to toggle source
# File lib/oma-ruby/client.rb, line 67 def format_params(params) { credentials: api_credentials }.merge(params) end
handle_reponse(response)
click to toggle source
# File lib/oma-ruby/client.rb, line 42 def handle_reponse(response) check_http_error!(response) check_api_error!(response) Oj.load(response.body) end
request(action, params)
click to toggle source
# File lib/oma-ruby/client.rb, line 36 def request(action, params) response = api.post(action, format_params(params)) handle_reponse(response) end