Class: Wodify::Requester
- Inherits:
-
Object
- Object
- Wodify::Requester
- Includes:
- HTTParty
- Defined in:
- lib/wodify/requester.rb
Class Attribute Summary collapse
-
.apikey ⇒ Object
readonly
Returns the value of attribute apikey.
-
.encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
.request_data ⇒ Object
readonly
Returns the value of attribute request_data.
-
.response_data ⇒ Object
readonly
Returns the value of attribute response_data.
-
.type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .request(verb, resource, opts = {}) ⇒ Object
- .setup(apikey, env = "production", type = 'json', encoding = 'utf-8') ⇒ Object
-
.symbolize_keys(hash) ⇒ Object
recursively symbolize hash keys.
Class Attribute Details
.apikey ⇒ Object (readonly)
Returns the value of attribute apikey.
10 11 12 |
# File 'lib/wodify/requester.rb', line 10 def apikey @apikey end |
.encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
10 11 12 |
# File 'lib/wodify/requester.rb', line 10 def encoding @encoding end |
.request_data ⇒ Object (readonly)
Returns the value of attribute request_data.
10 11 12 |
# File 'lib/wodify/requester.rb', line 10 def request_data @request_data end |
.response_data ⇒ Object (readonly)
Returns the value of attribute response_data.
10 11 12 |
# File 'lib/wodify/requester.rb', line 10 def response_data @response_data end |
.type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/wodify/requester.rb', line 10 def type @type end |
Class Method Details
.request(verb, resource, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wodify/requester.rb', line 19 def request(verb, resource, opts={}) uri = URIBuilder.build_uri verb, resource, @env, opts opts[:query] ||= {} [:apikey, :type, :encoding].each do |param| opts[:query][param] = self.send param end @request_data = { verb: verb, resource: resource, uri: uri, opts: opts } @response_data = self.send verb, uri, opts symbolize_keys(JSON.parse(@response_data.body))[:recordlist] end |
.setup(apikey, env = "production", type = 'json', encoding = 'utf-8') ⇒ Object
12 13 14 15 16 17 |
# File 'lib/wodify/requester.rb', line 12 def setup(apikey, env="production", type='json', encoding='utf-8') @apikey = apikey @env = env @type = type @encoding = encoding end |
.symbolize_keys(hash) ⇒ Object
recursively symbolize hash keys
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wodify/requester.rb', line 33 def symbolize_keys(hash) hash.inject({}){|result, (key, value)| new_key = case key when String then key.downcase.to_sym else key end new_value = case value when Hash then symbolize_keys(value) else value end result[new_key] = new_value result } end |