absmartly-sdk 1.2.2 → 1.3.0.pre.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: 4a2b6f96e452fc60de76e49bc1166b6df3030b1ab424e99cdaf72554493ac0b3
4
- data.tar.gz: aae37038713a693935209e387dee6ac5a33f84d4c74a27edec5d2ed69152e1e7
3
+ metadata.gz: 01cba8157effb3de46d5392c80d36d4247b1a802f0c4ec5fab1758bb2f1059b7
4
+ data.tar.gz: dfbe07427f077cd936ec28449f3d42d8efcbb9d09d90b0a171998976acdb442e
5
5
  SHA512:
6
- metadata.gz: 6c5feb92c44db0ea6b24d33f40812626d4fdeaa6339c258c5da5926e522382f0981a0550b2508ae7a79ca6b0b1d6c18d54ed2a0f1b24c4241b45cad3d3a39edb
7
- data.tar.gz: 113ba3c0c2594537dd8ea6c02021bc447f7918783b7175106317d60893013a843f0f93f4eb4411deab9b502f97b539120593d66a0d9c4b50e2fc201cf1d2e531
6
+ metadata.gz: 5920cdb96b212aa2fbc08d52212b7d15fd11eab5493b50d22d05e51dac2f30414fe2080735ac1f4b1a30c61723c1e41f4841bfc4a623a40686c30d12ef0f4fc0
7
+ data.tar.gz: 45cc5a139fd3fdca0c2b97ba98da1ed0caf14b63a70684f3ae983f473016e8147ea269ca7f90f00b5752ddb0f1779c7362d7d706d10079d257f581c1c5914fe3
data/Gemfile CHANGED
@@ -8,6 +8,8 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
  gem "murmurhash3"
10
10
  gem "faraday"
11
+ gem "faraday-net_http_persistent"
12
+ gem "connection_pool", "< 3"
11
13
 
12
14
  group :test do
13
15
  gem "rspec", "~> 3.5"
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- absmartly-sdk (1.2.2)
4
+ absmartly-sdk (1.3.0.pre.1)
5
5
  base64 (~> 0.2)
6
6
  faraday (~> 2.0)
7
+ faraday-net_http_persistent (~> 2.0)
7
8
  faraday-retry (~> 2.0)
8
9
  murmurhash3 (~> 0.1.7)
9
10
 
@@ -13,11 +14,15 @@ GEM
13
14
  ast (2.4.2)
14
15
  base64 (0.3.0)
15
16
  byebug (11.1.3)
17
+ connection_pool (2.5.5)
16
18
  diff-lcs (1.5.0)
17
19
  faraday (2.7.4)
18
20
  faraday-net_http (>= 2.0, < 3.1)
19
21
  ruby2_keywords (>= 0.0.4)
20
22
  faraday-net_http (3.0.2)
23
+ faraday-net_http_persistent (2.3.1)
24
+ faraday (~> 2.5)
25
+ net-http-persistent (>= 4.0.4, < 5)
21
26
  faraday-retry (2.4.0)
22
27
  faraday (~> 2.0)
23
28
  io-console (0.5.6)
@@ -25,6 +30,8 @@ GEM
25
30
  reline (>= 0.1.5)
26
31
  json (2.6.2)
27
32
  murmurhash3 (0.1.7)
33
+ net-http-persistent (4.0.8)
34
+ connection_pool (>= 2.2.4, < 4)
28
35
  parallel (1.22.1)
29
36
  parser (3.1.2.0)
30
37
  ast (~> 2.4.1)
@@ -70,7 +77,9 @@ PLATFORMS
70
77
  DEPENDENCIES
71
78
  absmartly-sdk!
72
79
  byebug
80
+ connection_pool (< 3)
73
81
  faraday
82
+ faraday-net_http_persistent
74
83
  irb
75
84
  murmurhash3
76
85
  rake (~> 13.0)
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` | &#9989; | `undefined` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` |
40
- | apiKey | `string` | &#9989; | `undefined` | Your API key which can be found on the Web Console. |
44
+ | api_key | `string` | &#9989; | `undefined` | Your API key which can be found on the Web Console. |
41
45
  | environment | `"production"` or `"development"` | &#9989; | `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` | &#9989; | `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
- | retries | `number` | &#10060; | `5` | The number of retries before the SDK stops trying to connect. |
44
- | timeout | `number` | &#10060; | `3000` | An amount of time, in milliseconds, before the SDK will stop trying to connect. |
45
- | eventLogger | `(context, eventName, data) => void` | &#10060; | See "Using a Custom Event Logger" below | A callback function which runs after SDK events. |
47
+ | connect_timeout | `number` | &#10060; | `3.0` | The socket connection timeout in seconds. |
48
+ | connection_request_timeout | `number` | &#10060; | `3.0` | The request timeout in seconds. |
49
+ | retry_interval | `number` | &#10060; | `0.5` | The initial retry interval in seconds (uses exponential backoff). |
50
+ | max_retries | `number` | &#10060; | `5` | The maximum number of retries before giving up. |
51
+ | event_logger | `ContextEventLogger` | &#10060; | 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, in the `[CONTEXT_CONFIG_VARIABLE]`.
57
+ particular context in the context config.
52
58
 
53
- ```
54
- Custom Event Logger Code
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/absmartly.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  # Faraday 2.7.x uses base64 but doesn't declare it as a dependency.
37
37
  spec.add_dependency "base64", "~> 0.2"
38
38
  spec.add_dependency "faraday", "~> 2.0"
39
+ spec.add_dependency "faraday-net_http_persistent", "~> 2.0"
39
40
  spec.add_dependency "faraday-retry", "~> 2.0"
40
41
  spec.add_dependency "murmurhash3", "~> 0.1.7"
41
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Absmartly
4
- VERSION = "1.2.2"
4
+ VERSION = "1.3.0.pre.1"
5
5
  end
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(DefaultHttpClientConfig.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
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "faraday"
4
- require 'faraday/retry'
4
+ require "faraday/net_http_persistent"
5
+ require "faraday/retry"
5
6
  require "uri"
6
7
  require_relative "http_client"
7
8
 
@@ -22,6 +23,9 @@ class DefaultHttpClient < HttpClient
22
23
  backoff_factor: 2
23
24
  f.options.timeout = config.connect_timeout
24
25
  f.options.open_timeout = config.connection_request_timeout
26
+ f.adapter :net_http_persistent, pool_size: 20 do |http|
27
+ http.idle_timeout = 5
28
+ end
25
29
  end
26
30
  end
27
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absmartly-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - absmartly
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday-net_http_persistent
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: faraday-retry
42
56
  requirement: !ruby/object:Gem::Requirement