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
# 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
end

Instance Method Details

#send_batch(events) ⇒ Object



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

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



20
21
22
23
# File 'lib/shopcircle/orbit/transport.rb', line 20

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

#shutdownObject



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

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