Class: Tire::HTTP::Client::Curb

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/http/clients/curb.rb

Class Method Summary collapse

Class Method Details

.__host_unreachable_exceptionsObject



63
64
65
# File 'lib/tire/http/clients/curb.rb', line 63

def self.__host_unreachable_exceptions
  [::Curl::Err::HostResolutionError, ::Curl::Err::ConnectionFailedError]
end

.clientObject



10
11
12
13
14
15
16
17
# File 'lib/tire/http/clients/curb.rb', line 10

def self.client
  Thread.current[:client] ||= begin
    client = ::Curl::Easy.new
    client.resolve_mode = :ipv4
    # client.verbose = true
    client
  end
end

.delete(url) ⇒ Object



51
52
53
54
55
# File 'lib/tire/http/clients/curb.rb', line 51

def self.delete(url)
  client.url = url
  client.http_delete
  Response.new client.body_str, client.response_code
end

.get(url, data = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tire/http/clients/curb.rb', line 19

def self.get(url, data=nil)
  client.url = url

  # FIXME: Curb cannot post bodies with GET requests?
  #        Roy Fielding seems to approve:
  #        <http://tech.groups.yahoo.com/group/rest-discuss/message/9962>
  if data
    client.post_body = data
    client.http_post
  else
    client.http_get
  end
  Response.new client.body_str, client.response_code
end

.head(url) ⇒ Object



57
58
59
60
61
# File 'lib/tire/http/clients/curb.rb', line 57

def self.head(url)
  client.url = url
  client.http_head
  Response.new client.body_str, client.response_code
end

.post(url, data) ⇒ Object



34
35
36
37
38
39
# File 'lib/tire/http/clients/curb.rb', line 34

def self.post(url, data)
  client.url = url
  client.post_body = data
  client.http_post
  Response.new client.body_str, client.response_code
end

.put(url, data) ⇒ Object



44
45
46
47
48
49
# File 'lib/tire/http/clients/curb.rb', line 44

def self.put(url, data)
  method = client.respond_to?(:http_put_without_newrelic) ? :http_put_without_newrelic : :http_put
  client.url = url
  client.send method, data
  Response.new client.body_str, client.response_code
end