openpanel-sdk 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9777c4309f179a7458c3db1aa7faa136689ba9952830614c109ff29634950f1a
4
- data.tar.gz: 827f2e8b345398fc176eb122b2d1eaa0aec28d0179c9ad94a01bd8b613572754
3
+ metadata.gz: 23f101cbdcbec005b038d9f8dd1452b4d1d4b6cd835fe5b2a02c00876d386a16
4
+ data.tar.gz: 20cea0702b357dbb44668d0b9a24f04375482bd66fe7f974cfb14e78d8237bba
5
5
  SHA512:
6
- metadata.gz: 79e882b70b392f8e475057be327696ccc79b4fca5bfbe48d78baffb3deaf9a5781cedb52cb6bc8d55ffeaa8a4e4ef3a3b9624943cd4d2322c151cc32d9a97b5c
7
- data.tar.gz: 9b0814453c46b72f92c37a077804ccaaf413cd1e0e15bf23c4de31a51e0bb99f8a45f9ef7e3a7c00f577c7a3fded802fea3372f6cdb6ca1baab3e00e2fd1f77f
6
+ metadata.gz: 1d5d4ff649654fff8094f9d3a50190b095c89b977a7dddf5d1f0192c47006988fb3c3fc4bc3368791c21e2261dee5eacfabb327f1896dd6e6acbfc0750d63853
7
+ data.tar.gz: 05e9b1ce5f442555f7be902639ff14a89058234b66d337812547b66d7250f106e775e0d25ee58b5938d89652ebd7a77e810388fbbd98fc24e887545806bdb4b8
@@ -2,6 +2,12 @@
2
2
 
3
3
  module OpenPanel
4
4
  module SDK
5
+ # Identify user payload class. Use this class to identify a user in OpenPanel.
6
+ # @attr profile_id [String] user profile ID
7
+ # @attr email [String] user email address
8
+ # @attr first_name [String] user first name
9
+ # @attr last_name [String] user last name
10
+ # @attr properties [Hash] user properties
5
11
  class IdentifyUser
6
12
  attr_accessor :profile_id, :email, :first_name, :last_name, :properties
7
13
 
@@ -6,6 +6,8 @@ module OpenPanel
6
6
  module SDK
7
7
  class OpenPanelError < StandardError; end
8
8
 
9
+ # OpenPanel SDK tracker class. Use this class to track events in OpenPanel by using
10
+ # the OpenPanel backend API.
9
11
  class Tracker
10
12
  TRACKING_TYPE_IDENTIFY = 'identify'
11
13
  TRACKING_TYPE_TRACK = 'track'
@@ -14,12 +16,10 @@ module OpenPanel
14
16
 
15
17
  attr_reader :headers, :global_properties
16
18
 
17
- ##############################
18
19
  # Initialize OpenPanel tracker
19
20
  # @param global_props [Hash] global properties to send with every `track` and `identify` event
20
21
  # @param disabled [Boolean] disable sending tracking events, defaults to false
21
- ##############################
22
- def initialize(global_props: {}, disabled: false)
22
+ def initialize(global_props, disabled: false)
23
23
  @headers = {
24
24
  'Content-Type' => 'application/json',
25
25
  'openpanel-client-id' => ENV['OPENPANEL_CLIENT_ID'],
@@ -29,22 +29,18 @@ module OpenPanel
29
29
  @global_properties = global_props
30
30
  end
31
31
 
32
- ##############################
33
32
  # Set custom header for OpenPanel request
34
33
  # @param key [String] header key
35
34
  # @param value [String] header value
36
- ##############################
37
35
  def set_header(key, value)
38
36
  @headers[key] = value
39
37
  end
40
38
 
41
- ##############################
42
39
  # Track events in OpenPanel
43
40
  # https://openpanel.dev/docs/api/track
44
41
  # @param event [String] name of event
45
42
  # @param tracking_type [String]
46
43
  # @param payload [Hash] event payload
47
- ##############################
48
44
  def track(event, tracking_type: TRACKING_TYPE_TRACK, payload: {})
49
45
  payload = global_properties.merge(payload) unless global_properties.empty?
50
46
  payload = { type: tracking_type, payload: { name: event, properties: payload } }
@@ -52,11 +48,9 @@ module OpenPanel
52
48
  send_request payload: payload
53
49
  end
54
50
 
55
- ##############################
56
51
  # Identify user in OpenPanel
57
52
  # https://openpanel.dev/docs/api/track
58
53
  # @param user [OpenPanel::SDK::IdentifyUser] user to identify
59
- ##############################
60
54
  def identify(user)
61
55
  properties = user.properties.merge(global_properties) unless global_properties.empty?
62
56
  payload = { profileId: user.profile_id, firstName: user.first_name, lastName: user.last_name,
@@ -66,12 +60,10 @@ module OpenPanel
66
60
  send_request payload: payload
67
61
  end
68
62
 
69
- ##############################
70
63
  # Decrement property in OpenPanel
71
- # @param user [User] user to identify
64
+ # @param user [OpenPanel::SDK::IdentifyUser] user to identify
72
65
  # @param property [String] property to increment
73
66
  # @param value [Integer] value to increment by
74
- #############################
75
67
  def increment_property(user, property = 'visits', value = 1)
76
68
  payload = { profileId: user.profile_id, property: property, value: value }
77
69
  payload = { type: TRACKING_TYPE_INCREMENT, payload: payload }
@@ -79,12 +71,10 @@ module OpenPanel
79
71
  send_request payload: payload
80
72
  end
81
73
 
82
- ##############################
83
74
  # Decrement property in OpenPanel
84
- # @param user [User] user to identify
75
+ # @param user [OpenPanel::SDK::IdentifyUser] user to identify
85
76
  # @param property [String] property to increment
86
77
  # @param value [Integer] value to decrement by
87
- #############################
88
78
  def decrement_property(user, property = 'visits', value = 1)
89
79
  payload = { profileId: user.profile_id, property: property, value: value }
90
80
  payload = { type: TRACKING_TYPE_DECREMENT, payload: payload }
@@ -94,13 +84,11 @@ module OpenPanel
94
84
 
95
85
  private
96
86
 
97
- ##############################
98
87
  # Send request to OpenPanel API
99
88
  # @param url [String] API endpoint URL
100
89
  # @param payload [Hash] request payload
101
90
  # @return [Faraday::Response] The Faraday plain response object
102
91
  # @raise [OpenPanel::SDK::OpenPanelError] if request fails
103
- ##############################
104
92
  def send_request(url: ENV['OPENPANEL_TRACK_URL'], payload: {})
105
93
  return if @disabled
106
94
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenPanel
4
4
  module SDK
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
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.2.0
4
+ version: 0.2.1
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-29 00:00:00.000000000 Z
11
+ date: 2025-11-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: OpenPanel SDK for Ruby
14
14
  email: