Class: GitlabSDK::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab-sdk/client.rb

Constant Summary collapse

SCHEMAS =
{
  custom_event: 'iglu:com.gitlab/custom_event/jsonschema/1-0-0',
  user_context: 'iglu:com.gitlab/user_context/jsonschema/1-0-0'
}.freeze
DEFAULT_TRACKER_NAMESPACE =
'gitlab'
USERAGENT =
"GitLab Analytics Ruby SDK/#{GitlabSDK::VERSION}"
HostHasNoSchemeError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(app_id:, host:, buffer_size: 1, async: true) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
# File 'lib/gitlab-sdk/client.rb', line 18

def initialize(app_id:, host:, buffer_size: 1, async: true)
  emitter = build_emitter(host, buffer_size: buffer_size, async: async)

  @tracker = SnowplowTracker::Tracker.new(
    emitters: emitter,
    app_id: app_id,
    namespace: DEFAULT_TRACKER_NAMESPACE
  )
end

Instance Method Details

#flush_events(async: false) ⇒ Object



48
49
50
# File 'lib/gitlab-sdk/client.rb', line 48

def flush_events(async: false)
  tracker.flush(async: async)
end

#identify(user_id, user_attributes = {}) ⇒ Object



43
44
45
46
# File 'lib/gitlab-sdk/client.rb', line 43

def identify(user_id, user_attributes = {})
  GitlabSDK::CurrentUser.user_id = user_id
  GitlabSDK::CurrentUser.user_attributes = user_attributes
end

#track(event_name, event_payload = {}) ⇒ Object



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

def track(event_name, event_payload = {})
  self_desc_json = SnowplowTracker::SelfDescribingJson.new(
    SCHEMAS[:custom_event],
    name: event_name,
    props: event_payload
  )

  track_arguments = { event_json: self_desc_json }

  set_subject_data
  set_user_context(track_arguments)

  tracker.track_self_describing_event(**track_arguments)
end