Class: Optimizely::OdpEventApiManager
- Inherits:
-
Object
- Object
- Optimizely::OdpEventApiManager
- Defined in:
- lib/optimizely/odp/odp_event_api_manager.rb
Instance Method Summary collapse
-
#initialize(logger: nil, proxy_config: nil, timeout: nil) ⇒ OdpEventApiManager
constructor
Interface that handles sending ODP events.
-
#send_odp_events(api_key, api_host, events) ⇒ Object
Send events to the ODP Events API.
Constructor Details
#initialize(logger: nil, proxy_config: nil, timeout: nil) ⇒ OdpEventApiManager
Interface that handles sending ODP events.
25 26 27 28 29 |
# File 'lib/optimizely/odp/odp_event_api_manager.rb', line 25 def initialize(logger: nil, proxy_config: nil, timeout: nil) @logger = logger || NoOpLogger.new @proxy_config = proxy_config @timeout = timeout || Optimizely::Helpers::Constants::ODP_REST_API_CONFIG[:REQUEST_TIMEOUT] end |
Instance Method Details
#send_odp_events(api_key, api_host, events) ⇒ Object
Send events to the ODP Events API.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/optimizely/odp/odp_event_api_manager.rb', line 37 def send_odp_events(api_key, api_host, events) should_retry = false url = "#{api_host}/v3/events" headers = {'Content-Type' => 'application/json', 'x-api-key' => api_key.to_s} begin response = Helpers::HttpUtils.make_request( url, :post, events.to_json, headers, @timeout, @proxy_config ) rescue SocketError, Timeout::Error, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EFAULT, Errno::ENETUNREACH, Errno::ENETDOWN, Errno::ECONNREFUSED log_failure('network error') should_retry = true return should_retry rescue StandardError => e log_failure(e) return should_retry end status = response.code.to_i if status >= 400 log_failure(!response.body.empty? ? response.body : "#{status}: #{response.}") should_retry = status >= 500 end should_retry end |