oneaccess 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -17
- data/lib/oneaccess/api/api_base.rb +2 -2
- data/lib/oneaccess/api/v3_0/providers.rb +7 -9
- data/lib/oneaccess/configuration.rb +7 -0
- data/lib/oneaccess/http/http_client.rb +86 -7
- data/oneaccess.gemspec +3 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 839afdde8249236a6efc2785eea68230f972507b
|
4
|
+
data.tar.gz: c178bab91d1fa090d03220d14c0370a26191e72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 740bfae1d5e4545efba40f1a9406ac0451de90bb272ed2dc3c3d3bd2ff9581d744b5126503f953fcc445fddf4d4a4fcf051c87c2e3469ee9df0aa79d1ebc909b
|
7
|
+
data.tar.gz: 23a0a0f6e43fa55e59ce5dc30b4ef81b389a3070ae28a3b98c020710a7a7013f3656f15dbe9288cde3e1ca3d238ae83912852c2cfe07ab115bc27bbc9d4c985c
|
data/Gemfile.lock
CHANGED
@@ -2,9 +2,9 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
oneaccess (0.0.0)
|
5
|
+
faraday (~> 0.13)
|
5
6
|
multi_json (~> 1.12.0)
|
6
7
|
representable (~> 3.0.4)
|
7
|
-
rest-client (~> 2.0.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -20,18 +20,13 @@ GEM
|
|
20
20
|
declarative-option (0.1.0)
|
21
21
|
diff-lcs (1.3)
|
22
22
|
docile (1.1.5)
|
23
|
-
|
24
|
-
|
23
|
+
faraday (0.15.0)
|
24
|
+
multipart-post (>= 1.2, < 3)
|
25
25
|
hashdiff (0.3.5)
|
26
26
|
hirb (0.7.3)
|
27
|
-
http-cookie (1.0.3)
|
28
|
-
domain_name (~> 0.5)
|
29
27
|
json (2.1.0)
|
30
|
-
|
31
|
-
|
32
|
-
mime-types-data (3.2016.0521)
|
33
|
-
multi_json (1.12.1)
|
34
|
-
netrc (0.11.0)
|
28
|
+
multi_json (1.12.2)
|
29
|
+
multipart-post (2.0.0)
|
35
30
|
parallel (1.12.1)
|
36
31
|
parser (2.5.1.0)
|
37
32
|
ast (~> 2.4.0)
|
@@ -43,10 +38,6 @@ GEM
|
|
43
38
|
declarative (< 0.1.0)
|
44
39
|
declarative-option (< 0.2.0)
|
45
40
|
uber (< 0.2.0)
|
46
|
-
rest-client (2.0.2)
|
47
|
-
http-cookie (>= 1.0.2, < 2.0)
|
48
|
-
mime-types (>= 1.16, < 4.0)
|
49
|
-
netrc (~> 0.8)
|
50
41
|
rspec (3.7.0)
|
51
42
|
rspec-core (~> 3.7.0)
|
52
43
|
rspec-expectations (~> 3.7.0)
|
@@ -79,9 +70,6 @@ GEM
|
|
79
70
|
simplecov
|
80
71
|
simplecov-html (0.10.2)
|
81
72
|
uber (0.1.0)
|
82
|
-
unf (0.1.4)
|
83
|
-
unf_ext
|
84
|
-
unf_ext (0.0.7.4)
|
85
73
|
unicode-display_width (1.3.2)
|
86
74
|
webmock (3.0.1)
|
87
75
|
addressable (>= 2.3.6)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "faraday"
|
4
4
|
require "json"
|
5
5
|
require_relative "../response/api_error"
|
6
6
|
require_relative "../error/api_error"
|
@@ -14,7 +14,7 @@ module ONEAccess
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def send_post(method, body)
|
17
|
-
Http::HttpClient.post(api_url(method), body,
|
17
|
+
Http::HttpClient.post(api_url(method), body, "Content-Type" => "application/json")
|
18
18
|
end
|
19
19
|
|
20
20
|
def resource_api_path
|
@@ -19,12 +19,12 @@ module ONEAccess
|
|
19
19
|
receivedate: receive_date
|
20
20
|
}.reject { |_, v| v.nil? }
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
Response::InducementResponse.from_json(resp.body)
|
22
|
+
response = send_post("inducements", inducement: params)
|
23
|
+
Response::InducementResponse.from_json(response.body)
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
27
|
+
def users_details(
|
28
28
|
buy_side_org_id:,
|
29
29
|
provider_id:,
|
30
30
|
contract_status_id: nil,
|
@@ -35,8 +35,6 @@ module ONEAccess
|
|
35
35
|
reverse_entitlement_status: nil
|
36
36
|
)
|
37
37
|
|
38
|
-
provider_id = comma_separated_values(provider_id)
|
39
|
-
|
40
38
|
params = {
|
41
39
|
buysideorgid: buy_side_org_id,
|
42
40
|
contractstatusid: contract_status_id,
|
@@ -45,12 +43,12 @@ module ONEAccess
|
|
45
43
|
userreverseentitlementstatus: user_reverse_entitlement_status,
|
46
44
|
vendorid: vendor_id,
|
47
45
|
reverseentitlementstatus: reverse_entitlement_status
|
48
|
-
}.
|
49
|
-
|
50
|
-
resp = send_get("GetProviderUserDetails?providerid=#{provider_id}", params)
|
46
|
+
}.compact!
|
51
47
|
|
48
|
+
resp = send_get("GetProviderUserDetails?providerid=#{comma_separated_values(provider_id)}", params)
|
52
49
|
Response::ProvidersUsersDetailsResponse.from_json(resp.body)
|
53
50
|
end
|
51
|
+
# rubocop:enable Metrics/MethodLength
|
54
52
|
|
55
53
|
private
|
56
54
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "logger"
|
4
|
+
|
3
5
|
module ONEAccess
|
4
6
|
class Configuration
|
5
7
|
DEFAULT_BASE_URL = "http://ws.oneaccess.io"
|
@@ -10,6 +12,7 @@ module ONEAccess
|
|
10
12
|
attr_accessor :base_url
|
11
13
|
attr_accessor :api_key
|
12
14
|
attr_accessor :master_api_key
|
15
|
+
attr_writer :logger
|
13
16
|
|
14
17
|
def base_v1_1_url
|
15
18
|
"#{base_url}#{DEFAULT_BASE_V1_1_PATH}"
|
@@ -24,6 +27,10 @@ module ONEAccess
|
|
24
27
|
self.api_key = nil
|
25
28
|
self.master_api_key = nil
|
26
29
|
end
|
30
|
+
|
31
|
+
def logger
|
32
|
+
@logger ||= Logger.new(STDOUT)
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
reset!
|
@@ -4,24 +4,85 @@ module ONEAccess
|
|
4
4
|
module Http
|
5
5
|
class HttpClient
|
6
6
|
class << self
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
DEFAULT_TIMEOUT = 10
|
8
|
+
|
9
|
+
def get(url, params = {}, headers = {})
|
10
|
+
response = connection.get do |request|
|
11
|
+
request.url url
|
12
|
+
request.params.merge!(params)
|
13
|
+
request.headers.merge!(headers)
|
14
|
+
end
|
15
|
+
handle_response(response)
|
16
|
+
rescue Faraday::TimeoutError => e
|
17
|
+
raise create_timeout_error(e, url)
|
18
|
+
rescue Faraday::Error => e
|
10
19
|
raise create_api_error(e)
|
11
20
|
end
|
12
21
|
|
13
22
|
def post(url, body, headers = {})
|
14
|
-
|
15
|
-
|
23
|
+
response = connection.post do |request|
|
24
|
+
request.url url
|
25
|
+
request.headers.merge!(headers)
|
26
|
+
request.body = body.to_json
|
27
|
+
end
|
28
|
+
handle_response(response)
|
29
|
+
rescue Faraday::TimeoutError => e
|
30
|
+
raise create_timeout_error(e, url)
|
31
|
+
rescue Faraday::Error => e
|
16
32
|
raise create_api_error(e)
|
17
33
|
end
|
18
34
|
|
19
35
|
private
|
20
36
|
|
37
|
+
def handle_response(response)
|
38
|
+
# make sure we have a valid JSON in the response
|
39
|
+
if response.headers["Content-Type"] == "application/json"
|
40
|
+
begin
|
41
|
+
MultiJson.load(response.body)
|
42
|
+
rescue MultiJson::ParseError
|
43
|
+
raise Error::APIError.new(500, response.code, "Invalid JSON Response:'#{message.body}'")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
response
|
47
|
+
end
|
48
|
+
|
49
|
+
def connection
|
50
|
+
Faraday.new(url: Configuration.base_url,
|
51
|
+
headers: auth_headers,
|
52
|
+
request: { timeout: DEFAULT_TIMEOUT }) do |faraday|
|
53
|
+
faraday.response :raise_error
|
54
|
+
faraday.response :logger, Configuration.logger, bodies: true do |logger|
|
55
|
+
logger.filter(/(Api-Key)([\s:"]*)(.+)(\"{1})/, "[REMOVED]")
|
56
|
+
end
|
57
|
+
faraday.adapter(detect_adapter)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_timeout_error(_error, url)
|
62
|
+
Error::APIError.new(408, 408, "Timeout #{DEFAULT_TIMEOUT} at #{url}")
|
63
|
+
end
|
64
|
+
|
21
65
|
def create_api_error(error)
|
66
|
+
status = error.response[:status]
|
67
|
+
body = error.response[:body]
|
68
|
+
headers = error.response[:headers]
|
69
|
+
if headers["Content-Type"] == "application/json"
|
70
|
+
handle_json_error(body, status)
|
71
|
+
else
|
72
|
+
Error::APIError.new(status, status, "API Response body:'#{body}'")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def handle_json_error(body, status)
|
22
77
|
api_error_data = Response::APIError.new
|
23
|
-
Response::Representer::APIError.new(api_error_data).from_json(
|
24
|
-
Error::APIError.new(
|
78
|
+
Response::Representer::APIError.new(api_error_data).from_json(body)
|
79
|
+
Error::APIError.new(
|
80
|
+
status,
|
81
|
+
api_error_data.api_status_code,
|
82
|
+
api_error_data.api_status_message
|
83
|
+
)
|
84
|
+
rescue MultiJson::ParseError
|
85
|
+
Error::APIError.new(500, 500, "Invalid JSON:'#{body}'")
|
25
86
|
end
|
26
87
|
|
27
88
|
def auth_headers
|
@@ -30,6 +91,24 @@ module ONEAccess
|
|
30
91
|
"Authorization" => "X-One-Access-Master-Api-Key #{Configuration.master_api_key}"
|
31
92
|
}
|
32
93
|
end
|
94
|
+
|
95
|
+
# Auto-detect the best adapter (HTTP "driver") available, based on libraries
|
96
|
+
# loaded by the user, preferring those with persistent connections ("keep-alive") by default
|
97
|
+
# rubocop:disable Metrics/MethodLength
|
98
|
+
def detect_adapter
|
99
|
+
if defined?(::Patron)
|
100
|
+
:patron
|
101
|
+
elsif defined?(::Typhoeus)
|
102
|
+
:typhoeus
|
103
|
+
elsif defined?(::HTTPClient)
|
104
|
+
:httpclient
|
105
|
+
elsif defined?(::Net::HTTP::Persistent)
|
106
|
+
:net_http_persistent
|
107
|
+
else
|
108
|
+
::Faraday.default_adapter
|
109
|
+
end
|
110
|
+
end
|
111
|
+
# rubocop:enable Metrics/MethodLength
|
33
112
|
end
|
34
113
|
end
|
35
114
|
end
|
data/oneaccess.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "oneaccess"
|
5
|
-
s.version = "1.0.
|
6
|
-
s.date = "2018-
|
5
|
+
s.version = "1.0.1"
|
6
|
+
s.date = "2018-05-07"
|
7
7
|
s.summary = "ONEAccess API wrapper"
|
8
8
|
s.description = "Easily communicate with ONEAccess API"
|
9
9
|
s.homepage = "https://github.com/AlphaExchange/oneaccess-rb"
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "simplecov-console"
|
25
25
|
s.add_development_dependency "webmock", "~> 3.0.1"
|
26
26
|
|
27
|
+
s.add_runtime_dependency "faraday", "~> 0.13"
|
27
28
|
s.add_runtime_dependency "multi_json", "~> 1.12.0"
|
28
29
|
s.add_runtime_dependency "representable", "~> 3.0.4"
|
29
|
-
s.add_runtime_dependency "rest-client", "~> 2.0.0"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneaccess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Correia Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,47 +123,47 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 3.0.1
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: faraday
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: '0.13'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: '0.13'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: multi_json
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 1.12.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 1.12.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: representable
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 3.0.4
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 3.0.4
|
167
167
|
description: Easily communicate with ONEAccess API
|
168
168
|
email:
|
169
169
|
- alex@alpha-exchange.com
|