Class: BugherdClient::Resources::V2::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bugherd_client/resources/v2/base.rb

Direct Known Subclasses

Comment, Organization, Project, Task, User

Constant Summary collapse

DEFAULT_HEADERS =
{ content_type: :json, accept: :json }

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject

Returns the value of attribute connection.



11
12
13
# File 'lib/bugherd_client/resources/v2/base.rb', line 11

def connection
  @connection
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/bugherd_client/resources/v2/base.rb', line 11

def options
  @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