apruve 1.1.7 → 2.0.0
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/README.md +2 -2
- data/lib/apruve.rb +34 -30
- data/lib/apruve/version.rb +1 -1
- data/spec/apruve/apruve_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d7705dc13dc90111cd299c5bada4b347c470f71
|
4
|
+
data.tar.gz: fa98a6139069483ea38ee4c8b27c8d995fdbf594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/apruve.rb
CHANGED
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
34
|
+
def config=(c)
|
35
|
+
Thread.current[:config] = c
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
38
|
+
def client
|
39
|
+
Thread.current[:client]
|
40
|
+
end
|
28
41
|
|
29
|
-
def
|
30
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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?(
|
110
|
-
"#{
|
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'
|
data/lib/apruve/version.rb
CHANGED
data/spec/apruve/apruve_spec.rb
CHANGED
@@ -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:
|
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-
|
12
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|