class Songkick::Transport::Base
Constants
- DEFAULT_INSTRUMENTATION_LABEL
Attributes
basic_auth[R]
endpoint[R]
host[R]
instrumenter[R]
timeout[R]
user_agent[RW]
user_error_codes[RW]
Public Class Methods
new(host, options = {})
click to toggle source
# File lib/songkick/transport/base.rb, line 58 def initialize(host, options = {}) @host = host @timeout = options[:timeout] || DEFAULT_TIMEOUT @user_agent = options[:user_agent] @user_error_codes = options[:user_error_codes] || DEFAULT_USER_ERROR_CODES @instrumenter ||= options[:instrumenter] @instrumentation_label = options[:instrumentation_label] || DEFAULT_INSTRUMENTATION_LABEL @basic_auth = options[:basic_auth] end
Public Instance Methods
do_verb(verb, path, params = {}, head = {}, timeout = nil)
click to toggle source
# File lib/songkick/transport/base.rb, line 68 def do_verb(verb, path, params = {}, head = {}, timeout = nil) auth_headers = basic_auth ? Authentication.basic_auth_headers(basic_auth) : {} req = Request.new(endpoint, verb, path, params, headers.merge(auth_headers).merge(head), timeout) Reporting.log_request(req) instrument(req) do |payload| begin req.response = execute_request(req) payload.merge!({ :status => req.response.status, :response_headers => req.response.headers.to_hash }) if req.response rescue => error req.error = error payload.merge!({ :status => error.status, :response_headers => error.headers.to_hash }) if error.is_a?(HttpError) Reporting.record(req) raise error ensure payload.merge!(self.instrumentation_payload_extras) end end Reporting.log_response(req) Reporting.record(req) req.response end
instrumentation_payload_extras()
click to toggle source
# File lib/songkick/transport/base.rb, line 95 def instrumentation_payload_extras Thread.current[:transport_base_payload_extras] ||= {} end
instrumentation_payload_extras=(extras)
click to toggle source
# File lib/songkick/transport/base.rb, line 99 def instrumentation_payload_extras=(extras) Thread.current[:transport_base_payload_extras] = {} end
Private Instance Methods
headers()
click to toggle source
# File lib/songkick/transport/base.rb, line 126 def headers Headers.new( 'Connection' => 'close', 'User-Agent' => user_agent ) end
instrument(request) { |payload| ... }
click to toggle source
# File lib/songkick/transport/base.rb, line 109 def instrument(request) if self.instrumenter payload = { :adapter => self.class.name, :endpoint => request.endpoint, :verb => request.verb, :path => request.path, :params => request.params, :request_headers => request.headers.to_hash } self.instrumenter.instrument(@instrumentation_label, payload) do yield(payload) end else yield({}) end end
logger()
click to toggle source
# File lib/songkick/transport/base.rb, line 133 def logger Transport.logger end
process(url, status, headers, body)
click to toggle source
# File lib/songkick/transport/base.rb, line 105 def process(url, status, headers, body) Response.process(url, status, headers, body, @user_error_codes) end