Class: AmplitudeAnalytics::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/amplitude/config.rb

Overview

Config

Direct Known Subclasses

AmplitudeExperiment::AssignmentConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, flush_queue_size: FLUSH_QUEUE_SIZE, flush_interval_millis: FLUSH_INTERVAL_MILLIS, flush_max_retries: FLUSH_MAX_RETRIES, logger: Logger.new($stdout, progname: LOGGER_NAME, level: Logger::ERROR), min_id_length: nil, callback: nil, server_zone: DEFAULT_ZONE, use_batch: false, server_url: nil, storage_provider: InMemoryStorageProvider.new, ingestion_metadata: nil) ⇒ Config

Returns a new instance of Config.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/amplitude/config.rb', line 9

def initialize(api_key: nil, flush_queue_size: FLUSH_QUEUE_SIZE,
               flush_interval_millis: FLUSH_INTERVAL_MILLIS,
               flush_max_retries: FLUSH_MAX_RETRIES,
               logger: Logger.new($stdout, progname: LOGGER_NAME, level: Logger::ERROR),
               min_id_length: nil, callback: nil, server_zone: DEFAULT_ZONE,
               use_batch: false, server_url: nil,
               storage_provider: InMemoryStorageProvider.new, ingestion_metadata: nil)
  @api_key = api_key
  @flush_queue_size = flush_queue_size
  @flush_size_divider = 1
  @flush_interval_millis = flush_interval_millis
  @flush_max_retries = flush_max_retries
  @logger = logger
  @min_id_length = min_id_length
  @callback = callback
  @server_zone = server_zone
  @use_batch = use_batch
  @server_url = server_url
  @storage_provider = storage_provider
  @opt_out = false
  @ingestion_metadata = 
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def api_key
  @api_key
end

#callbackObject

Returns the value of attribute callback.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def callback
  @callback
end

#flush_interval_millisObject

Returns the value of attribute flush_interval_millis.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def flush_interval_millis
  @flush_interval_millis
end

#flush_max_retriesObject

Returns the value of attribute flush_max_retries.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def flush_max_retries
  @flush_max_retries
end

#ingestion_metadataObject

Returns the value of attribute ingestion_metadata.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def 
  @ingestion_metadata
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def logger
  @logger
end

#min_id_lengthObject

Returns the value of attribute min_id_length.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def min_id_length
  @min_id_length
end

#opt_outObject

Returns the value of attribute opt_out.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def opt_out
  @opt_out
end

#server_zoneObject

Returns the value of attribute server_zone.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def server_zone
  @server_zone
end

#storage_providerObject

Returns the value of attribute storage_provider.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def storage_provider
  @storage_provider
end

#use_batchObject

Returns the value of attribute use_batch.



5
6
7
# File 'lib/amplitude/config.rb', line 5

def use_batch
  @use_batch
end

Instance Method Details

#flush_queue_sizeObject



44
45
46
# File 'lib/amplitude/config.rb', line 44

def flush_queue_size
  [@flush_queue_size / @flush_size_divider, 1].max
end

#flush_queue_size=(size) ⇒ Object



48
49
50
51
# File 'lib/amplitude/config.rb', line 48

def flush_queue_size=(size)
  @flush_queue_size = size
  @flush_size_divider = 1
end

#increase_flush_dividerObject



70
71
72
# File 'lib/amplitude/config.rb', line 70

def increase_flush_divider
  @flush_size_divider += 1
end

#min_id_length_valid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/amplitude/config.rb', line 40

def min_id_length_valid?
  @min_id_length.nil? || (@min_id_length.is_a?(Integer) && @min_id_length > 0)
end

#optionsObject



66
67
68
# File 'lib/amplitude/config.rb', line 66

def options
  { 'min_id_length' => @min_id_length } if min_id_length_valid? && @min_id_length
end

#reset_flush_dividerObject



74
75
76
# File 'lib/amplitude/config.rb', line 74

def reset_flush_divider
  @flush_size_divider = 1
end

#server_urlObject



53
54
55
56
57
58
59
60
# File 'lib/amplitude/config.rb', line 53

def server_url
  @url || (
    if use_batch
      SERVER_URL[@server_zone][BATCH]
    else
      SERVER_URL[@server_zone][HTTP_V2]
    end)
end

#server_url=(url) ⇒ Object



62
63
64
# File 'lib/amplitude/config.rb', line 62

def server_url=(url)
  @url = url
end

#storageObject



32
33
34
# File 'lib/amplitude/config.rb', line 32

def storage
  @storage_provider.storage
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/amplitude/config.rb', line 36

def valid?
  @api_key && @flush_queue_size > 0 && @flush_interval_millis > 0 && min_id_length_valid?
end