Class: Songkick::Transport::Base
- Inherits:
-
Object
- Object
- Songkick::Transport::Base
- Includes:
- API
- Defined in:
- lib/songkick/transport/base.rb
Direct Known Subclasses
Defined Under Namespace
Modules: API Classes: BasicAuthDecorator, HeaderDecorator, ParamsDecorator, TimeoutDecorator
Constant Summary collapse
- DEFAULT_INSTRUMENTATION_LABEL =
'http.songkick_transport'
Instance Attribute Summary collapse
-
#basic_auth ⇒ Object
readonly
Returns the value of attribute basic_auth.
-
#host ⇒ Object
(also: #endpoint)
readonly
Returns the value of attribute host.
-
#instrumenter ⇒ Object
readonly
Returns the value of attribute instrumenter.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#user_error_codes ⇒ Object
Returns the value of attribute user_error_codes.
Instance Method Summary collapse
- #do_verb(verb, path, params = {}, head = {}, timeout = nil) ⇒ Object
-
#initialize(host, options = {}) ⇒ Base
constructor
A new instance of Base.
- #instrumentation_payload_extras ⇒ Object
- #instrumentation_payload_extras=(extras) ⇒ Object
Methods included from API
#delete, #get, #head, #options, #patch, #post, #put, #with_basic_auth, #with_headers, #with_params, #with_timeout
Constructor Details
#initialize(host, options = {}) ⇒ Base
Returns a new instance of Base.
58 59 60 61 62 63 64 65 66 |
# File 'lib/songkick/transport/base.rb', line 58 def initialize(host, = {}) @host = host @timeout = [:timeout] || DEFAULT_TIMEOUT @user_agent = [:user_agent] @user_error_codes = [:user_error_codes] || DEFAULT_USER_ERROR_CODES @instrumenter ||= [:instrumenter] @instrumentation_label = [:instrumentation_label] || DEFAULT_INSTRUMENTATION_LABEL @basic_auth = [:basic_auth] end |
Instance Attribute Details
#basic_auth ⇒ Object (readonly)
Returns the value of attribute basic_auth.
54 55 56 |
# File 'lib/songkick/transport/base.rb', line 54 def basic_auth @basic_auth end |
#host ⇒ Object (readonly) Also known as: endpoint
Returns the value of attribute host.
54 55 56 |
# File 'lib/songkick/transport/base.rb', line 54 def host @host end |
#instrumenter ⇒ Object (readonly)
Returns the value of attribute instrumenter.
54 55 56 |
# File 'lib/songkick/transport/base.rb', line 54 def instrumenter @instrumenter end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
54 55 56 |
# File 'lib/songkick/transport/base.rb', line 54 def timeout @timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
53 54 55 |
# File 'lib/songkick/transport/base.rb', line 53 def user_agent @user_agent end |
#user_error_codes ⇒ Object
Returns the value of attribute user_error_codes.
53 54 55 |
# File 'lib/songkick/transport/base.rb', line 53 def user_error_codes @user_error_codes end |
Instance Method Details
#do_verb(verb, path, params = {}, head = {}, timeout = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
95 96 97 |
# File 'lib/songkick/transport/base.rb', line 95 def instrumentation_payload_extras Thread.current[:transport_base_payload_extras] ||= {} end |
#instrumentation_payload_extras=(extras) ⇒ Object
99 100 101 |
# File 'lib/songkick/transport/base.rb', line 99 def instrumentation_payload_extras=(extras) Thread.current[:transport_base_payload_extras] = {} end |