gitlab-sdk 0.2.6 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c5951cd03dfb98fbcb92ef04436e50e984117040e59cb991a3bd8f4d8b7557e
4
- data.tar.gz: 820348b1c3ba2fa2b46ca06d1660069518f827d307042c9c3536195f1da8a93e
3
+ metadata.gz: aea01fe6700609b32e376e19478b48d269f023e1f5276b823e4f7497c050cacb
4
+ data.tar.gz: a9bda3fc4c97fe8fd207144d004a8abb71fff72d81232630327461fdfbe1f835
5
5
  SHA512:
6
- metadata.gz: 5fc3cb9ab2a0598948471499bc4ef79d76ff46f3c57da9316a98c2b19ea49d8c11ef4b812b7d977809417569c9581e642a2151b27b847643a215c071321123e0
7
- data.tar.gz: de9b05e5bab69adc5c6e3687bbd0f88d86e71be845768d6cbf45cd6904b44eba8d93758c3f8659ab0fbc838f8f06ce61992fd8cb7ad7c7850fd467c5e2cfc25f
6
+ metadata.gz: 1a673a3212d5f457d1ea521944e69d338d759d8087b182859eb179b85e21918d81e228529d20dccf0b7c39a7b4ba8c350a04de5bbea636d33418ebede975bd86
7
+ data.tar.gz: 218fd1c7c44fd37faba7d1dff14dd106a7cabd83a5b13e2cb89f029f7b3504430641674c6249346202419b60dfd69ae7ce38aa9246c5873646dedecc08556ea4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-sdk (0.2.6)
4
+ gitlab-sdk (0.3.1)
5
5
  activesupport (>= 5.2.0)
6
6
  rake (~> 13.0)
7
7
  snowplow-tracker (~> 0.8.0)
data/README.md CHANGED
@@ -26,9 +26,29 @@ client = GitlabSDK::Client.new(app_id: 'YOUR_APP_ID', host: 'YOUR_HOST')
26
26
  |:----------------|:---------------------------------------------------------------------------------------------------------------------------------------------------|
27
27
  | `app_id` | The ID specified in the GitLab Project Analytics setup guide. It ensures your data is sent to your analytics instance. |
28
28
  | `host` | The GitLab Project Analytics instance specified in the setup guide. When using a non-standard port, includde it here, e.g. `http://localhost:9091` |
29
+ | `buffer_size` | Optional. Default `1`. How many events are sent in one request at a time. Setting more than `1` will change the HTTP method from `GET` to `POST`. |
30
+ | `async` | Optional. Default `true`. Use `AsyncEmitter` instead of `Emitter` for non-blocking requests. |
31
+
32
+ For more details see Snowplow Ruby Tracker [docs](https://snowplow.github.io/snowplow-ruby-tracker/).
29
33
 
30
34
  ## Methods
31
35
 
36
+ ### `flush`
37
+
38
+ Used to manually flush all events from Snowplow Ruby Tracker's emitters, defaults to synchronous.
39
+
40
+ ```ruby
41
+ # Flush events synchronously (default)
42
+ client.flush_events
43
+
44
+ # Flush events asynchronously
45
+ client.flush_events(async: true)
46
+ ```
47
+
48
+ | Property | Type | Description |
49
+ |:-----------------|:----------|:--------------------------------------------------------------------------|
50
+ | `async` | `Boolean` | Optional. Default `false`. Use `true` to flush all events asynchronously. |
51
+
32
52
  ### `identify`
33
53
 
34
54
  Used to associate a user and their attributes with the session and tracking events.
@@ -15,8 +15,8 @@ module GitlabSDK
15
15
 
16
16
  HostHasNoSchemeError = Class.new(StandardError)
17
17
 
18
- def initialize(app_id:, host:)
19
- emitter = build_emitter(host)
18
+ def initialize(app_id:, host:, buffer_size: 1, async: true)
19
+ emitter = build_emitter(host, buffer_size: buffer_size, async: async)
20
20
 
21
21
  @tracker = SnowplowTracker::Tracker.new(
22
22
  emitters: emitter,
@@ -25,7 +25,7 @@ module GitlabSDK
25
25
  )
26
26
  end
27
27
 
28
- def track(event_name, event_payload)
28
+ def track(event_name, event_payload = {})
29
29
  self_desc_json = SnowplowTracker::SelfDescribingJson.new(
30
30
  SCHEMAS[:custom_event],
31
31
  name: event_name,
@@ -45,16 +45,31 @@ module GitlabSDK
45
45
  GitlabSDK::CurrentUser.user_attributes = user_attributes
46
46
  end
47
47
 
48
+ def flush_events(async: false)
49
+ tracker.flush(async: async)
50
+ end
51
+
48
52
  private
49
53
 
50
54
  attr_reader :tracker
51
55
 
52
- def build_emitter(host)
56
+ def build_emitter(host, buffer_size:, async:)
53
57
  uri = URI(host)
54
58
  raise HostHasNoSchemeError unless uri.scheme
59
+ raise ArgumentError, 'buffer_size has to be positive' unless buffer_size.positive?
55
60
 
56
61
  endpoint = "#{uri.hostname}:#{uri.port}#{uri.path}"
57
- SnowplowTracker::Emitter.new(endpoint: endpoint, options: { protocol: uri.scheme })
62
+ method = buffer_size > 1 ? 'post' : 'get'
63
+ emitter_class = async ? SnowplowTracker::AsyncEmitter : SnowplowTracker::Emitter
64
+
65
+ emitter_class.new(
66
+ endpoint: endpoint,
67
+ options: {
68
+ protocol: uri.scheme,
69
+ method: method,
70
+ buffer_size: buffer_size
71
+ }
72
+ )
58
73
  end
59
74
 
60
75
  def set_subject_data
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabSDK
4
- VERSION = "0.2.6"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2024-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -119,7 +119,7 @@ metadata:
119
119
  homepage_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb
120
120
  source_code_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb
121
121
  changelog_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb/-/releases
122
- post_install_message:
122
+ post_install_message:
123
123
  rdoc_options: []
124
124
  require_paths:
125
125
  - lib
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.1.6
138
- signing_key:
137
+ rubygems_version: 3.3.26
138
+ signing_key:
139
139
  specification_version: 4
140
140
  summary: Client side Ruby SDK for GitLab Application services
141
141
  test_files: []