chartmogul-ruby 1.1.9 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c40767c5703fd33e6082f381b76d6e37a21ec7a1
4
- data.tar.gz: ba522825f3763def73d620cfd8e219d08f305185
2
+ SHA256:
3
+ metadata.gz: f4f3fb69e05a0a258906b974f566741f9fa152f59f69dccae4cead5baef0f9f9
4
+ data.tar.gz: d3724ddc288874e997856c2f8159fa84312cf5c27723dd24cd54668e1fca2ea1
5
5
  SHA512:
6
- metadata.gz: 2506be57ed3239b5a1686489b4ca57466392e847e9e478690ffaf5f44a825ea99286313614c56e2aa66860b856799cd01c40f8f0b83ff4caa5d2a2b4bc30fbf3
7
- data.tar.gz: 4b5b19a865fcc201bbbfcb8a0c17a138f156c633f20518ffed6aeafb22d8f79d19af70ef3732708728e21604b59010fbfa1db1fada2b6a651fac1ba8585204cc
6
+ metadata.gz: 75f93ec8855dee1db9045ab6a203c53fc33f0e7b255d746e539f40034b90df85278c380133619e46aa06172c2d3c4b26d25b107ef7d71bd08e74d080597ac316
7
+ data.tar.gz: 256cddea65586fc78b381d52afdbf14e4b44747a268ba7b2749b7f9ca97a5146d3e75c5374425d71688764049dd28bb26b173441f3d4fceb35dc4e9e02ad9ebb
data/README.md CHANGED
@@ -86,6 +86,16 @@ You can find examples for each endpoint in the ChartMogul [API documentation](ht
86
86
 
87
87
  [![https://gyazo.com/f7a2a1b86a409586ee8dd0f4f7563937](https://i.gyazo.com/f7a2a1b86a409586ee8dd0f4f7563937.gif)](https://i.gyazo.com/f7a2a1b86a409586ee8dd0f4f7563937.gif)
88
88
 
89
+ ## Rate Limits & Exponential Backoff
90
+
91
+ The library will keep retrying if the request exceeds the rate limit or if there's any network related error. By default, the request will be retried for 20 times (approximated 15 minutes) before finally giving up.
92
+
93
+ You can change the retry count with:
94
+ ```ruby
95
+ ChartMogul.max_retries = 15
96
+ ```
97
+ Set it to 0 to disable it.
98
+
89
99
  ## Development
90
100
 
91
101
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'vcr', '~> 3.0'
29
29
  spec.add_development_dependency 'pry', '~> 0.10.3'
30
+ spec.add_development_dependency 'webmock', '~> 3.4', '>= 3.4.2'
30
31
  end
@@ -67,6 +67,7 @@ require 'chartmogul/enrichment/customer'
67
67
 
68
68
  module ChartMogul
69
69
  API_BASE = 'https://api.chartmogul.com'.freeze
70
+ MAX_RETRIES = 20
70
71
 
71
72
  class << self
72
73
  extend ConfigAttributes
@@ -77,5 +78,6 @@ module ChartMogul
77
78
 
78
79
  config_accessor :account_token
79
80
  config_accessor :secret_key
81
+ config_accessor :max_retries, MAX_RETRIES
80
82
  end
81
83
  end
@@ -4,6 +4,16 @@ module ChartMogul
4
4
  class APIResource < ChartMogul::Object
5
5
  extend Forwardable
6
6
 
7
+ RETRY_STATUSES = [429, *500..599].freeze
8
+ RETRY_EXCEPTIONS = [
9
+ 'Faraday::ConnectionFailed',
10
+ 'Faraday::RetriableResponse'
11
+ ].freeze
12
+ BACKOFF_FACTOR = 2
13
+ INTERVAL_RANDOMNESS = 0.5
14
+ INTERVAL = 1
15
+ MAX_INTERVAL = 60
16
+
7
17
  class << self; attr_reader :resource_path, :resource_name, :resource_root_key end
8
18
 
9
19
  def self.set_resource_path(path)
@@ -22,6 +32,9 @@ module ChartMogul
22
32
  @connection ||= Faraday.new(url: ChartMogul::API_BASE) do |faraday|
23
33
  faraday.use Faraday::Request::BasicAuthentication, ChartMogul.account_token, ChartMogul.secret_key
24
34
  faraday.use Faraday::Response::RaiseError
35
+ faraday.request :retry, max: ChartMogul.max_retries, retry_statuses: RETRY_STATUSES,
36
+ max_interval: MAX_INTERVAL, backoff_factor: BACKOFF_FACTOR,
37
+ interval_randomness: INTERVAL_RANDOMNESS, interval: INTERVAL, exceptions: RETRY_EXCEPTIONS
25
38
  faraday.use Faraday::Adapter::NetHttp
26
39
  end
27
40
  end
@@ -1,8 +1,8 @@
1
1
  module ChartMogul
2
2
  module ConfigAttributes
3
- def config_accessor(attribute)
3
+ def config_accessor(attribute, default_value = nil)
4
4
  define_method(attribute) do
5
- attr = config.send(attribute)
5
+ attr = config.send(attribute) || default_value
6
6
  raise ConfigurationError, "Configuration for #{attribute} not set" if attr.nil?
7
7
  attr
8
8
  end
@@ -2,5 +2,6 @@ module ChartMogul
2
2
  class Configuration
3
3
  attr_accessor :account_token
4
4
  attr_accessor :secret_key
5
+ attr_accessor :max_retries
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module ChartMogul
2
- VERSION = '1.1.9'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartmogul-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Langenauer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,26 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.10.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 3.4.2
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '3.4'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 3.4.2
97
117
  description: Official Ruby client for ChartMogul's API
98
118
  email:
99
119
  - jason@chartmogul.com
@@ -242,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
262
  version: '0'
243
263
  requirements: []
244
264
  rubyforge_project:
245
- rubygems_version: 2.5.2
265
+ rubygems_version: 2.7.4
246
266
  signing_key:
247
267
  specification_version: 4
248
268
  summary: Chartmogul API Ruby Client