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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f058e44eeada090f73556e3717608d7f61868776840970d2ca51ffa14120b108
4
- data.tar.gz: c9a7d201a55dca8e07096e13e8a5d7e415970cd2ccda2b3bae1ff2c08280db8a
3
+ metadata.gz: 71d49e2703660c679a0fa144f8b12f121f0014cca877ea1e9858d3dfd3e80af1
4
+ data.tar.gz: b5d6a0b7a266fbe4f6efeaacccb509c77a9950371ad2b5ed0bb98e4883ef5e7f
5
5
  SHA512:
6
- metadata.gz: fbe6e1946cb014f429fdce91ab381900f7701a536a6142b8eac6cdf7a957f8e2264933f525f90ac9b20eba370c826dfa323cbf018cb29d62405a4fbb7e51560e
7
- data.tar.gz: 1b3254a51f15c7a4604013c56b523fe1e53263d32c0c815e71a578970e08b097357f30462015442eaa4b523655eb885961c0114871bf5ea82e346d4ef284c0c5
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
- TODO: Write usage instructions here
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,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OpenPanel
2
4
  module SDK
3
5
  class IdentifyUser
4
6
  attr_accessor :profile_id, :email, :first_name, :last_name, :properties
5
7
 
6
- def to_json
8
+ def to_json(*_args)
7
9
  {
8
10
  profileId: profile_id,
9
11
  email: email,
@@ -1,26 +1,30 @@
1
- require "faraday"
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 = "identify"
9
- TRACKING_TYPE_TRACK = "track"
10
- TRACKING_TYPE_INCREMENT = "increment"
11
- TRACKING_TYPE_DECREMENT = "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
- "Content-Type" => "application/json",
21
- "openpanel-client-id" => ENV["OPENPANEL_CLIENT_ID"],
22
- "openpanel-client-secret" => ENV["OPENPANEL_CLIENT_SECRET"],
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, email: user.email }
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
- def increment_property(user, property = "visits", value = 1)
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 = "visits", value = 1)
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["OPENPANEL_TRACK_URL"], payload: {})
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, "Unauthorized"
107
+ raise OpenPanel::SDK::OpenPanelError, 'Unauthorized'
104
108
  when 429
105
- raise OpenPanel::SDK::OpenPanelError, "Too many requests"
109
+ raise OpenPanel::SDK::OpenPanelError, 'Too many requests'
106
110
  when 500
107
- raise OpenPanel::SDK::OpenPanelError, "Internal server error"
111
+ raise OpenPanel::SDK::OpenPanelError, 'Internal server error'
108
112
  else
109
113
  response
110
114
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OpenPanel
2
4
  module SDK
3
- VERSION = "0.1.1"
5
+ VERSION = '0.1.3'
4
6
  end
5
7
  end
data/lib/openpanel/sdk.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "sdk/identify_user"
4
- require_relative "sdk/tracker"
5
- require_relative "sdk/version"
3
+ require_relative 'sdk/identify_user'
4
+ require_relative 'sdk/tracker'
5
+ require_relative 'sdk/version'
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.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-28 00:00:00.000000000 Z
11
+ date: 2025-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: OpenPanel SDK for Ruby
14
14
  email: