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, &block) ⇒ Object

public: Track content

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/koko/tracker/client.rb', line 28

def track_content attrs, &block
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.new
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.to_f

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

  if block
    block.call(response.body)
  end

  true
end

#track_flag(attrs) ⇒ Object

public: Track flag

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



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/koko/tracker/client.rb', line 47

def track_flag attrs
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.new
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.to_f

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

  true
end

#track_moderation(attrs) ⇒ Object

public: Track moderation

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



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/koko/tracker/client.rb', line 62

def track_moderation attrs
  symbolize_keys! attrs

  timestamp = attrs[:created_at] || Time.new
  check_timestamp! timestamp
  attrs[:created_at] = timestamp.to_f

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

  true
end