Class: Dimelo::CCP::API::Client
- Inherits:
-
Object
- Object
- Dimelo::CCP::API::Client
- Defined in:
- lib/dimelo/ccp/api/client.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#default_parameters ⇒ Object
Returns the value of attribute default_parameters.
Instance Method Summary collapse
- #check ⇒ Object
- #config ⇒ Object
-
#initialize(base_uri, options = {}) ⇒ Client
constructor
A new instance of Client.
- #transport(method, path, payload = {}) ⇒ Object
Constructor Details
#initialize(base_uri, options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 |
# File 'lib/dimelo/ccp/api/client.rb', line 7 def initialize(base_uri, ={}) @base_uri = base_uri.is_a?(URI) ? base_uri : URI.parse(base_uri) = .with_indifferent_access @http_options = .delete(:http_options) || {} @default_parameters = end |
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
5 6 7 |
# File 'lib/dimelo/ccp/api/client.rb', line 5 def base_uri @base_uri end |
#default_parameters ⇒ Object
Returns the value of attribute default_parameters.
5 6 7 |
# File 'lib/dimelo/ccp/api/client.rb', line 5 def default_parameters @default_parameters end |
Instance Method Details
#check ⇒ Object
14 15 16 |
# File 'lib/dimelo/ccp/api/client.rb', line 14 def check Dimelo::CCP::API.decode_json(transport(:get, 'check')) end |
#config ⇒ Object
18 19 20 |
# File 'lib/dimelo/ccp/api/client.rb', line 18 def config Dimelo::CCP::API.decode_json(transport(:get, 'config')) end |
#transport(method, path, payload = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/dimelo/ccp/api/client.rb', line 22 def transport(method, path, payload={}) response = connection.perform(method, path, default_parameters.merge(payload)) if response.success? or response.status == 422 response.body else raise Error.from(method, path, response.status, response.body) end end |