api_client 0.5.24-java → 0.6.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/api_client/base.rb +77 -0
- data/lib/api_client/connection/abstract.rb +81 -0
- data/lib/api_client/connection/basic.rb +131 -0
- data/lib/api_client/connection/json.rb +14 -0
- data/lib/api_client/connection/middlewares/request/json.rb +34 -0
- data/lib/api_client/connection/middlewares/request/logger.rb +64 -0
- data/lib/api_client/connection/middlewares/request/oauth.rb +22 -0
- data/lib/api_client/connection/oauth.rb +18 -0
- data/lib/api_client/errors.rb +32 -0
- data/lib/api_client/mixins/configuration.rb +24 -0
- data/lib/api_client/mixins/connection_hooks.rb +24 -0
- data/lib/api_client/mixins/delegation.rb +23 -0
- data/lib/api_client/mixins/inheritance.rb +19 -0
- data/lib/api_client/mixins/instantiation.rb +29 -0
- data/lib/api_client/mixins/scoping.rb +49 -0
- data/lib/api_client/resource/base.rb +67 -0
- data/lib/api_client/resource/name_resolver.rb +37 -0
- data/lib/api_client/resource/scope.rb +73 -0
- data/lib/api_client/scope.rb +125 -0
- data/lib/api_client/utils.rb +18 -0
- data/lib/api_client/version.rb +3 -0
- data/spec/api_client/base/connection_hook_spec.rb +18 -0
- data/spec/api_client/base/delegation_spec.rb +15 -0
- data/spec/api_client/base/inheritance_spec.rb +44 -0
- data/spec/api_client/base/instantiation_spec.rb +55 -0
- data/spec/api_client/base/marshalling_spec.rb +33 -0
- data/spec/api_client/base/parsing_spec.rb +38 -0
- data/spec/api_client/base/scoping_spec.rb +60 -0
- data/spec/api_client/base_spec.rb +107 -0
- data/spec/api_client/connection/abstract_spec.rb +21 -0
- data/spec/api_client/connection/basic_spec.rb +198 -0
- data/spec/api_client/connection/oauth_spec.rb +23 -0
- data/spec/api_client/connection/request/json_spec.rb +30 -0
- data/spec/api_client/connection/request/logger_spec.rb +18 -0
- data/spec/api_client/connection/request/oauth_spec.rb +26 -0
- data/spec/api_client/resource/base_spec.rb +97 -0
- data/spec/api_client/resource/name_spec.rb +19 -0
- data/spec/api_client/resource/scope_spec.rb +122 -0
- data/spec/api_client/scope_spec.rb +204 -0
- data/spec/api_client/utils_spec.rb +32 -0
- data/spec/support/matchers.rb +5 -0
- metadata +72 -11
@@ -0,0 +1,204 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ApiClient::Scope do
|
4
|
+
|
5
|
+
describe 'default_scopes' do
|
6
|
+
|
7
|
+
it "runs the default scopes defined in the scopeable" do
|
8
|
+
class DefaultScopeTest < ApiClient::Base
|
9
|
+
always do
|
10
|
+
params :foo => 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
instance = ApiClient::Scope.new(DefaultScopeTest)
|
14
|
+
instance.params.should == { :foo => 1 }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#params" do
|
19
|
+
|
20
|
+
it "reads/writes the params and chains nicely" do
|
21
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
22
|
+
instance.params(:foo => 1).params(:moo => 10).should == instance
|
23
|
+
instance.params.should == { :foo => 1, :moo => 10 }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#headers" do
|
29
|
+
|
30
|
+
it "reads/writes the headers and chains nicely" do
|
31
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
32
|
+
instance.headers(:foo => 1).headers(:moo => 10).should == instance
|
33
|
+
instance.headers.should == { :foo => 1, :moo => 10 }
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#options" do
|
39
|
+
|
40
|
+
it "reads/writes the headers and chains nicely" do
|
41
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
42
|
+
instance.options(:foo => 1).options(:moo => 10).should == instance
|
43
|
+
instance.options.should == { :foo => 1, :moo => 10 }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#raw_body" do
|
49
|
+
|
50
|
+
it "reads/writes non-hash body" do
|
51
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
52
|
+
instance.raw_body('raw body string').should == instance
|
53
|
+
instance.raw_body.should == 'raw body string'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "overwrites previous raw_body" do
|
57
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
58
|
+
instance.raw_body('previous').raw_body('current')
|
59
|
+
instance.raw_body.should == 'current'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does request with raw body only if set, skips other params" do
|
63
|
+
connection = double
|
64
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
65
|
+
instance.stub(:connection).and_return(connection)
|
66
|
+
response = Faraday::Response.new(:body => '{"a": "1"}')
|
67
|
+
connection.should_receive(:get).with(@path, 'raw body string', {}).and_return(response)
|
68
|
+
|
69
|
+
result = instance.params({:skipped => 'params'}).raw_body('raw body string').request(:get, @path)
|
70
|
+
result.should == {"a"=> "1"}
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "connection" do
|
76
|
+
|
77
|
+
it "retuns the connection based on the adapter" do
|
78
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
79
|
+
instance.connection.should be_an_instance_of ApiClient::Connection::Basic
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises an error if adapter was not found" do
|
83
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
84
|
+
lambda {
|
85
|
+
instance.adapter("foo").connection
|
86
|
+
}.should raise_error
|
87
|
+
end
|
88
|
+
|
89
|
+
it "executes connection hooks" do
|
90
|
+
AConnectionHook = double
|
91
|
+
class ScopeConnectionHooksTest < ApiClient::Base
|
92
|
+
end
|
93
|
+
ScopeConnectionHooksTest.connection_hooks = [AConnectionHook]
|
94
|
+
instance = ApiClient::Scope.new(ScopeConnectionHooksTest)
|
95
|
+
AConnectionHook.should_receive(:call)
|
96
|
+
instance.connection
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "requests" do
|
102
|
+
|
103
|
+
before do
|
104
|
+
@path = "somepath"
|
105
|
+
@params = { :foo => 1 }
|
106
|
+
@headers = { 'token' => 'A' }
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_request(method)
|
110
|
+
connection = double
|
111
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
112
|
+
instance.stub(:connection).and_return(connection)
|
113
|
+
response = Faraday::Response.new(:body => '{"a": "1"}')
|
114
|
+
connection.should_receive(method).with(@path, @params, @headers).and_return(response)
|
115
|
+
instance.params(@params).headers(@headers).send(method, @path)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "can make any request" do
|
119
|
+
connection = double
|
120
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
121
|
+
instance.stub(:connection).and_return(connection)
|
122
|
+
response = Faraday::Response.new(:body => '{"a": "1"}')
|
123
|
+
connection.should_receive(:get).with(@path, @params, @headers).and_return(response)
|
124
|
+
result = instance.params(@params).headers(@headers).request(:get, @path)
|
125
|
+
result.should == {"a"=> "1"}
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can make any request and get a raw response" do
|
129
|
+
connection = double
|
130
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
131
|
+
instance.stub(:connection).and_return(connection)
|
132
|
+
response = Faraday::Response.new(:body => '{"a": "1"}')
|
133
|
+
connection.should_receive(:get).twice.with(@path, @params, @headers).and_return(response)
|
134
|
+
result = instance.params(@params).headers(@headers).request(:get, @path, :raw => true)
|
135
|
+
result.should == response
|
136
|
+
result = instance.raw.params(@params).headers(@headers).request(:get, @path)
|
137
|
+
result.should == response
|
138
|
+
end
|
139
|
+
|
140
|
+
it "makes a GET request" do
|
141
|
+
result = test_request :get
|
142
|
+
result.should == {"a"=> "1"}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "makes a POST request" do
|
146
|
+
result = test_request :post
|
147
|
+
result.should == {"a"=> "1"}
|
148
|
+
end
|
149
|
+
|
150
|
+
it "makes a PATCH request" do
|
151
|
+
result = test_request :patch
|
152
|
+
result.should == {"a"=> "1"}
|
153
|
+
end
|
154
|
+
|
155
|
+
it "makes a PUT request" do
|
156
|
+
result = test_request :put
|
157
|
+
result.should == {"a"=> "1"}
|
158
|
+
end
|
159
|
+
|
160
|
+
it "makes a PUT request" do
|
161
|
+
result = test_request :delete
|
162
|
+
result.should == {"a"=> "1"}
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "fetch" do
|
166
|
+
|
167
|
+
it "performs a get and builds an object" do
|
168
|
+
connection = double
|
169
|
+
instance = ApiClient::Scope.new(ApiClient::Base)
|
170
|
+
instance.stub(:connection).and_return(connection)
|
171
|
+
response = Faraday::Response.new(:body => '{"id": 42}')
|
172
|
+
connection.should_receive(:get).with(@path, @params, @headers).and_return(response)
|
173
|
+
result = instance.params(@params).headers(@headers).fetch(@path)
|
174
|
+
result.should be_an_instance_of(ApiClient::Base)
|
175
|
+
result.id.should == 42
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "dynamic delegation of scopeable singleton methods" do
|
183
|
+
|
184
|
+
it "dynamically delegates and properly scopes" do
|
185
|
+
class DynamicDelegationTest < ApiClient::Base
|
186
|
+
def self.some_method
|
187
|
+
self.scope.params
|
188
|
+
end
|
189
|
+
end
|
190
|
+
scope = ApiClient::Scope.new(DynamicDelegationTest)
|
191
|
+
scope.params(:param => "aaa").some_method.should == { :param => "aaa" }
|
192
|
+
end
|
193
|
+
|
194
|
+
it "raises an error if scopeable does not implement the method" do
|
195
|
+
scope = ApiClient::Scope.new(ApiClient::Base)
|
196
|
+
lambda {
|
197
|
+
scope.some_method_the_class_does_not_have
|
198
|
+
}.should raise_error(NoMethodError)
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ApiClient::Utils do
|
4
|
+
|
5
|
+
describe '.deep_merge' do
|
6
|
+
|
7
|
+
it "merges two hashes updating the first one" do
|
8
|
+
hash_a = { :a => 1, :b => 2 }
|
9
|
+
hash_b = { :b => 3, :c => 45 }
|
10
|
+
ApiClient::Utils.deep_merge hash_a, hash_b
|
11
|
+
hash_a.should == { :a => 1, :b => 3, :c=>45 }
|
12
|
+
hash_b.should == { :b => 3, :c => 45 }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "deeply merges two hashes recursively" do
|
16
|
+
hash_a = { :a => { :foo => 2, :boo => { :wat => 'wat' } }, :b => 2 }
|
17
|
+
hash_b = { :b => 3, :c => 45, :a => { :boo => { :wat => "WAT????" } } }
|
18
|
+
ApiClient::Utils.deep_merge hash_a, hash_b
|
19
|
+
hash_a.should == { :a => { :foo => 2, :boo => { :wat => 'WAT????' } }, :b => 3, :c => 45 }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "require correct key type" do
|
23
|
+
hash_a = { :a => 1 }
|
24
|
+
hash_b = { 'a' => 2 }
|
25
|
+
ApiClient::Utils.deep_merge hash_a, hash_b
|
26
|
+
hash_a.should == { :a => 1, 'a' => 2 }
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,8 +17,8 @@ dependencies:
|
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: 2.14.1
|
19
19
|
name: rspec
|
20
|
-
type: :development
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
@@ -31,8 +31,8 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '0'
|
33
33
|
name: jrjackson
|
34
|
-
type: :runtime
|
35
34
|
prerelease: false
|
35
|
+
type: :runtime
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
@@ -45,8 +45,8 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 2.0.5
|
47
47
|
name: hashie
|
48
|
-
type: :runtime
|
49
48
|
prerelease: false
|
49
|
+
type: :runtime
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
@@ -60,10 +60,10 @@ dependencies:
|
|
60
60
|
version: 0.8.1
|
61
61
|
- - "<"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: 2.0.0
|
64
64
|
name: faraday
|
65
|
-
type: :runtime
|
66
65
|
prerelease: false
|
66
|
+
type: :runtime
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
version: 0.8.1
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: 2.0.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
@@ -79,8 +79,8 @@ dependencies:
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: 1.6.1
|
81
81
|
name: multi_json
|
82
|
-
type: :runtime
|
83
82
|
prerelease: false
|
83
|
+
type: :runtime
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
@@ -100,7 +100,48 @@ files:
|
|
100
100
|
- README.md
|
101
101
|
- Rakefile
|
102
102
|
- lib/api_client.rb
|
103
|
+
- lib/api_client/base.rb
|
104
|
+
- lib/api_client/connection/abstract.rb
|
105
|
+
- lib/api_client/connection/basic.rb
|
106
|
+
- lib/api_client/connection/json.rb
|
107
|
+
- lib/api_client/connection/middlewares/request/json.rb
|
108
|
+
- lib/api_client/connection/middlewares/request/logger.rb
|
109
|
+
- lib/api_client/connection/middlewares/request/oauth.rb
|
110
|
+
- lib/api_client/connection/oauth.rb
|
111
|
+
- lib/api_client/errors.rb
|
112
|
+
- lib/api_client/mixins/configuration.rb
|
113
|
+
- lib/api_client/mixins/connection_hooks.rb
|
114
|
+
- lib/api_client/mixins/delegation.rb
|
115
|
+
- lib/api_client/mixins/inheritance.rb
|
116
|
+
- lib/api_client/mixins/instantiation.rb
|
117
|
+
- lib/api_client/mixins/scoping.rb
|
118
|
+
- lib/api_client/resource/base.rb
|
119
|
+
- lib/api_client/resource/name_resolver.rb
|
120
|
+
- lib/api_client/resource/scope.rb
|
121
|
+
- lib/api_client/scope.rb
|
122
|
+
- lib/api_client/utils.rb
|
123
|
+
- lib/api_client/version.rb
|
124
|
+
- spec/api_client/base/connection_hook_spec.rb
|
125
|
+
- spec/api_client/base/delegation_spec.rb
|
126
|
+
- spec/api_client/base/inheritance_spec.rb
|
127
|
+
- spec/api_client/base/instantiation_spec.rb
|
128
|
+
- spec/api_client/base/marshalling_spec.rb
|
129
|
+
- spec/api_client/base/parsing_spec.rb
|
130
|
+
- spec/api_client/base/scoping_spec.rb
|
131
|
+
- spec/api_client/base_spec.rb
|
132
|
+
- spec/api_client/connection/abstract_spec.rb
|
133
|
+
- spec/api_client/connection/basic_spec.rb
|
134
|
+
- spec/api_client/connection/oauth_spec.rb
|
135
|
+
- spec/api_client/connection/request/json_spec.rb
|
136
|
+
- spec/api_client/connection/request/logger_spec.rb
|
137
|
+
- spec/api_client/connection/request/oauth_spec.rb
|
138
|
+
- spec/api_client/resource/base_spec.rb
|
139
|
+
- spec/api_client/resource/name_spec.rb
|
140
|
+
- spec/api_client/resource/scope_spec.rb
|
141
|
+
- spec/api_client/scope_spec.rb
|
142
|
+
- spec/api_client/utils_spec.rb
|
103
143
|
- spec/spec_helper.rb
|
144
|
+
- spec/support/matchers.rb
|
104
145
|
homepage: https://github.com/futuresimple/api_client
|
105
146
|
licenses:
|
106
147
|
- Apache License Version 2.0
|
@@ -113,16 +154,36 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
154
|
requirements:
|
114
155
|
- - ">="
|
115
156
|
- !ruby/object:Gem::Version
|
116
|
-
version: 2.
|
157
|
+
version: 2.3.8
|
117
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
159
|
requirements:
|
119
160
|
- - ">="
|
120
161
|
- !ruby/object:Gem::Version
|
121
162
|
version: '0'
|
122
163
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.2.29
|
124
165
|
signing_key:
|
125
166
|
specification_version: 3
|
126
167
|
summary: API client builder
|
127
168
|
test_files:
|
128
169
|
- spec/spec_helper.rb
|
170
|
+
- spec/api_client/utils_spec.rb
|
171
|
+
- spec/api_client/scope_spec.rb
|
172
|
+
- spec/api_client/base_spec.rb
|
173
|
+
- spec/api_client/connection/oauth_spec.rb
|
174
|
+
- spec/api_client/connection/basic_spec.rb
|
175
|
+
- spec/api_client/connection/abstract_spec.rb
|
176
|
+
- spec/api_client/connection/request/oauth_spec.rb
|
177
|
+
- spec/api_client/connection/request/json_spec.rb
|
178
|
+
- spec/api_client/connection/request/logger_spec.rb
|
179
|
+
- spec/api_client/resource/name_spec.rb
|
180
|
+
- spec/api_client/resource/scope_spec.rb
|
181
|
+
- spec/api_client/resource/base_spec.rb
|
182
|
+
- spec/api_client/base/delegation_spec.rb
|
183
|
+
- spec/api_client/base/connection_hook_spec.rb
|
184
|
+
- spec/api_client/base/marshalling_spec.rb
|
185
|
+
- spec/api_client/base/inheritance_spec.rb
|
186
|
+
- spec/api_client/base/instantiation_spec.rb
|
187
|
+
- spec/api_client/base/parsing_spec.rb
|
188
|
+
- spec/api_client/base/scoping_spec.rb
|
189
|
+
- spec/support/matchers.rb
|