Class: ShopCircle::Orbit::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/shopcircle/orbit/transport.rb

Constant Summary collapse

SDK_NAME =
"shopcircle-orbit-ruby"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Transport

Returns a new instance of Transport.



13
14
15
16
17
18
19
20
# File 'lib/shopcircle/orbit/transport.rb', line 13

def initialize(config)
  @config  = config
  @api_uri = URI.parse(config.api_url.to_s.chomp("/"))
  @http    = nil
  @mutex   = Mutex.new
  @ingest_token = nil
  @ingest_token_expires_at = 0
end

Instance Method Details

#send_batch(events) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/shopcircle/orbit/transport.rb', line 27

def send_batch(events)
  body = JSON.generate({
    events: events.map(&:to_payload),
    clientId: @config.client_id,
    sdkName: SDK_NAME,
    sdkVersion: ShopCircle::Orbit::VERSION
  })
  post("/api/track/batch", body)
end

#send_single(event) ⇒ Object



22
23
24
25
# File 'lib/shopcircle/orbit/transport.rb', line 22

def send_single(event)
  body = JSON.generate(event.to_payload)
  post("/api/track", body)
end

#shutdownObject



37
38
39
40
41
42
# File 'lib/shopcircle/orbit/transport.rb', line 37

def shutdown
  @mutex.synchronize do
    @http&.finish rescue nil
    @http = nil
  end
end