Module: HTTY::RequestsUtil

Defined in:
lib/htty/requests_util.rb

Overview

Provides support for making HTTP(S) requests.

Class Method Summary collapse

Class Method Details

.delete(request) ⇒ Object

Makes an HTTP DELETE request with the specified request.



12
13
14
15
16
# File 'lib/htty/requests_util.rb', line 12

def self.delete(request)
  request(request) do |host|
    host.delete request.send(:path_query_and_fragment), headers_from(request)
  end
end

.get(request) ⇒ Object

Makes an HTTP GET request with the specified request.



19
20
21
22
23
# File 'lib/htty/requests_util.rb', line 19

def self.get(request)
  request(request) do |host|
    host.request_get request.send(:path_query_and_fragment), headers_from(request)
  end
end

.head(request) ⇒ Object

Makes an HTTP HEAD request with the specified request.



26
27
28
29
30
# File 'lib/htty/requests_util.rb', line 26

def self.head(request)
  request(request) do |host|
    host.head request.send(:path_query_and_fragment), headers_from(request)
  end
end

.http_response_to_status(http_response) ⇒ Object (protected)



75
76
77
78
79
# File 'lib/htty/requests_util.rb', line 75

def self.http_response_to_status(http_response)
  [http_response.code,
   http_response.code_type.name.gsub(/^Net::HTTP/,       '').
                                gsub(/(\S)([A-Z][a-z])/, '\1 \2')]
end

.options(request) ⇒ Object

Makes an HTTP OPTIONS request with the specified request.



33
34
35
36
37
# File 'lib/htty/requests_util.rb', line 33

def self.options(request)
  request(request) do |host|
    host.options request.send(:path_query_and_fragment), headers_from(request)
  end
end

.patch(request) ⇒ Object

Makes an HTTP PATCH request with the specified request.



40
41
42
43
44
45
46
# File 'lib/htty/requests_util.rb', line 40

def self.patch(request)
  request(request) do |host|
    host.patch request.send(:path_query_and_fragment),
               request.body,
               headers_from(request)
  end
end

.post(request) ⇒ Object

Makes an HTTP POST request with the specified request.



49
50
51
52
53
54
55
# File 'lib/htty/requests_util.rb', line 49

def self.post(request)
  request(request) do |host|
    host.post request.send(:path_query_and_fragment),
              request.body,
              headers_from(request)
  end
end

.put(request) ⇒ Object

Makes an HTTP PUT request with the specified request.



58
59
60
61
62
63
64
# File 'lib/htty/requests_util.rb', line 58

def self.put(request)
  request(request) do |host|
    host.put request.send(:path_query_and_fragment),
             request.body,
             headers_from(request)
  end
end

.trace(request) ⇒ Object

Makes an HTTP TRACE request with the specified request.



67
68
69
70
71
# File 'lib/htty/requests_util.rb', line 67

def self.trace(request)
  request(request) do |host|
    host.trace request.send(:path_query_and_fragment), headers_from(request)
  end
end