Class: Phocoder::HTTP

Inherits:
Base
  • Object
show all
Defined in:
lib/phocoder/http.rb,
lib/phocoder/http/net_http.rb,
lib/phocoder/http/typhoeus.rb

Defined Under Namespace

Classes: NetHTTP, Typhoeus

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, base_url, decode, #decode, #encode, encode

Constructor Details

#initialize(method, url, options = {}) ⇒ HTTP

Returns a new instance of HTTP.



15
16
17
18
19
20
21
# File 'lib/phocoder/http.rb', line 15

def initialize(method, url, options={})
  self.method  = method
  self.url     = url
  self.format  = options.delete(:format)
  self.options = options
  self.body    = options.delete(:body)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/phocoder/http.rb', line 4

def body
  @body
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/phocoder/http.rb', line 4

def format
  @format
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/phocoder/http.rb', line 4

def method
  @method
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/phocoder/http.rb', line 4

def options
  @options
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/phocoder/http.rb', line 4

def url
  @url
end

Class Method Details

.delete(url, options = {}) ⇒ Object



35
36
37
# File 'lib/phocoder/http.rb', line 35

def self.delete(url, options={})
  new(:delete, url, options).perform_method
end

.get(url, options = {}) ⇒ Object



31
32
33
# File 'lib/phocoder/http.rb', line 31

def self.get(url, options={})
  new(:get, url, options).perform_method
end

.post(url, body, options = {}) ⇒ Object



23
24
25
# File 'lib/phocoder/http.rb', line 23

def self.post(url, body, options={})
  new(:post, url, options.merge(:body => body)).perform_method
end

.put(url, body, options = {}) ⇒ Object



27
28
29
# File 'lib/phocoder/http.rb', line 27

def self.put(url, body, options={})
  new(:put, url, options.merge(:body => body)).perform_method
end

Instance Method Details

#default_optionsObject



67
68
69
# File 'lib/phocoder/http.rb', line 67

def default_options
  self.class.default_options.recursive_with_indifferent_access
end

#http_backendObject



63
64
65
# File 'lib/phocoder/http.rb', line 63

def http_backend
  self.class.http_backend
end

#perform_methodObject



39
40
41
42
43
# File 'lib/phocoder/http.rb', line 39

def perform_method
  process(http_backend.send(method, url, options))
rescue StandardError => e
  raise HTTPError.new(e)
end