Class: Lymbix::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/lymbix/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, method, header_hash, object = nil) ⇒ Request

:nodoc:



8
9
10
11
12
13
14
# File 'lib/lymbix/request.rb', line 8

def initialize(http_method, method, header_hash, object = nil) #:nodoc:
  self.http_method = http_method
  self.url = Lymbix::Configuration.host
  self.method = method
  self.object = object
  self.header_hash = header_hash
end

Instance Attribute Details

#header_hashObject

Returns the value of attribute header_hash.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def header_hash
  @header_hash
end

#http_methodObject

Returns the value of attribute http_method.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def http_method
  @http_method
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def method
  @method
end

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def object
  @object
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def response
  @response
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/lymbix/request.rb', line 6

def url
  @url
end

Instance Method Details

#connectionObject



16
17
18
19
20
# File 'lib/lymbix/request.rb', line 16

def connection
  options = {}
  options[:headers] = {:accept => self.header_hash[:accept_type], :AUTHENTICATION => self.header_hash[:auth_key], :VERSION => self.header_hash[:version]}            
  RestClient::Resource.new(self.url, options)
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lymbix/request.rb', line 22

def run
  case(self.http_method)
  when :get
    self.connection[self.method].get do |resp|
      self.response = resp.body
    end
  when :post
    self.connection[self.method].post(object) do |resp|
      self.response = resp.body
    end
  end
  Response.new(self.response)
end