Class: Apical::HttpAdapter

Inherits:
Adapter
  • Object
show all
Includes:
HTTParty
Defined in:
lib/apical/adapters/http_adapter.rb

Instance Method Summary collapse

Methods inherited from Adapter

[], identifier

Constructor Details

#initialize(options = {}) ⇒ HttpAdapter

Returns a new instance of HttpAdapter.



9
10
11
12
# File 'lib/apical/adapters/http_adapter.rb', line 9

def initialize(options={})
  self.class.base_uri options[:base_uri]
  @headers = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



22
23
24
25
26
27
# File 'lib/apical/adapters/http_adapter.rb', line 22

def method_missing(name, *args)
  self.class.headers(@headers) unless @headers.empty?
  response = self.class.send(name, *args)
  clear_headers!
  return response
end

Instance Method Details

#clear_headers!Object



18
19
20
# File 'lib/apical/adapters/http_adapter.rb', line 18

def clear_headers!
  @headers = {}
end

#header(name, value) ⇒ Object



14
15
16
# File 'lib/apical/adapters/http_adapter.rb', line 14

def header(name, value)
  @headers[name] = value
end