Class: Ravelin::Client
- Inherits:
-
Object
- Object
- Ravelin::Client
- Defined in:
- lib/ravelin/client.rb
Direct Known Subclasses
Constant Summary collapse
- API_BASE =
'https://api.ravelin.com'
Instance Method Summary collapse
- #delete_tag(**args) ⇒ Object
- #get_tag(**args) ⇒ Object
-
#initialize(api_key:, api_version: 2, include_rule_output: false) ⇒ Client
constructor
A new instance of Client.
- #send_backfill_event(**args) ⇒ Object
- #send_event(**args) ⇒ Object
- #send_tag(**args) ⇒ Object
Constructor Details
#initialize(api_key:, api_version: 2, include_rule_output: false) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ravelin/client.rb', line 14 def initialize(api_key:, api_version: 2, include_rule_output: false) @api_key = api_key @url_prefix = '' @include_rule_output = include_rule_output raise ArgumentError.new("api_version must be 2 or 3") unless [2,3].include? api_version @api_version = api_version @connection = Faraday.new(API_BASE, ) do |conn| conn.response :json, context_type: /\bjson$/ conn.adapter Ravelin.faraday_adapter end end |
Instance Method Details
#delete_tag(**args) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/ravelin/client.rb', line 53 def delete_tag(**args) tag = Tag.new(**args).serializable_hash customer_id = tag["customerId"] = tag["tagNames"].join(",") delete("#{@url_prefix}/v#{@api_version}/tag/customer?customerId=#{customer_id}&tagName=#{tags}") end |
#get_tag(**args) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/ravelin/client.rb', line 61 def get_tag(**args) tag = Tag.new(**args).serializable_hash customer_id = tag["customerId"] get("#{@url_prefix}/v#{@api_version}/tag/customer/#{customer_id}") end |
#send_backfill_event(**args) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ravelin/client.rb', line 37 def send_backfill_event(**args) unless args.has_key?(:timestamp) raise ArgumentError.new('missing parameters: timestamp') end event = Event.new(**args) post("#{@url_prefix}/v#{@api_version}/backfill/#{event.name}", event.serializable_hash) end |
#send_event(**args) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/ravelin/client.rb', line 28 def send_event(**args) score = args.delete(:score) event = Event.new(**args) score_param = score ? "?score=true" : nil post("#{@url_prefix}/v#{@api_version}/#{event.name}#{score_param}", event.serializable_hash) end |
#send_tag(**args) ⇒ Object
47 48 49 50 51 |
# File 'lib/ravelin/client.rb', line 47 def send_tag(**args) tag = Tag.new(**args) post("#{@url_prefix}/v#{@api_version}/tag/customer", tag.serializable_hash) end |