absmartly-sdk 1.2.2 → 1.2.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/Gemfile.lock +1 -1
- data/README.md +40 -7
- data/lib/absmartly/version.rb +1 -1
- data/lib/absmartly.rb +8 -1
- data/lib/client.rb +1 -2
- data/lib/client_config.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd9b4360f94a88304191f94a53fbab8ea76d70824d9ab5b3e593d69978989565
|
|
4
|
+
data.tar.gz: d3539a3334fe8c08e8c198fe9fece965f538eb4800ce2f4d52b06b94bb0c37cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8101361bf9fae3a18c04d4276a53a184fef7ab1c2bb0224e0018fe3ba1f84d04822968974fb749b0d902007040fa8b060fd83051c16c741d4a48e19ff3551204
|
|
7
|
+
data.tar.gz: 979f1e2e9b6e0f929cca1826441edda2e5385b11bcb6f068140dd45770aadcf8487d3cfe4f224c5bfbb3074a18ca9bb5fd4d4fee2cf12493f83ff2a95d6e14a0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -29,6 +29,10 @@ Absmartly.configure_client do |config|
|
|
|
29
29
|
config.api_key = "YOUR-API-KEY"
|
|
30
30
|
config.application = "website"
|
|
31
31
|
config.environment = "development"
|
|
32
|
+
config.connect_timeout = 3.0
|
|
33
|
+
config.connection_request_timeout = 3.0
|
|
34
|
+
config.retry_interval = 0.5
|
|
35
|
+
config.max_retries = 5
|
|
32
36
|
end
|
|
33
37
|
```
|
|
34
38
|
|
|
@@ -37,21 +41,50 @@ end
|
|
|
37
41
|
| Config | Type | Required? | Default | Description |
|
|
38
42
|
| :---------- | :----------------------------------- | :-------: | :-------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
39
43
|
| endpoint | `string` | ✅ | `undefined` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` |
|
|
40
|
-
|
|
|
44
|
+
| api_key | `string` | ✅ | `undefined` | Your API key which can be found on the Web Console. |
|
|
41
45
|
| environment | `"production"` or `"development"` | ✅ | `undefined` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. |
|
|
42
46
|
| application | `string` | ✅ | `undefined` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. |
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
47
|
+
| connect_timeout | `number` | ❌ | `3.0` | The socket connection timeout in seconds. |
|
|
48
|
+
| connection_request_timeout | `number` | ❌ | `3.0` | The request timeout in seconds. |
|
|
49
|
+
| retry_interval | `number` | ❌ | `0.5` | The initial retry interval in seconds (uses exponential backoff). |
|
|
50
|
+
| max_retries | `number` | ❌ | `5` | The maximum number of retries before giving up. |
|
|
51
|
+
| event_logger | `ContextEventLogger` | ❌ | See "Using a Custom Event Logger" below | A `ContextEventLogger` instance implementing `handle_event(event, data)` to receive SDK events. |
|
|
46
52
|
|
|
47
53
|
### Using a Custom Event Logger
|
|
48
54
|
|
|
49
55
|
The A/B Smartly SDK can be instantiated with an event logger used for all
|
|
50
56
|
contexts. In addition, an event logger can be specified when creating a
|
|
51
|
-
particular context
|
|
57
|
+
particular context in the context config.
|
|
52
58
|
|
|
53
|
-
```
|
|
54
|
-
|
|
59
|
+
```ruby
|
|
60
|
+
class MyEventLogger < ContextEventLogger
|
|
61
|
+
def handle_event(event, data)
|
|
62
|
+
case event
|
|
63
|
+
when EVENT_TYPE::EXPOSURE
|
|
64
|
+
puts "Exposure: #{data}"
|
|
65
|
+
when EVENT_TYPE::GOAL
|
|
66
|
+
puts "Goal: #{data}"
|
|
67
|
+
when EVENT_TYPE::ERROR
|
|
68
|
+
puts "Error: #{data}"
|
|
69
|
+
when EVENT_TYPE::PUBLISH
|
|
70
|
+
puts "Publish: #{data}"
|
|
71
|
+
when EVENT_TYPE::READY
|
|
72
|
+
puts "Ready: #{data}"
|
|
73
|
+
when EVENT_TYPE::REFRESH
|
|
74
|
+
puts "Refresh: #{data}"
|
|
75
|
+
when EVENT_TYPE::CLOSE
|
|
76
|
+
puts "Close"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
Absmartly.configure_client do |config|
|
|
82
|
+
config.endpoint = "https://your-company.absmartly.io/v1"
|
|
83
|
+
config.api_key = "YOUR-API-KEY"
|
|
84
|
+
config.application = "website"
|
|
85
|
+
config.environment = "development"
|
|
86
|
+
config.event_logger = MyEventLogger.new
|
|
87
|
+
end
|
|
55
88
|
```
|
|
56
89
|
|
|
57
90
|
The data parameter depends on the type of event. Currently, the SDK logs the
|
data/lib/absmartly/version.rb
CHANGED
data/lib/absmartly.rb
CHANGED
|
@@ -12,7 +12,9 @@ module Absmartly
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
class << self
|
|
15
|
-
attr_accessor :endpoint, :api_key, :application, :environment
|
|
15
|
+
attr_accessor :endpoint, :api_key, :application, :environment,
|
|
16
|
+
:connect_timeout, :connection_request_timeout, :retry_interval, :max_retries,
|
|
17
|
+
:event_logger
|
|
16
18
|
|
|
17
19
|
def configure_client
|
|
18
20
|
yield self
|
|
@@ -45,12 +47,17 @@ module Absmartly
|
|
|
45
47
|
@client_config.api_key = @api_key
|
|
46
48
|
@client_config.application = @application
|
|
47
49
|
@client_config.environment = @environment
|
|
50
|
+
@client_config.connect_timeout = @connect_timeout
|
|
51
|
+
@client_config.connection_request_timeout = @connection_request_timeout
|
|
52
|
+
@client_config.retry_interval = @retry_interval
|
|
53
|
+
@client_config.max_retries = @max_retries
|
|
48
54
|
@client_config
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
def sdk_config
|
|
52
58
|
@sdk_config = ABSmartlyConfig.create
|
|
53
59
|
@sdk_config.client = Client.create(client_config)
|
|
60
|
+
@sdk_config.context_event_logger = @event_logger
|
|
54
61
|
@sdk_config
|
|
55
62
|
end
|
|
56
63
|
|
data/lib/client.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "default_http_client"
|
|
4
|
-
require_relative "default_http_client_config"
|
|
5
4
|
require_relative "default_context_data_deserializer"
|
|
6
5
|
require_relative "default_context_event_serializer"
|
|
7
6
|
|
|
@@ -10,7 +9,7 @@ class Client
|
|
|
10
9
|
attr_reader :data_future, :promise, :exception
|
|
11
10
|
|
|
12
11
|
def self.create(config, http_client = nil)
|
|
13
|
-
Client.new(config, http_client || DefaultHttpClient.create(
|
|
12
|
+
Client.new(config, http_client || DefaultHttpClient.create(config.http_client_config))
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
def initialize(config, http_client = nil)
|
data/lib/client_config.rb
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "default_http_client_config"
|
|
4
|
+
|
|
3
5
|
class ClientConfig
|
|
4
6
|
attr_accessor :endpoint, :api_key, :environment, :application, :deserializer,
|
|
5
|
-
:serializer, :executor
|
|
7
|
+
:serializer, :executor, :connect_timeout, :connection_request_timeout,
|
|
8
|
+
:retry_interval, :max_retries
|
|
6
9
|
|
|
7
10
|
def self.create
|
|
8
11
|
ClientConfig.new
|
|
@@ -40,4 +43,13 @@ class ClientConfig
|
|
|
40
43
|
def context_event_serializer=(serializer)
|
|
41
44
|
@serializer = serializer
|
|
42
45
|
end
|
|
46
|
+
|
|
47
|
+
def http_client_config
|
|
48
|
+
http_config = DefaultHttpClientConfig.create
|
|
49
|
+
http_config.connect_timeout = @connect_timeout unless @connect_timeout.nil?
|
|
50
|
+
http_config.connection_request_timeout = @connection_request_timeout unless @connection_request_timeout.nil?
|
|
51
|
+
http_config.retry_interval = @retry_interval unless @retry_interval.nil?
|
|
52
|
+
http_config.max_retries = @max_retries unless @max_retries.nil?
|
|
53
|
+
http_config
|
|
54
|
+
end
|
|
43
55
|
end
|