Class: BugherdClient::Resources::V1::Base
- Inherits:
-
Object
- Object
- BugherdClient::Resources::V1::Base
- Defined in:
- lib/bugherd_client/resources/v1/base.rb
Constant Summary collapse
- DEFAULT_HEADER_ATTRS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#api_methods ⇒ Object
Return a list of available methods in a Resource.
-
#initialize(conn, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #parse_response(response, root_element = nil) ⇒ Object
- #send_request(method = 'GET', path = '', params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(conn, opts = {}) ⇒ Base
Returns a new instance of Base.
22 23 24 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 22 def initialize(conn, opts={}) @connection, = conn, opts end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
21 22 23 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 21 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 21 def end |
Instance Method Details
#api_methods ⇒ Object
Return a list of available methods in a Resource
17 18 19 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 17 def api_methods self.class.instance_methods(false) end |
#parse_response(response, root_element = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 39 def parse_response(response, root_element=nil) if root_element pr = JSON.parse(response) if pr.is_a?(Hash) and pr.has_key?(root_element) pr[root_element] else pr end else JSON.parse(response) end end |
#send_request(method = 'GET', path = '', params = {}, headers = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 26 def send_request(method='GET', path='', params={}, headers={}) headers = DEFAULT_HEADER_ATTRS.merge(headers) params.merge!(headers) method_name = method.to_s.downcase self.connection[path].__send__(method_name, params) end |