Class: Coarnotify::Http::NetHttpLayer
- Defined in:
- lib/coarnotify/http.rb
Overview
Implementation of the HTTP layer using Net::HTTP. This is the default implementation used when no other implementation is supplied
Instance Method Summary collapse
-
#get(url, headers = {}, *args, **kwargs) ⇒ NetHttpResponse
Make an HTTP GET request to the supplied URL with the given headers.
-
#post(url, data, headers = {}, *args, **kwargs) ⇒ NetHttpResponse
Make an HTTP POST request to the supplied URL with the given body data, and headers.
Instance Method Details
#get(url, headers = {}, *args, **kwargs) ⇒ NetHttpResponse
Make an HTTP GET request to the supplied URL with the given headers
args and kwargs can be used to pass additional parameters to the Net::HTTP request, such as authentication credentials, etc.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/coarnotify/http.rb', line 101 def get(url, headers = {}, *args, **kwargs) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') request = Net::HTTP::Get.new(uri.request_uri) headers.each { |key, value| request[key] = value } response = http.request(request) NetHttpResponse.new(response) end |
#post(url, data, headers = {}, *args, **kwargs) ⇒ NetHttpResponse
Make an HTTP POST request to the supplied URL with the given body data, and headers
args and kwargs can be used to pass additional parameters to the Net::HTTP request, such as authentication credentials, etc.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/coarnotify/http.rb', line 78 def post(url, data, headers = {}, *args, **kwargs) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') request = Net::HTTP::Post.new(uri.request_uri) headers.each { |key, value| request[key] = value } request.body = data response = http.request(request) NetHttpResponse.new(response) end |