Class: Koko::Tracker::Client

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/koko/tracker/client.rb

Constant Summary

Constants included from Utils

Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON

Instance Method Summary collapse

Methods included from Utils

#date_in_iso8601, #datetime_in_iso8601, #formatted_offset, #isoify_dates, #isoify_dates!, #seconds_to_utc_offset, #stringify_keys, #symbolize_keys, #symbolize_keys!, #time_in_iso8601, #uid

Constructor Details

#initialize(attrs = {}) ⇒ Client

public: Creates a new client

attrs - Hash

:auth           - String of your authorization key
:max_queue_size - Fixnum of the max calls to remain queued (optional)
:on_error       - Proc which handles error calls from the API


16
17
18
19
20
21
22
23
# File 'lib/koko/tracker/client.rb', line 16

def initialize attrs = {}
  symbolize_keys! attrs

  @auth = attrs[:auth]
  @options = attrs

  check_auth!
end

Instance Method Details

#track_content(attrs) ⇒ Object

public: Track content

attrs - Hash (see docs.koko.ai/#track-endpoints)



28
29
30
31
32
33
34
35
36
# File 'lib/koko/tracker/client.rb', line 28

def track_content attrs
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.now
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.iso8601

  handle_response(Request.new(path: '/track/content').post(@auth, attrs)).body
end

#track_flag(attrs) ⇒ Object

public: Track flag

attrs - Hash (see docs.koko.ai/#track-endpoints)



41
42
43
44
45
46
47
48
49
# File 'lib/koko/tracker/client.rb', line 41

def track_flag attrs
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.now
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.iso8601

  handle_response(Request.new(path: '/track/flag').post(@auth, attrs)).body
end

#track_moderation(attrs) ⇒ Object

public: Track moderation

attrs - Hash (see docs.koko.ai/#track-endpoints)



54
55
56
57
58
59
60
61
62
# File 'lib/koko/tracker/client.rb', line 54

def track_moderation attrs
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.now
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.iso8601

  handle_response(Request.new(path: '/track/moderation').post(@auth, attrs)).body
end