Class: ShopCircle::Orbit::Transport
- Inherits:
-
Object
- Object
- ShopCircle::Orbit::Transport
- Defined in:
- lib/shopcircle/orbit/transport.rb
Constant Summary collapse
- SDK_NAME =
"shopcircle-orbit-ruby"
Instance Method Summary collapse
-
#initialize(config) ⇒ Transport
constructor
A new instance of Transport.
- #send_batch(events) ⇒ Object
- #send_single(event) ⇒ Object
- #shutdown ⇒ Object
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 |
#shutdown ⇒ Object
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 |