access 2.0.20 → 2.0.21
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 +6 -3
- data/lib/access/config.rb +4 -1
- data/lib/access/request.rb +8 -7
- data/lib/access/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0243211608932cdb56d93819aec2d16f97e3e9b6
|
4
|
+
data.tar.gz: 6ee0b4ca459a42ac9813337452763431b8e06ff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65d28a19875e97f1e4ecbd31c39979c780eef39181a5e9a417b468d5ea85ffc9ecf8619f2ec89b8b76194bf53ef1959aa072b034cf2f6403a7c1d26ae6fc1fae
|
7
|
+
data.tar.gz: d123feef877638060c6de67953e9632e19ac9d6b5e03d0c3be0d00555988cc0c75e940e7ad843387b624646748a4b938ad3b6b963572c2a9dae2c07324292b90
|
data/README.md
CHANGED
@@ -25,15 +25,16 @@ Or install it yourself as:
|
|
25
25
|
You can configure the following options:
|
26
26
|
|
27
27
|
- `access_token` **Required**
|
28
|
-
- `api_environment`: Set as `'demo'` or `'production'`. Default is `'demo'
|
28
|
+
- `api_environment`: Set as `'demo'` or `'production'`. Default is `'demo'`.
|
29
29
|
- `return_json`: Set as `'true'` or `'false'`. Default is `'false'` return ruby objects.
|
30
|
-
- `hashify`: Set as `'true'` or `'false'`. Default is `'false'` return a hashed version of the json response if `return_json` is set to 'true'
|
30
|
+
- `hashify`: Set as `'true'` or `'false'`. Default is `'false'` return a hashed version of the json response if `return_json` is set to 'true'.
|
31
|
+
- `access_timeout`: Set as a number. Default to `'10'`.
|
31
32
|
|
32
33
|
#### Config via Environment Variables
|
33
34
|
|
34
35
|
You can set config settings by creating environment variables called:
|
35
36
|
|
36
|
-
`ENV['ACCESS_TOKEN']`, `ENV['ACCESS_ENVIRONMENT']`, `ENV['ACCESS_RETURN_JSON']`, `ENV['ACCESS_HASHIFY']`
|
37
|
+
`ENV['ACCESS_TOKEN']`, `ENV['ACCESS_ENVIRONMENT']`, `ENV['ACCESS_RETURN_JSON']`, `ENV['ACCESS_HASHIFY']`, `ENV['ACCESS_TIMEOUT']`
|
37
38
|
|
38
39
|
#### Config via Initializer
|
39
40
|
|
@@ -55,6 +56,8 @@ You can also set them one at a time
|
|
55
56
|
|
56
57
|
`hashify` can be overwritten by passing in by passing the param `hashify` to the end of any call that accepts options.
|
57
58
|
|
59
|
+
`access_token` can be overwritten by passing in by passing the param `access_token` to the end of any call that accepts options.
|
60
|
+
|
58
61
|
###Making Calls
|
59
62
|
|
60
63
|
####Offer
|
data/lib/access/config.rb
CHANGED
@@ -14,7 +14,7 @@ module Access
|
|
14
14
|
|
15
15
|
class Config
|
16
16
|
DOMAINS = {'production' => '', 'demo' => '-demo', 'stage' => '-stage', 'staging' => '-stage' }
|
17
|
-
attr_accessor :access_token, :api_environment, :return_json, :hashify
|
17
|
+
attr_accessor :access_token, :api_environment, :return_json, :hashify, :access_timeout
|
18
18
|
|
19
19
|
def initialize
|
20
20
|
@access_token = ENV['ACCESS_TOKEN']
|
@@ -24,6 +24,8 @@ module Access
|
|
24
24
|
@return_json = ENV['ACCESS_RETURN_JSON'] || 'false'
|
25
25
|
# only used when return_json is true
|
26
26
|
@hashify = ENV['ACCESS_HASHIFY'] || 'false'
|
27
|
+
# how many seconds till we raise a Access::Error::Timeout
|
28
|
+
@access_timeout = ENV['ACCESS_TIMEOUT'] || '10'
|
27
29
|
end
|
28
30
|
|
29
31
|
def reset
|
@@ -32,6 +34,7 @@ module Access
|
|
32
34
|
# self.api_version = 'v1'
|
33
35
|
self.return_json = ENV['ACCESS_RETURN_JSON'] || 'false'
|
34
36
|
self.hashify = ENV['ACCESS_HASHIFY'] || 'false'
|
37
|
+
self.access_timeout = ENV['ACCESS_TIMEOUT'] || '10'
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
data/lib/access/request.rb
CHANGED
@@ -4,7 +4,7 @@ module Access
|
|
4
4
|
|
5
5
|
def get(path, api_type, options={}, &block)
|
6
6
|
url = set_base(api_type, path)
|
7
|
-
results = self.class.get(url, headers: headers(options[:access_token]), query: options, timeout: (options[:access_timeout] ||
|
7
|
+
results = self.class.get(url, headers: headers(options[:access_token]), query: options, timeout: (options[:access_timeout] || Access.config.access_timeout))
|
8
8
|
if should_return_json?(options[:return_json])
|
9
9
|
hashify_results?(options[:hashify]) ? results.hashify : results
|
10
10
|
else
|
@@ -13,19 +13,19 @@ module Access
|
|
13
13
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
14
14
|
# block.call({"message"=>"Request Timeout Error", "status"=>408})
|
15
15
|
raise Access::Error::Timeout
|
16
|
-
|
16
|
+
rescue EOFError
|
17
|
+
raise Access::Error::NoData
|
17
18
|
end
|
18
19
|
|
19
20
|
def post(path, api_type, options={}, &block)
|
20
21
|
url = set_base(api_type, path)
|
21
|
-
results = self.class.post(url, headers: headers(options[:access_token]), body: options.to_json, timeout: (options[:access_timeout] ||
|
22
|
+
results = self.class.post(url, headers: headers(options[:access_token]), body: options.to_json, timeout: (options[:access_timeout] || Access.config.access_timeout))
|
22
23
|
if should_return_json?(options[:return_json])
|
23
24
|
hashify_results?(options[:hashify]) ? results.hashify : results
|
24
25
|
else
|
25
26
|
block.call results
|
26
27
|
end
|
27
28
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
28
|
-
# block.call({"message"=>"Request Timeout Error", "status"=>408})
|
29
29
|
raise Access::Error::Timeout
|
30
30
|
rescue EOFError
|
31
31
|
raise Access::Error::NoData
|
@@ -33,14 +33,13 @@ module Access
|
|
33
33
|
|
34
34
|
def delete(path, api_type, options={}, &block)
|
35
35
|
url = set_base(api_type, path)
|
36
|
-
results = self.class.delete(url, headers: headers(options[:access_token]), body: options.to_json, timeout: (options[:access_timeout] ||
|
36
|
+
results = self.class.delete(url, headers: headers(options[:access_token]), body: options.to_json, timeout: (options[:access_timeout] || Access.config.access_timeout))
|
37
37
|
if should_return_json?(options[:return_json])
|
38
38
|
hashify_results?(options[:hashify]) ? results.hashify : results
|
39
39
|
else
|
40
40
|
block.call results
|
41
41
|
end
|
42
42
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
43
|
-
# block.call({"message"=>"Request Timeout Error", "status"=>408})
|
44
43
|
raise Access::Error::Timeout
|
45
44
|
rescue EOFError
|
46
45
|
raise Access::Error::NoData
|
@@ -48,7 +47,7 @@ module Access
|
|
48
47
|
|
49
48
|
def post_for_filter(path, api_type, filter, options={}, &block)
|
50
49
|
url = set_base(api_type, path)
|
51
|
-
results = self.class.post(url, headers: headers(options[:access_token]), body: filter, timeout: (options[:access_timeout] ||
|
50
|
+
results = self.class.post(url, headers: headers(options[:access_token]), body: filter, timeout: (options[:access_timeout] || Access.config.access_timeout))
|
52
51
|
if should_return_json?(options[:return_json])
|
53
52
|
hashify_results?(options[:hashify]) ? results.hashify : results
|
54
53
|
else
|
@@ -56,6 +55,8 @@ module Access
|
|
56
55
|
end
|
57
56
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
58
57
|
raise Access::Error::Timeout
|
58
|
+
rescue EOFError
|
59
|
+
raise Access::Error::NoData
|
59
60
|
end
|
60
61
|
|
61
62
|
private
|
data/lib/access/version.rb
CHANGED