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_HEADER_ATTRS =
{ :content_type => :json, :accept => :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
-
#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.
16 17 18 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 16 def initialize(conn, opts={}) @connection, @options = conn, opts end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 14 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 14 def @options end |
Instance Method Details
#parse_response(response, root_element = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 33 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
20 21 22 23 24 25 |
# File 'lib/bugherd_client/resources/v2/base.rb', line 20 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 |