Class: RudderAnalyticsSync::Request

Inherits:
Object
  • Object
show all
Includes:
Constants, Logging
Defined in:
lib/rudder_analytics_sync/request.rb

Constant Summary

Constants included from Constants

Constants::BASE_URL, Constants::DEFAULT_CONTEXT, Constants::DEFAULT_HEADERS, Constants::MAX_BATCH_SIZE, Constants::MAX_MESSAGE_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#default_logger, included

Constructor Details

#initialize(client) ⇒ Request

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
21
22
23
24
# File 'lib/rudder_analytics_sync/request.rb', line 15

def initialize(client) # rubocop:disable Metrics/AbcSize
  @write_key = client.config.write_key
  @data_plane_url = client.config.data_plane_url || BASE_URL
  @error_handler = client.config.on_error
  @stub = client.config.stub
  @logger = client.config.logger
  @http_options = client.config.http_options
  @gzip = client.config.gzip.nil? ? true : client.config.gzip
  @retry = Retry.new(client.config)
end

Instance Attribute Details

#data_plane_url ⇒ Object (readonly)

Returns the value of attribute data_plane_url.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def data_plane_url
  @data_plane_url
end

#error_handler ⇒ Object (readonly)

Returns the value of attribute error_handler.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def error_handler
  @error_handler
end

#gzip ⇒ Object (readonly)

Returns the value of attribute gzip.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def gzip
  @gzip
end

#http_options ⇒ Object (readonly)

Returns the value of attribute http_options.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def http_options
  @http_options
end

#logger ⇒ Object (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def logger
  @logger
end

#stub ⇒ Object (readonly)

Returns the value of attribute stub.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def stub
  @stub
end

#write_key ⇒ Object (readonly)

Returns the value of attribute write_key.



13
14
15
# File 'lib/rudder_analytics_sync/request.rb', line 13

def write_key
  @write_key
end

Instance Method Details

#post(path, payload, headers: DEFAULT_HEADERS) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rudder_analytics_sync/request.rb', line 26

def post(path, payload, headers: DEFAULT_HEADERS)
  begin
    uri = URI(data_plane_url)
    return stub_post(path, payload) if stub

    payload, headers = encode(payload, headers)
  rescue StandardError => e
    return error_handler.call(nil, nil, e, nil)
  end

  execute_post(uri, path, payload, headers)
end