Class: Zenaton::Services::Http
- Inherits:
-
Object
- Object
- Zenaton::Services::Http
- Defined in:
- lib/zenaton/services/http.rb
Overview
Wrapper class around HTTParty that:
-
handles http calls
-
sets appropriate headers for each request type
-
translates exceptions into Zenaton specific ones
Constant Summary collapse
- ALL_NET_HTTP_ERRORS =
Net::HTTP errors translated into a Zenaton::ConnectionError
[ Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError ].freeze
Instance Method Summary collapse
-
#get(url) ⇒ Hash
Makes a GET request and sets the correct headers.
-
#post(url, body, headers = {}) ⇒ Hash
Makes a POST request with some data and sets the correct headers.
-
#put(url, body, headers = {}) ⇒ Hash
Makes a PUT request with some data and sets the correct headers.
Instance Method Details
#get(url) ⇒ Hash
Makes a GET request and sets the correct headers
31 32 33 34 35 36 |
# File 'lib/zenaton/services/http.rb', line 31 def get(url) parsed_url = parse_url(url) request = Net::HTTP::Get.new(parsed_url[:uri]) set_body_and_headers(request, ) make_request(request, parsed_url) end |
#post(url, body, headers = {}) ⇒ Hash
Makes a POST request with some data and sets the correct headers
44 45 46 47 48 49 |
# File 'lib/zenaton/services/http.rb', line 44 def post(url, body, headers = {}) parsed_url = parse_url(url) request = Net::HTTP::Post.new(parsed_url[:uri]) set_body_and_headers(request, (body, headers)) make_request(request, parsed_url) end |
#put(url, body, headers = {}) ⇒ Hash
Makes a PUT request with some data and sets the correct headers
57 58 59 60 61 62 |
# File 'lib/zenaton/services/http.rb', line 57 def put(url, body, headers = {}) parsed_url = parse_url(url) request = Net::HTTP::Put.new(parsed_url[:uri]) set_body_and_headers(request, (body, headers)) make_request(request, parsed_url) end |