gitlab-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d02a90e3d161d2e2edc18fb76a08dc011bc567d56ef7d29d62c3df22c40c3ebc
4
+ data.tar.gz: 15e64bfc91b0e4f23dddc7fc07d32e0906232bca06d9f4f4c36dbaa17b6c19c5
5
+ SHA512:
6
+ metadata.gz: d9c5ed95c3d1bcdef50e777a04a42e64ccc6d0f4bb77fc6385e8050248d81f51c3f16f898793468512dfd90a5fd85e63f343bb4afc76b73fee0f8a73a45a8a9d
7
+ data.tar.gz: cf474d2e60515b417caa2230c81d24d620f464761ed835b1fa71f37968fecf327bcee8ea7a69a59ddf746e9cef149f236824baee967e03ea8c0ef89edbd8058c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ inherit_gem:
2
+ gitlab-styles:
3
+ - rubocop-default.yml
4
+
5
+ CodeReuse/ActiveRecord:
6
+ Exclude:
7
+ - spec/**/*.rb
8
+
9
+ RSpec/FilePath:
10
+ Exclude:
11
+ - spec/gitlab-sdk/version_spec.rb
12
+ CustomTransform:
13
+ GitlabSDK: gitlab-sdk
14
+
15
+ RSpec/MultipleMemoizedHelpers:
16
+ Max: 10
17
+
18
+ Naming/FileName:
19
+ Exclude:
20
+ - lib/gitlab-sdk.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in gitlab-sdk.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitlab-sdk (0.1.0)
5
+ activesupport (~> 7.0)
6
+ rake (~> 13.0)
7
+ snowplow-tracker (~> 0.8.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (7.0.4.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ addressable (2.8.4)
18
+ public_suffix (>= 2.0.2, < 6.0)
19
+ ast (2.4.2)
20
+ concurrent-ruby (1.2.2)
21
+ crack (0.4.5)
22
+ rexml
23
+ diff-lcs (1.5.0)
24
+ gitlab-styles (10.0.0)
25
+ rubocop (~> 1.43.0)
26
+ rubocop-graphql (~> 0.18)
27
+ rubocop-performance (~> 1.15)
28
+ rubocop-rails (~> 2.17)
29
+ rubocop-rspec (~> 2.18)
30
+ hashdiff (1.0.1)
31
+ i18n (1.12.0)
32
+ concurrent-ruby (~> 1.0)
33
+ json (2.6.3)
34
+ minitest (5.18.0)
35
+ parallel (1.22.1)
36
+ parser (3.2.2.0)
37
+ ast (~> 2.4.1)
38
+ public_suffix (5.0.1)
39
+ rack (3.0.7)
40
+ rainbow (3.1.1)
41
+ rake (13.0.6)
42
+ regexp_parser (2.7.0)
43
+ rexml (3.2.5)
44
+ rspec (3.12.0)
45
+ rspec-core (~> 3.12.0)
46
+ rspec-expectations (~> 3.12.0)
47
+ rspec-mocks (~> 3.12.0)
48
+ rspec-core (3.12.1)
49
+ rspec-support (~> 3.12.0)
50
+ rspec-expectations (3.12.2)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.12.0)
53
+ rspec-mocks (3.12.5)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.12.0)
56
+ rspec-support (3.12.0)
57
+ rubocop (1.43.0)
58
+ json (~> 2.3)
59
+ parallel (~> 1.10)
60
+ parser (>= 3.2.0.0)
61
+ rainbow (>= 2.2.2, < 4.0)
62
+ regexp_parser (>= 1.8, < 3.0)
63
+ rexml (>= 3.2.5, < 4.0)
64
+ rubocop-ast (>= 1.24.1, < 2.0)
65
+ ruby-progressbar (~> 1.7)
66
+ unicode-display_width (>= 2.4.0, < 3.0)
67
+ rubocop-ast (1.28.0)
68
+ parser (>= 3.2.1.0)
69
+ rubocop-capybara (2.17.1)
70
+ rubocop (~> 1.41)
71
+ rubocop-graphql (0.19.0)
72
+ rubocop (>= 0.87, < 2)
73
+ rubocop-performance (1.17.1)
74
+ rubocop (>= 1.7.0, < 2.0)
75
+ rubocop-ast (>= 0.4.0)
76
+ rubocop-rails (2.19.0)
77
+ activesupport (>= 4.2.0)
78
+ rack (>= 1.1)
79
+ rubocop (>= 1.33.0, < 2.0)
80
+ rubocop-rspec (2.19.0)
81
+ rubocop (~> 1.33)
82
+ rubocop-capybara (~> 2.17)
83
+ ruby-progressbar (1.13.0)
84
+ snowplow-tracker (0.8.0)
85
+ tzinfo (2.0.6)
86
+ concurrent-ruby (~> 1.0)
87
+ unicode-display_width (2.4.2)
88
+ webmock (3.18.1)
89
+ addressable (>= 2.8.0)
90
+ crack (>= 0.3.2)
91
+ hashdiff (>= 0.4.0, < 2.0.0)
92
+
93
+ PLATFORMS
94
+ arm64-darwin-21
95
+
96
+ DEPENDENCIES
97
+ gitlab-sdk!
98
+ gitlab-styles (~> 10.0.0)
99
+ rspec (~> 3.0)
100
+ webmock
101
+
102
+ BUNDLED WITH
103
+ 2.3.22
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # GitLab Application SDK - Ruby
2
+
3
+ This SDK is for using GitLab Application Services with Ruby.
4
+
5
+ ## How to use the SDK
6
+
7
+ ### Using the gem
8
+
9
+ Add the gem to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gitlab-sdk', '~> 0.1.0', git: 'git@gitlab.com:gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb.git'
13
+ ```
14
+
15
+ ### Using the client
16
+
17
+ Initialize the client:
18
+
19
+ ```ruby
20
+ client = GitlabSDK::Client.new(app_id: 'YOUR_APP_ID', host: 'YOUR_HOST')
21
+ ```
22
+
23
+ ## Client initialization options
24
+
25
+ | Option | Description |
26
+ |:----------------|:------------------------------------------------------------------------------------------------------------------------------------------|
27
+ | `app_id` | The ID specified in the GitLab Project Analytics setup guide. It ensures your data is sent to your analytics instance. |
28
+ | `host` | The GitLab Project Analytics instance specified in the setup guide. |
29
+
30
+ ## Methods
31
+
32
+ ### `identify`
33
+
34
+ Used to associate a user and their attributes with the session and tracking events.
35
+
36
+ ```ruby
37
+ client.identify('123abc', { user_name: 'Matthew' })
38
+ ```
39
+
40
+ | Property | Type | Description |
41
+ |:-----------------|:---------|:------------------------------------------------------------------------------|
42
+ | `user_id` | `String` | The ID of the user. |
43
+ | `user_attributes` | `Hash` | Optional. The user attributes to add to the session and tracking events. |
44
+
45
+ ### `track`
46
+
47
+ Used to trigger a custom event.
48
+
49
+ ```ruby
50
+ client.track(event_name, event_attributes)
51
+ ```
52
+
53
+ | Property | Type | Description |
54
+ |:------------------|:----------|:-----------------------------------------------------------------|
55
+ | `event_name` | `String` | The name of the event. |
56
+ | `event_attributes` | `Hash` | The event attributes to add to the tracked event. |
57
+
58
+ ## Developing with the devkit
59
+
60
+ To develop with a local Snowplow pipeline, use Analytics devkit's [Snowplow setup](https://gitlab.com/gitlab-org/analytics-section/product-analytics/devkit/-/tree/main#setup).
61
+
62
+ To test the gem's functionality, run `bin/console`.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "version"
4
+ require_relative "current_user"
5
+ require 'snowplow-tracker'
6
+
7
+ module GitlabSDK
8
+ class Client
9
+ SCHEMAS = {
10
+ custom_event: 'iglu:com.gitlab/custom_event/jsonschema/1-0-0',
11
+ user_context: 'iglu:com.gitlab/user_context/jsonschema/1-0-0'
12
+ }.freeze
13
+ DEFAULT_TRACKER_NAMESPACE = 'gitlab'
14
+
15
+ def initialize(app_id:, host:)
16
+ emitter = SnowplowTracker::Emitter.new(endpoint: host)
17
+
18
+ @tracker = SnowplowTracker::Tracker.new(
19
+ emitters: emitter,
20
+ app_id: app_id,
21
+ namespace: DEFAULT_TRACKER_NAMESPACE
22
+ )
23
+ end
24
+
25
+ def track(event_name, event_payload)
26
+ self_desc_json = SnowplowTracker::SelfDescribingJson.new(
27
+ SCHEMAS[:custom_event],
28
+ name: event_name,
29
+ props: event_payload
30
+ )
31
+
32
+ track_arguments = { event_json: self_desc_json }
33
+ set_user_data(track_arguments)
34
+
35
+ tracker.track_self_describing_event(**track_arguments)
36
+ end
37
+
38
+ def identify(user_id, user_attributes = {})
39
+ GitlabSDK::CurrentUser.user_id = user_id
40
+ GitlabSDK::CurrentUser.user_attributes = user_attributes
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :tracker
46
+
47
+ def set_user_data(track_arguments)
48
+ set_user_id
49
+ set_user_context(track_arguments)
50
+ end
51
+
52
+ def set_user_id
53
+ user_id = GitlabSDK::CurrentUser.user_id
54
+
55
+ subject = SnowplowTracker::Subject.new
56
+ subject.set_user_id(user_id) if user_id
57
+ tracker.set_subject(subject)
58
+ end
59
+
60
+ def set_user_context(track_arguments)
61
+ user_attributes = GitlabSDK::CurrentUser.user_attributes || {}
62
+
63
+ return if user_attributes.empty?
64
+
65
+ user_context = SnowplowTracker::SelfDescribingJson.new(
66
+ SCHEMAS[:user_context],
67
+ user_attributes
68
+ )
69
+ track_arguments[:context] = [user_context]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module GitlabSDK
6
+ class CurrentUser < ::ActiveSupport::CurrentAttributes
7
+ attribute :user_id, :user_attributes
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabSDK
4
+ VERSION = "0.1.0"
5
+ end
data/lib/gitlab-sdk.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gitlab-sdk/client"
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - GitLab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: snowplow-tracker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: gitlab-styles
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 10.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Client side Ruby SDK for GitLab Application services
98
+ email:
99
+ - gitlab_rubygems@gitlab.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rspec"
105
+ - ".rubocop.yml"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - README.md
109
+ - Rakefile
110
+ - lib/gitlab-sdk.rb
111
+ - lib/gitlab-sdk/client.rb
112
+ - lib/gitlab-sdk/current_user.rb
113
+ - lib/gitlab-sdk/version.rb
114
+ homepage: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb
115
+ licenses:
116
+ - MIT
117
+ metadata:
118
+ allowed_push_host: https://rubygems.org
119
+ homepage_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb
120
+ source_code_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb
121
+ changelog_uri: https://gitlab.com/gitlab-org/analytics-section/product-analytics/gl-application-sdk-rb/-/releases
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.2.22
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Client side Ruby SDK for GitLab Application services
141
+ test_files: []