chartmogul-ruby 1.7.2 → 1.7.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: 5381b67c739d176db4a06bb7bda534885bd370253fcbae18c090196183cd37c4
4
- data.tar.gz: 3b64a66d45d6a890b826d8eb7fd7baa8d9bb9fa942c42eda07dab1496a8e3f49
3
+ metadata.gz: 3b73de02f8130e5d5e2c132e89bed5575fed0c501c194586255629b46f7acc0e
4
+ data.tar.gz: efc54b760b1ca2fa40f949ab30fc78f9ca16970a7aaadbfc7963d93ce0e6d503
5
5
  SHA512:
6
- metadata.gz: 2f97167bbf6aaa21ae83003c073ed3a5fc69fcb8a81eebc105f7b16c6cf85dd2e775a97842a6fa050ca4311c316617c8a74af3b06feb67f60b043e2fb5a6f0eb
7
- data.tar.gz: 7d82814b322e62b04baa2b4b4b44b7b516cebbca04e3540c7eb6b68d05c2267db0fdf8f483238efe10230de6790397d7af1a3a0fa22fe1e87f01aa57a23f0c4d
6
+ metadata.gz: e7add992a1e3a5f421f27331c837b2d174bc0935ff935a9fd2e018061e1d129ad3d3fe13fa9f8fc10cf84adf245340075ed5db71766f15ede64ce5d8eadf7573
7
+ data.tar.gz: f45d866b83041a3695f8addb971cd083636b39cea420b5080ed1bc3e0cf3a96a8829c835f4ff83c9b0324b163506a2ceec01d3cf37d8f9477f336270cd16c32f
data/README.md CHANGED
@@ -53,13 +53,20 @@ This gem supports Ruby 2.3 and above.
53
53
  ## Configuration
54
54
 
55
55
  Configure `chartmogul-ruby` with your Account Token and Secret Key, available from the administration section of your ChartMogul account.
56
+ You can either do this in the global scope for the whole runtime (eg. in initializer):
56
57
 
58
+ ```ruby
59
+ ChartMogul.global_account_token = '<Account key goes here>'
60
+ ChartMogul.global_secret_key = '<Secret key goes here>'
61
+ ```
62
+
63
+ Or in a thread-safe scope for the current thread only (eg. different accounts in different async jobs):
57
64
  ```ruby
58
65
  ChartMogul.account_token = '<Account key goes here>'
59
66
  ChartMogul.secret_key = '<Secret key goes here>'
60
67
  ```
61
68
 
62
- Configuration is threadsafe and applied only to the current thread.
69
+ Thread-safe configuration is used if available, otherwise global is used.
63
70
 
64
71
  Test your authentication:
65
72
  ```ruby
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'faraday', '~> 1.0.0'
24
+ spec.add_dependency 'faraday', '~> 1.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 2'
27
27
  spec.add_development_dependency 'pry', '~> 0.12.2'
data/lib/chartmogul.rb CHANGED
@@ -79,10 +79,14 @@ module ChartMogul
79
79
  class << self
80
80
  extend ConfigAttributes
81
81
 
82
+ def global_config
83
+ @global_config ||= ChartMogul::Configuration.new
84
+ end
82
85
 
86
+ # This configuration is thread-safe and fits multi-account async
87
+ # jobs processing use case.
83
88
  def config
84
- Thread.current[CONFIG_THREAD_KEY] = ChartMogul::Configuration.new if Thread.current[CONFIG_THREAD_KEY].nil?
85
- Thread.current[CONFIG_THREAD_KEY]
89
+ Thread.current[CONFIG_THREAD_KEY] ||= ChartMogul::Configuration.new
86
90
  end
87
91
 
88
92
  config_accessor :account_token
@@ -4,7 +4,7 @@ module ChartMogul
4
4
  module ConfigAttributes
5
5
  def config_accessor(attribute, default_value = nil)
6
6
  define_method(attribute) do
7
- attr = config.send(attribute) || default_value
7
+ attr = config.send(attribute) || global_config.send(attribute) || default_value
8
8
  if attr.nil?
9
9
  raise ConfigurationError, "Configuration for #{attribute} not set"
10
10
  end
@@ -12,9 +12,25 @@ module ChartMogul
12
12
  attr
13
13
  end
14
14
 
15
+ define_method("global_#{attribute}") do
16
+ attr = global_config.send(attribute) || default_value
17
+ if attr.nil?
18
+ raise ConfigurationError, "Global configuration for #{attribute} not set"
19
+ end
20
+
21
+ attr
22
+ end
23
+
15
24
  define_method("#{attribute}=") do |val|
16
25
  config.send("#{attribute}=", val)
17
26
  Thread.current[ChartMogul::APIResource::THREAD_CONNECTION_KEY] = nil
27
+ val
28
+ end
29
+
30
+ define_method("global_#{attribute}=") do |val|
31
+ global_config.send("#{attribute}=", val)
32
+ Thread.current[ChartMogul::APIResource::THREAD_CONNECTION_KEY] = nil
33
+ val
18
34
  end
19
35
  end
20
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChartMogul
4
- VERSION = '1.7.2'
4
+ VERSION = '1.7.3'
5
5
  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.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Kopac
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement