Class: Bento::Analytics::Transport
- Inherits:
-
Object
- Object
- Bento::Analytics::Transport
- Includes:
- Defaults::Request, Logging, Utils
- Defined in:
- lib/bento/sdk/transport.rb
Constant Summary
Constants included from Utils
Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON
Constants included from Defaults::Request
Defaults::Request::HEADERS, Defaults::Request::HOST, Defaults::Request::PATH, Defaults::Request::PORT, Defaults::Request::RETRIES, Defaults::Request::SSL
Class Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Transport
constructor
A new instance of Transport.
-
#send(write_key, batch) ⇒ Response
Sends a batch of messages to the API.
-
#shutdown ⇒ Object
Closes a persistent connection if it exists.
Methods included from Logging
Methods included from Utils
#date_in_iso8601, #datetime_in_iso8601, #formatted_offset, #isoify_dates, #isoify_dates!, #seconds_to_utc_offset, #stringify_keys, #symbolize_keys, #symbolize_keys!, #time_in_iso8601, #uid
Constructor Details
permalink #initialize(options = {}) ⇒ Transport
Returns a new instance of Transport.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bento/sdk/transport.rb', line 17 def initialize( = {}) [:host] ||= HOST [:port] ||= PORT [:ssl] ||= SSL @headers = [:headers] || HEADERS @path = [:path] || PATH @retries = [:retries] || RETRIES @backoff_policy = [:backoff_policy] || Bento::Analytics::BackoffPolicy.new http = Net::HTTP.new([:host], [:port]) http.use_ssl = [:ssl] http.read_timeout = 8 http.open_timeout = 4 @http = http end |
Class Attribute Details
permalink .stub ⇒ Object
138 139 140 |
# File 'lib/bento/sdk/transport.rb', line 138 def stub @stub || ENV["STUB"] end |
Instance Method Details
permalink #send(write_key, batch) ⇒ Response
Sends a batch of messages to the API
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bento/sdk/transport.rb', line 38 def send(write_key, batch) logger.debug("Sending request for #{batch.length} items") last_response, exception = retry_with_backoff(@retries) { status_code, body = send_request(write_key, batch) error = "" should_retry = should_retry_request?(status_code, body) logger.debug("🍱Response status code: #{status_code}") logger.debug("🍱Response error (if any): #{error}") if error [Bento::Analytics::Response.new(status_code, error), should_retry] } if exception logger.error(exception.) exception.backtrace.each { |line| logger.error(line) } Bento::Analytics::Response.new(-1, exception.to_s) else last_response end end |
permalink #shutdown ⇒ Object
Closes a persistent connection if it exists
62 63 64 |
# File 'lib/bento/sdk/transport.rb', line 62 def shutdown @http.finish if @http.started? end |