Class: Cryptid::Client
- Inherits:
-
Object
- Object
- Cryptid::Client
- Defined in:
- lib/cryptid/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #build_event_payload(event) ⇒ Object
- #headers ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #send(event) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/cryptid/client.rb', line 8 def initialize(={}) @conn = [:conn] if [:conn] if [:tracker_id] @tracker_id = [:tracker_id] else @tracker_id = Cryptid.configuration.tracker_id end end |
Instance Attribute Details
#conn ⇒ Object
22 23 24 |
# File 'lib/cryptid/client.rb', line 22 def conn @conn ||= ::Excon.new(url) end |
#tracker_id ⇒ Object
26 27 28 |
# File 'lib/cryptid/client.rb', line 26 def tracker_id @tracker_id or raise 'Missing tracker_id. Set in initializer or Cryptid::Client constructor' end |
Instance Method Details
#build_event_payload(event) ⇒ Object
41 42 43 44 45 |
# File 'lib/cryptid/client.rb', line 41 def build_event_payload(event) { event: Helpers.camelize(event.merge(tracker_id: tracker_id)) }.to_json end |
#headers ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cryptid/client.rb', line 30 def headers { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } end |
#send(event) ⇒ Object
37 38 39 |
# File 'lib/cryptid/client.rb', line 37 def send(event) conn.post(body: build_event_payload(event), headers: headers) end |
#url ⇒ Object
18 19 20 |
# File 'lib/cryptid/client.rb', line 18 def url Cryptid.configuration.url end |