Class: Songkick::Transport::HttParty::Adapter
- Includes:
- HTTParty
- Defined in:
- lib/songkick/transport/httparty.rb
Constant Summary
Constants inherited from Base
Base::DEFAULT_INSTRUMENTATION_LABEL
Instance Attribute Summary
Attributes inherited from Base
#basic_auth, #host, #instrumenter, #timeout, #user_agent, #user_error_codes
Instance Method Summary collapse
Methods inherited from Base
#do_verb, #initialize, #instrumentation_payload_extras, #instrumentation_payload_extras=
Methods included from Base::API
#delete, #get, #head, #options, #patch, #post, #put, #with_basic_auth, #with_headers, #with_params, #with_timeout
Constructor Details
This class inherits a constructor from Songkick::Transport::Base
Instance Method Details
#endpoint ⇒ Object
17 18 19 |
# File 'lib/songkick/transport/httparty.rb', line 17 def endpoint @host end |
#execute_request(req) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/songkick/transport/httparty.rb', line 21 def execute_request(req) timeout = req.timeout || self.class.[:timeout] = { :base_uri => @host, :headers => req.headers, :timeout => timeout } response = if req.use_body? self.class.__send__(req.verb, req.path, .merge(:body => req.body)) else self.class.__send__(req.verb, req.url, ) end process(req, response.code, response.headers, response.parsed_response) rescue SocketError => error logger.warn "Could not connect to host: #{self.class.base_uri}" raise ConnectionFailedError, req rescue Timeout::Error => error logger.warn "Request timed out: #{req}" raise Transport::TimeoutError, req rescue UpstreamError => error raise error rescue Object => error if error.class.name =~ /json/i or error. =~ /json/i logger.warn("Request returned invalid JSON: #{req}") raise Transport::InvalidJSONError, req else logger.warn("Error trying to call #{req}: #{error.class}: #{error.}") raise UpstreamError, req end end |