Class: Ravelin::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ravelin/client.rb

Constant Summary collapse

API_BASE =
'https://api.ravelin.com'

Instance Method Summary collapse

Constructor Details

#initialize(api_key:) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
# File 'lib/ravelin/client.rb', line 14

def initialize(api_key:)
  @api_key = api_key

  @connection = Faraday.new(API_BASE, faraday_options) do |conn|
    conn.response :json, context_type: /\bjson$/
    conn.adapter Ravelin.faraday_adapter
  end
end

Instance Method Details

#delete_tag(**args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/ravelin/client.rb', line 48

def delete_tag(**args)
  tag = Tag.new(**args).serializable_hash
  customer_id = tag[:customerId]
  tags = tag[:tagNames].join(",")

  delete("/v2/tag/customer?customerId=[#{customer_id}]&tagName=[#{tags}]")
end

#send_backfill_event(**args) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/ravelin/client.rb', line 32

def send_backfill_event(**args)
  unless args.has_key?(:timestamp)
    raise ArgumentError.new('missing parameters: timestamp')
  end

  event = Event.new(**args)

  post("/v2/backfill/#{event.name}", event.serializable_hash)
end

#send_event(**args) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ravelin/client.rb', line 23

def send_event(**args)
  score = args.delete(:score)
  event = Event.new(**args)

  score_param = score ? "?score=true" : nil

  post("/v2/#{event.name}#{score_param}", event.serializable_hash)
end

#send_tag(**args) ⇒ Object



42
43
44
45
46
# File 'lib/ravelin/client.rb', line 42

def send_tag(**args)
  tag = Tag.new(**args)

  post("/v2/tag/customer", tag.serializable_hash)
end