Class: BugherdClient::Resources::V1::Base

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

Direct Known Subclasses

Comment, Project, Task, User

Constant Summary collapse

DEFAULT_HEADERS =
{

Instance Attribute Summary collapse

Instance Method Summary collapse

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, @options = conn, opts
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



18
19
20
# File 'lib/bugherd_client/resources/v1/base.rb', line 18

def connection
  @connection
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/bugherd_client/resources/v1/base.rb', line 18

def options
  @options
end

Instance Method Details

#api_methodsObject

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