apruve 1.1.7 → 2.0.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
2
  SHA1:
3
- metadata.gz: c4906c25ab5dd9bc57bd845ebf10600e090d3d1d
4
- data.tar.gz: 317335e6592dca30ad63ef08792a29b5a155bfee
3
+ metadata.gz: 9d7705dc13dc90111cd299c5bada4b347c470f71
4
+ data.tar.gz: fa98a6139069483ea38ee4c8b27c8d995fdbf594
5
5
  SHA512:
6
- metadata.gz: 429f35de4d1c7ec5a0b9e3981fa92037f2ebf37e5d0fbe8b2eb7f89941a8cf5077ab5af1a00a375ced3f090eb0d2eea2dec8b5dfb6607f61beebd6d4fe6b075e
7
- data.tar.gz: 7470ba178ce9f27264125f51e36a1299cf3845cae3cc104212ed7cfb44b8ea2995289f20eb0089a7997fd8656f26be37642f3f1f886158550efd31abea95915c
6
+ metadata.gz: 370b81788ff4a080c63dddda24130ea31ac0f288510a020c48e534f2289739cd3b118322a4ff56a9f88fa56edca1908ea2fb61e7bfda6043dfe0c31d5c4d139d
7
+ data.tar.gz: 291e7b9b72cacd494f80252f42c144e7aa011a9e23c9efd07e0fb87ddab3573f358e843193b0a3965b72ebf123c6df4459ba1296fb99f3b66995f6a3810205c7
data/README.md CHANGED
@@ -31,10 +31,10 @@ test.apruve.com for test accounts.
31
31
 
32
32
  ### Initialize the library
33
33
 
34
- For [test.apruve.com](test.apruve.com)
34
+ For [test.apruve.com](https://test.apruve.com/)
35
35
  Apruve.configure('YOUR_APRUVE_API_KEY', 'test')
36
36
 
37
- For [app.apruve.com](app.apruve.com)
37
+ For [app.apruve.com](https://app.apruve.com)
38
38
  Apruve.configure('YOUR_APRUVE_API_KEY', 'prod')
39
39
 
40
40
  ### Create an Order
@@ -1,6 +1,7 @@
1
1
  # $:.unshift File.join(File.dirname(__FILE__), 'apruve', 'resources')
2
2
  # $:.unshift File.join(File.dirname(__FILE__), 'apruve', 'response')
3
3
 
4
+ require 'thread'
4
5
  require_relative 'apruve/client'
5
6
  require_relative 'apruve/version'
6
7
  require_relative 'apruve/error'
@@ -8,28 +9,38 @@ require_relative 'apruve/faraday_error_handler'
8
9
  require_relative 'apruve/utils'
9
10
 
10
11
  module Apruve
12
+ class << self
13
+ PROD = 'prod'.freeze
14
+ TEST = 'test'.freeze
15
+ LOCAL = 'local'.freeze
11
16
 
12
- @client = nil
13
- @config = {
14
- :scheme => 'http',
15
- :host => 'localhost',
16
- :port => 3000,
17
- :version => 'v4',
18
- }
17
+ def configure(api_key=nil, environment=LOCAL, options={})
18
+ self.config = config.merge(configure_environment(environment)).merge(options)
19
+ self.client = Apruve::Client.new(api_key, config)
20
+ end
19
21
 
20
- class << self
22
+ def config
23
+ if Thread.current[:config].nil?
24
+ Thread.current[:config] = {
25
+ scheme: 'http',
26
+ host: 'localhost',
27
+ port: 3000,
28
+ version: 'v4'
29
+ }
30
+ end
31
+ Thread.current[:config]
32
+ end
21
33
 
22
- attr_accessor :client
23
- attr_accessor :config
34
+ def config=(c)
35
+ Thread.current[:config] = c
36
+ end
24
37
 
25
- PROD = 'prod'
26
- TEST = 'test'
27
- LOCAL = 'local'
38
+ def client
39
+ Thread.current[:client]
40
+ end
28
41
 
29
- def configure(api_key=nil, environment=LOCAL, options={})
30
- configure_environment environment
31
- @config = @config.merge(options)
32
- @client = Apruve::Client.new(api_key, @config)
42
+ def client=(c)
43
+ Thread.current[:client] = c
33
44
  end
34
45
 
35
46
  def js(display=nil)
@@ -89,32 +100,25 @@ module Apruve
89
100
 
90
101
  def configure_environment(env)
91
102
  if env == PROD
92
- @config[:scheme] = 'https'
93
- @config[:host] = 'app.apruve.com'
94
- @config[:port] = 443
103
+ { scheme: 'https', host: 'app.apruve.com', port: 443 }
95
104
  elsif env == TEST
96
- @config[:scheme] = 'https'
97
- @config[:host] = 'test.apruve.com'
98
- @config[:port] = 443
105
+ { scheme: 'https', host: 'test.apruve.com', port: 443 }
99
106
  elsif env == LOCAL
100
- @config[:scheme] = 'http'
101
- @config[:host] = 'localhost'
102
- @config[:port] = 3000
107
+ { scheme: 'http', host: 'localhost', port: 3000 }
103
108
  else
104
109
  raise 'unknown environment'
105
110
  end
106
111
  end
107
112
 
108
113
  def js_url
109
- port_param = [443, 80].include?(@config[:port]) ? '' : ":#{@config[:port]}"
110
- "#{@config[:scheme]}://#{@config[:host]}#{port_param}/js/v4/apruve.js"
114
+ port_param = [443, 80].include?(config[:port]) ? '' : ":#{config[:port]}"
115
+ "#{config[:scheme]}://#{config[:host]}#{port_param}/js/v4/apruve.js"
111
116
  end
112
117
  end
113
118
 
114
119
  configure
115
120
  end
116
121
 
117
-
118
122
  # require all the resources! this is needed at the end because
119
123
  # the module needs to be defined first, as it contains the registry
120
- require_relative 'apruve/resources'
124
+ require_relative 'apruve/resources'
@@ -1,3 +1,3 @@
1
1
  module Apruve
2
- VERSION = '1.1.7'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -132,4 +132,21 @@ describe 'Apruve' do
132
132
  end
133
133
  end
134
134
  end
135
+
136
+ describe 'with multiple threads' do
137
+ let(:api_key) { 'an-api-key' }
138
+ let(:another_api_key) { 'another-api-key' }
139
+
140
+ it 'should have thread-contained configuration' do
141
+ Apruve.configure(api_key)
142
+ thread = Thread.new do
143
+ Apruve.configure(another_api_key)
144
+ expect(Apruve.client).not_to be_nil
145
+ expect(Apruve.client.api_key).to eq another_api_key
146
+ end
147
+ thread.join
148
+ expect(Apruve.client).not_to be_nil
149
+ expect(Apruve.client.api_key).to eq api_key
150
+ end
151
+ end
135
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apruve
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apruve, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-08 00:00:00.000000000 Z
12
+ date: 2017-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler