Class: BugherdClient::Resources::V2::Base
- Inherits:
-
Object
- Object
- BugherdClient::Resources::V2::Base
- Defined in:
- lib/bugherd_client/resources/v2/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_HEADERS =
{ content_type: :json, accept: :json }
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#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.
12 13 14 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 12 def initialize(conn, opts={}) @connection, @options = conn, opts end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
11 12 13 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 11 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 11 def @options end |
Instance Method Details
#parse_response(response, root_element = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 29 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
16 17 18 19 20 21 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 16 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 |