Class: MaponClient::Client
- Inherits:
-
Object
- Object
- MaponClient::Client
- Defined in:
- lib/mapon_client/client.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
'https://mapon.com/api/v1/'.freeze
- JSON =
'json'.freeze
- XML =
'xml'.freeze
- STRUCTURE =
'structure'.freeze
- OBJECT =
'object'.freeze
- AVAILABLE_FORMATS =
[JSON, XML, STRUCTURE, OBJECT].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#parser_class ⇒ Object
readonly
Returns the value of attribute parser_class.
-
#request_format ⇒ Object
readonly
Returns the value of attribute request_format.
-
#resource_base ⇒ Object
readonly
Returns the value of attribute resource_base.
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #append_format_to_url(*args) ⇒ Object
-
#initialize(api_key: nil, base_url: nil, format: nil) ⇒ Client
constructor
A new instance of Client.
- #with_key(params) ⇒ Object
Constructor Details
#initialize(api_key: nil, base_url: nil, format: nil) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mapon_client/client.rb', line 17 def initialize(api_key: nil, base_url: nil, format: nil) @api_key = api_key || ENV['MAPON_CLIENT_API_KEY'] @base_url = base_url || DEFAULT_BASE_URL @format = format || JSON set_request_format set_parser_class @resource_base ||= RestClient::Resource.new( @base_url, headers: { params: { key: @api_key } } ) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def base_url @base_url end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def format @format end |
#parser_class ⇒ Object (readonly)
Returns the value of attribute parser_class.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def parser_class @parser_class end |
#request_format ⇒ Object (readonly)
Returns the value of attribute request_format.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def request_format @request_format end |
#resource_base ⇒ Object (readonly)
Returns the value of attribute resource_base.
15 16 17 |
# File 'lib/mapon_client/client.rb', line 15 def resource_base @resource_base end |
Instance Method Details
#[](*args) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/mapon_client/client.rb', line 30 def [](*args) @resource_base.public_send( :[], *append_format_to_url(*args) ) end |
#append_format_to_url(*args) ⇒ Object
49 50 51 52 |
# File 'lib/mapon_client/client.rb', line 49 def append_format_to_url(*args) suburl = "#{args.shift}.#{@request_format}" args.unshift(suburl) end |
#with_key(params) ⇒ Object
45 46 47 |
# File 'lib/mapon_client/client.rb', line 45 def with_key(params) params.merge(key: @api_key) end |