openpanel-sdk 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +14 -2
- data/Rakefile +2 -2
- data/lib/openpanel/sdk/identify_user.rb +3 -1
- data/lib/openpanel/sdk/tracker.rb +33 -29
- data/lib/openpanel/sdk/version.rb +3 -1
- data/lib/openpanel/sdk.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71d49e2703660c679a0fa144f8b12f121f0014cca877ea1e9858d3dfd3e80af1
|
|
4
|
+
data.tar.gz: b5d6a0b7a266fbe4f6efeaacccb509c77a9950371ad2b5ed0bb98e4883ef5e7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38f322c5ab571c40cf5a145514e4b648421d4531097bb90af3bef33088a3464d4fc306eae886e071c40942157f1b720c9f68574f833a5bfa1d00181196074284
|
|
7
|
+
data.tar.gz: 2b12b3273ba1c973a41eff1fa1abc03ac8274334fd7c17679e760ad5cc4c0a011d2ee4f7d059622ccd9a963674734376ee7e4306346c3d7e2884d4f9f563a15c
|
data/README.md
CHANGED
|
@@ -16,9 +16,21 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
|
16
16
|
gem install openpanel-sdk
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
## Usage
|
|
19
|
+
## Usage example
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Use the gem by adding the following line to the Gemfile:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
tracker = OpenPanel::SDK::Tracker.new
|
|
25
|
+
identify_user = OpenPanel::SDK::IdentifyUser.new
|
|
26
|
+
|
|
27
|
+
# ... set user props
|
|
28
|
+
|
|
29
|
+
tracker.identify identify_user
|
|
30
|
+
tracker.track 'test_event', payload: { name: 'test' }
|
|
31
|
+
tracker.increment_property identify_user, 'test_property', 1
|
|
32
|
+
tracker.decrement_property identify_user, 'test_property', 1
|
|
33
|
+
```
|
|
22
34
|
|
|
23
35
|
## Development
|
|
24
36
|
|
data/Rakefile
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
2
4
|
|
|
3
5
|
module OpenPanel
|
|
4
6
|
module SDK
|
|
5
7
|
class OpenPanelError < StandardError; end
|
|
6
8
|
|
|
7
9
|
class Tracker
|
|
8
|
-
TRACKING_TYPE_IDENTIFY =
|
|
9
|
-
TRACKING_TYPE_TRACK =
|
|
10
|
-
TRACKING_TYPE_INCREMENT =
|
|
11
|
-
TRACKING_TYPE_DECREMENT =
|
|
10
|
+
TRACKING_TYPE_IDENTIFY = 'identify'
|
|
11
|
+
TRACKING_TYPE_TRACK = 'track'
|
|
12
|
+
TRACKING_TYPE_INCREMENT = 'increment'
|
|
13
|
+
TRACKING_TYPE_DECREMENT = 'decrement'
|
|
12
14
|
|
|
13
15
|
attr_reader :headers
|
|
14
16
|
|
|
15
17
|
##############################
|
|
16
18
|
# Initialize OpenPanel tracker
|
|
19
|
+
# @param disabled [Boolean] disable sending tracking events, defaults to false
|
|
17
20
|
##############################
|
|
18
|
-
def initialize
|
|
21
|
+
def initialize(disabled: false)
|
|
19
22
|
@headers = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
'Content-Type' => 'application/json',
|
|
24
|
+
'openpanel-client-id' => ENV['OPENPANEL_CLIENT_ID'],
|
|
25
|
+
'openpanel-client-secret' => ENV['OPENPANEL_CLIENT_SECRET']
|
|
23
26
|
}
|
|
27
|
+
@disabled = disabled
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
##############################
|
|
@@ -45,32 +49,26 @@ module OpenPanel
|
|
|
45
49
|
send_request payload: payload
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
##############################
|
|
49
|
-
# Track page view in OpenPanel
|
|
50
|
-
# @param user [User] user to track
|
|
51
|
-
# @param path [String] page path
|
|
52
|
-
##############################
|
|
53
|
-
def track_page_view(user, path)
|
|
54
|
-
if user
|
|
55
|
-
track "view", payload: { profileId: user.profile_id, path: path }
|
|
56
|
-
else
|
|
57
|
-
track "view", payload: { path: path }
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
52
|
##############################
|
|
62
53
|
# Identify user in OpenPanel
|
|
63
54
|
# https://openpanel.dev/docs/api/track
|
|
64
55
|
# @param user [OpenPanel::SDK::IdentifyUser] user to identify
|
|
65
56
|
##############################
|
|
66
57
|
def identify(user)
|
|
67
|
-
payload = { profileId: user.profile_id, firstName: user.first_name, lastName: user.last_name,
|
|
58
|
+
payload = { profileId: user.profile_id, firstName: user.first_name, lastName: user.last_name,
|
|
59
|
+
email: user.email }
|
|
68
60
|
payload = { type: TRACKING_TYPE_IDENTIFY, payload: payload }
|
|
69
61
|
|
|
70
62
|
send_request payload: payload
|
|
71
63
|
end
|
|
72
64
|
|
|
73
|
-
|
|
65
|
+
##############################
|
|
66
|
+
# Decrement property in OpenPanel
|
|
67
|
+
# @param user [User] user to identify
|
|
68
|
+
# @param property [String] property to increment
|
|
69
|
+
# @param value [Integer] value to increment by
|
|
70
|
+
#############################
|
|
71
|
+
def increment_property(user, property = 'visits', value = 1)
|
|
74
72
|
payload = { profileId: user.profile_id, property: property, value: value }
|
|
75
73
|
payload = { type: TRACKING_TYPE_INCREMENT, payload: payload }
|
|
76
74
|
|
|
@@ -80,8 +78,10 @@ module OpenPanel
|
|
|
80
78
|
##############################
|
|
81
79
|
# Decrement property in OpenPanel
|
|
82
80
|
# @param user [User] user to identify
|
|
81
|
+
# @param property [String] property to increment
|
|
82
|
+
# @param value [Integer] value to decrement by
|
|
83
83
|
#############################
|
|
84
|
-
def decrement_property(user, property =
|
|
84
|
+
def decrement_property(user, property = 'visits', value = 1)
|
|
85
85
|
payload = { profileId: user.profile_id, property: property, value: value }
|
|
86
86
|
payload = { type: TRACKING_TYPE_DECREMENT, payload: payload }
|
|
87
87
|
|
|
@@ -94,17 +94,21 @@ module OpenPanel
|
|
|
94
94
|
# Send request to OpenPanel API
|
|
95
95
|
# @param url [String] API endpoint URL
|
|
96
96
|
# @param payload [Hash] request payload
|
|
97
|
+
# @return [Faraday::Response] The Faraday plain response object
|
|
98
|
+
# @raise [OpenPanel::SDK::OpenPanelError] if request fails
|
|
97
99
|
##############################
|
|
98
|
-
def send_request(url: ENV[
|
|
100
|
+
def send_request(url: ENV['OPENPANEL_TRACK_URL'], payload: {})
|
|
101
|
+
return if @disabled
|
|
102
|
+
|
|
99
103
|
response = Faraday.post url, payload.to_json, @headers
|
|
100
104
|
|
|
101
105
|
case response.status
|
|
102
106
|
when 401
|
|
103
|
-
raise OpenPanel::SDK::OpenPanelError,
|
|
107
|
+
raise OpenPanel::SDK::OpenPanelError, 'Unauthorized'
|
|
104
108
|
when 429
|
|
105
|
-
raise OpenPanel::SDK::OpenPanelError,
|
|
109
|
+
raise OpenPanel::SDK::OpenPanelError, 'Too many requests'
|
|
106
110
|
when 500
|
|
107
|
-
raise OpenPanel::SDK::OpenPanelError,
|
|
111
|
+
raise OpenPanel::SDK::OpenPanelError, 'Internal server error'
|
|
108
112
|
else
|
|
109
113
|
response
|
|
110
114
|
end
|
data/lib/openpanel/sdk.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openpanel-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Stätter
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: OpenPanel SDK for Ruby
|
|
14
14
|
email:
|