Class: Datumfactory::Util::HTTP
- Inherits:
-
Object
- Object
- Datumfactory::Util::HTTP
- Extended by:
- Forwardable
- Defined in:
- lib/datumfactory/util/http.rb
Constant Summary collapse
- HEADERS =
{ 'Content-type'.freeze => 'application/json'.freeze, 'Content-Encoding'.freeze => 'deflate'.freeze, 'Accept'.freeze => 'text/json, application/json'.freeze, 'User-Agent'.freeze => "HB-Ruby #{VERSION}; #{RUBY_VERSION}; #{RUBY_PLATFORM}".freeze }.freeze
- ERRORS =
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, SocketError].freeze
Instance Method Summary collapse
- #get(endpoint) ⇒ Object
-
#initialize(config) ⇒ HTTP
constructor
A new instance of HTTP.
- #post(endpoint, payload, headers = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTTP
Returns a new instance of HTTP.
33 34 35 |
# File 'lib/datumfactory/util/http.rb', line 33 def initialize(config) @config = config end |
Instance Method Details
#get(endpoint) ⇒ Object
37 38 39 40 41 |
# File 'lib/datumfactory/util/http.rb', line 37 def get(endpoint) response = http_connection.get(endpoint) debug { format('http method=GET path=%s code=%d', endpoint.dump, response.code) } response end |
#post(endpoint, payload, headers = nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/datumfactory/util/http.rb', line 43 def post(endpoint, payload, headers = nil) response = http_connection.post(endpoint, compress(payload.to_json), http_headers(headers)) debug { format('http method=POST path=%s code=%d', endpoint.dump, response.code) } response end |