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_HEADERS =
{
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.
19 20 21 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 19 def initialize(conn, opts={}) @connection, = conn, opts end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
18 19 20 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 18 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
18 19 20 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 18 def end |
Instance Method Details
#api_methods ⇒ Object
Return a list of available methods in a Resource
14 15 16 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 14 def api_methods self.class.instance_methods(false) end |
#parse_response(response, root_element = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 36 def parse_response(response, root_element=nil) if root_element JSON.parse(response)[root_element.to_s] else JSON.parse(response) end end |
#send_request(method = "GET", path = "", params = {}, headers = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bugherd_client/resources/v1/base.rb', line 23 def send_request(method="GET", path="", params={}, headers={}) headers = DEFAULT_HEADERS.merge(headers) params.merge!(headers) method_name = method.to_s.downcase self.connection[path].__send__(method_name, params) end |