Class: Ahoy::Stores::KinesisFirehoseStore

Inherits:
LogStore show all
Defined in:
lib/ahoy/stores/kinesis_firehose_store.rb

Direct Known Subclasses

Ahoy::Store

Instance Method Summary collapse

Methods inherited from LogStore

#track_event, #track_visit

Methods inherited from BaseStore

#authenticate, #exclude?, #generate_id, #initialize, #report_exception, #track_event, #track_visit, #user, #visit

Constructor Details

This class inherits a constructor from Ahoy::Stores::BaseStore

Instance Method Details

#clientObject



12
13
14
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 12

def client
  @client ||= Aws::Firehose::Client.new(credentials)
end

#credentialsObject



25
26
27
28
29
30
31
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 25

def credentials
  {
    access_key_id: ENV["AWS_ACCESS_KEY_ID"],
    secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
    region: "us-east-1"
  }
end

#events_streamObject



37
38
39
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 37

def events_stream
  "ahoy_events"
end

#log_event(data) ⇒ Object



8
9
10
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 8

def log_event(data)
  post(events_stream, data)
end

#log_visit(data) ⇒ Object



4
5
6
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 4

def log_visit(data)
  post(visits_stream, data)
end

#post(stream, data) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 16

def post(stream, data)
  client.put_record(
    delivery_stream_name: stream,
    record: {
      data: "#{data.to_json}\n"
    }
  )
end

#visits_streamObject



33
34
35
# File 'lib/ahoy/stores/kinesis_firehose_store.rb', line 33

def visits_stream
  "ahoy_visits"
end