spark_api 1.4.28 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/spark_api/authentication/api_auth.rb +1 -1
- data/lib/spark_api/authentication/oauth2.rb +1 -1
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +1 -1
- data/lib/spark_api/client.rb +2 -2
- data/lib/spark_api/models.rb +1 -0
- data/lib/spark_api/models/account.rb +7 -1
- data/lib/spark_api/models/account_report.rb +0 -5
- data/lib/spark_api/models/floplan.rb +24 -0
- data/lib/spark_api/models/listing.rb +11 -1
- data/lib/spark_api/models/subresource.rb +2 -2
- data/lib/spark_api/request.rb +2 -2
- data/script/reso_middleware_example.rb +70 -0
- data/spec/fixtures/listings/floplans_index.json +15 -0
- data/spec/spec_helper.rb +9 -4
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +21 -22
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +3 -3
- data/spec/unit/spark_api/authentication/oauth2_impl/faraday_middleware_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/single_session_provider_spec.rb +2 -2
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +40 -40
- data/spec/unit/spark_api/authentication_spec.rb +2 -2
- data/spec/unit/spark_api/configuration/yaml_spec.rb +44 -44
- data/spec/unit/spark_api/configuration_spec.rb +56 -57
- data/spec/unit/spark_api/faraday_middleware_spec.rb +12 -12
- data/spec/unit/spark_api/models/account_report_spec.rb +2 -22
- data/spec/unit/spark_api/models/account_spec.rb +24 -21
- data/spec/unit/spark_api/models/activity_spec.rb +5 -5
- data/spec/unit/spark_api/models/base_spec.rb +32 -32
- data/spec/unit/spark_api/models/concerns/destroyable_spec.rb +2 -2
- data/spec/unit/spark_api/models/concerns/savable_spec.rb +19 -19
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +1 -1
- data/spec/unit/spark_api/models/constraint_spec.rb +1 -1
- data/spec/unit/spark_api/models/contact_spec.rb +50 -50
- data/spec/unit/spark_api/models/dirty_spec.rb +12 -12
- data/spec/unit/spark_api/models/document_spec.rb +3 -3
- data/spec/unit/spark_api/models/fields_spec.rb +17 -17
- data/spec/unit/spark_api/models/finders_spec.rb +7 -7
- data/spec/unit/spark_api/models/floplan_spec.rb +24 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb +46 -46
- data/spec/unit/spark_api/models/listing_meta_translations_spec.rb +6 -6
- data/spec/unit/spark_api/models/listing_spec.rb +91 -91
- data/spec/unit/spark_api/models/message_spec.rb +10 -10
- data/spec/unit/spark_api/models/note_spec.rb +10 -10
- data/spec/unit/spark_api/models/notification_spec.rb +6 -6
- data/spec/unit/spark_api/models/open_house_spec.rb +4 -4
- data/spec/unit/spark_api/models/photo_spec.rb +8 -8
- data/spec/unit/spark_api/models/portal_spec.rb +4 -4
- data/spec/unit/spark_api/models/property_types_spec.rb +5 -5
- data/spec/unit/spark_api/models/rental_calendar_spec.rb +13 -11
- data/spec/unit/spark_api/models/rule_spec.rb +2 -2
- data/spec/unit/spark_api/models/saved_search_spec.rb +33 -33
- data/spec/unit/spark_api/models/search_template/quick_search_spec.rb +5 -5
- data/spec/unit/spark_api/models/shared_listing_spec.rb +12 -12
- data/spec/unit/spark_api/models/sort_spec.rb +3 -3
- data/spec/unit/spark_api/models/standard_fields_spec.rb +12 -12
- data/spec/unit/spark_api/models/subresource_spec.rb +33 -15
- data/spec/unit/spark_api/models/system_info_spec.rb +7 -7
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +3 -3
- data/spec/unit/spark_api/models/video_spec.rb +9 -9
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +7 -7
- data/spec/unit/spark_api/models/vow_account_spec.rb +8 -8
- data/spec/unit/spark_api/multi_client_spec.rb +14 -14
- data/spec/unit/spark_api/options_hash_spec.rb +4 -4
- data/spec/unit/spark_api/paginate_spec.rb +71 -71
- data/spec/unit/spark_api/primary_array_spec.rb +5 -5
- data/spec/unit/spark_api/request_spec.rb +65 -59
- data/spec/unit/spark_api_spec.rb +6 -6
- metadata +215 -280
@@ -3,8 +3,8 @@ require './spec/spec_helper'
|
|
3
3
|
describe SparkApi::Authentication::BaseAuth do
|
4
4
|
subject {SparkApi::Authentication::BaseAuth.new(nil) }
|
5
5
|
it "should raise an error" do
|
6
|
-
expect {subject.authenticate()}.to raise_error(){ |e| e.message.
|
7
|
-
expect {subject.logout()}.to raise_error(){ |e| e.message.
|
8
|
-
expect {subject.request(nil, nil, nil, nil)}.to raise_error(){ |e| e.message.
|
6
|
+
expect {subject.authenticate()}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
7
|
+
expect {subject.logout()}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
8
|
+
expect {subject.request(nil, nil, nil, nil)}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
9
9
|
end
|
10
10
|
end
|
@@ -10,7 +10,7 @@ describe SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware do
|
|
10
10
|
:status => 201
|
11
11
|
}
|
12
12
|
subject.on_complete env
|
13
|
-
env[:body]["token"].
|
13
|
+
expect(env[:body]["token"]).to eq("sp4rkb4rt0k3n")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should raise error on unsuccessful response" do
|
@@ -4,6 +4,6 @@ describe SparkApi::Authentication::OAuth2Impl::GrantTypeBase do
|
|
4
4
|
subject { SparkApi::Authentication::OAuth2Impl::GrantTypeBase }
|
5
5
|
# Make sure the client boostraps the right plugin based on configuration.
|
6
6
|
it "create should " do
|
7
|
-
expect {subject.create(nil, InvalidAuth2Provider.new())}.to raise_error(SparkApi::ClientError){ |e| e.message.
|
7
|
+
expect {subject.create(nil, InvalidAuth2Provider.new())}.to raise_error(SparkApi::ClientError){ |e| expect(e.message).to eq("Unsupported grant type [not_a_real_type]") }
|
8
8
|
end
|
9
9
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe SparkApi::Authentication::SingleSessionProvider do
|
4
4
|
subject { SparkApi::Authentication::SingleSessionProvider.new({ :access_token => "the_token" }) }
|
5
5
|
it "should initialize a new session with access_token" do
|
6
|
-
subject.load_session.
|
7
|
-
subject.load_session.access_token.
|
6
|
+
expect(subject.load_session).to respond_to(:access_token)
|
7
|
+
expect(subject.load_session.access_token).to eq("the_token")
|
8
8
|
end
|
9
9
|
end
|
@@ -11,7 +11,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
11
11
|
# Make sure the client boostraps the right plugin based on configuration.
|
12
12
|
describe "plugin" do
|
13
13
|
it "should load the oauth2 authenticator" do
|
14
|
-
client.authenticator.class.
|
14
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OAuth2)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
describe "authenticate" do
|
@@ -21,8 +21,8 @@ describe SparkApi::Authentication::OAuth2 do
|
|
21
21
|
'{"client_id":"example-id","client_secret":"example-password","code":"my_code","grant_type":"authorization_code","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback"}'
|
22
22
|
).
|
23
23
|
to_return(:body => fixture("oauth2/access.json"), :status=>200)
|
24
|
-
subject.authenticate.access_token.
|
25
|
-
subject.authenticate.expires_in.
|
24
|
+
expect(subject.authenticate.access_token).to eq("04u7h-4cc355-70k3n")
|
25
|
+
expect(subject.authenticate.expires_in).to eq(57600)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should raise an error when api credentials are invalid" do
|
@@ -31,7 +31,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
31
31
|
'{"client_id":"example-id","client_secret":"example-password","code":"my_code","grant_type":"authorization_code","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback"}'
|
32
32
|
).
|
33
33
|
to_return(:body => fixture("oauth2/error.json"), :status=>400)
|
34
|
-
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
34
|
+
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to eq(400) }
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -40,16 +40,16 @@ describe SparkApi::Authentication::OAuth2 do
|
|
40
40
|
let(:session) { Object.new }
|
41
41
|
it "should return true when session is active" do
|
42
42
|
subject.session = session
|
43
|
-
session.
|
44
|
-
subject.authenticated
|
43
|
+
allow(session).to receive(:expired?) { false }
|
44
|
+
expect(subject.authenticated?).to eq(true)
|
45
45
|
end
|
46
46
|
it "should return false when session is expired" do
|
47
47
|
subject.session = session
|
48
|
-
session.
|
49
|
-
subject.authenticated
|
48
|
+
allow(session).to receive(:expired?) { true }
|
49
|
+
expect(subject.authenticated?).to eq(false)
|
50
50
|
end
|
51
51
|
it "should return false when session is uninitialized" do
|
52
|
-
subject.authenticated
|
52
|
+
expect(subject.authenticated?).to eq(false)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -58,11 +58,11 @@ describe SparkApi::Authentication::OAuth2 do
|
|
58
58
|
it "should logout when there is an active session" do
|
59
59
|
subject.session = session
|
60
60
|
subject.logout
|
61
|
-
subject.session.
|
61
|
+
expect(subject.session).to eq(nil)
|
62
62
|
end
|
63
63
|
it "should skip logging out when there is no active session information" do
|
64
|
-
client.
|
65
|
-
subject.logout.
|
64
|
+
allow(client).to receive(:delete) { raise "Should not be called" }
|
65
|
+
expect(subject.logout).to eq(nil)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -79,7 +79,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
79
79
|
with(:query => args).
|
80
80
|
to_return(:body => fixture("listings/no_subresources.json"))
|
81
81
|
subject.session = session
|
82
|
-
subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status.
|
82
|
+
expect(subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status).to eq(200)
|
83
83
|
end
|
84
84
|
it "should handle a post request" do
|
85
85
|
subject.session = session
|
@@ -95,7 +95,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
95
95
|
}]}
|
96
96
|
}',
|
97
97
|
:status=>201)
|
98
|
-
subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status.
|
98
|
+
expect(subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status).to eq(201)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -106,7 +106,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
106
106
|
with(:body => "access_token=#{session.access_token}").
|
107
107
|
to_return(:body => '{"token":"sp4rkb4rt0k3n"}')
|
108
108
|
subject.session = session
|
109
|
-
subject.sparkbar_token.
|
109
|
+
expect(subject.sparkbar_token).to eq("sp4rkb4rt0k3n")
|
110
110
|
end
|
111
111
|
it "should raise an error on missing sparkbar token" do
|
112
112
|
c = stub_request(:post, "https://test.sparkplatform.com/appbar/authorize").
|
@@ -142,9 +142,9 @@ describe SparkApi::Authentication::OAuth2 do
|
|
142
142
|
to_return(:body => fixture('errors/expired.json'), :status => 401).times(1).then.
|
143
143
|
to_return(:body => fixture('listings/with_documents.json'))
|
144
144
|
client.get("/listings/1234")
|
145
|
-
count.
|
146
|
-
refresh_count.
|
147
|
-
client.session.expired
|
145
|
+
expect(count).to eq(1)
|
146
|
+
expect(refresh_count).to eq(1)
|
147
|
+
expect(client.session.expired?).to eq(false)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
context "and an invalid refresh token" do
|
@@ -164,8 +164,8 @@ describe SparkApi::Authentication::OAuth2 do
|
|
164
164
|
to_return(:body => fixture('listings/with_documents.json'))
|
165
165
|
|
166
166
|
client.get("/listings/1234")
|
167
|
-
count.
|
168
|
-
client.session.expired
|
167
|
+
expect(count).to eq(2)
|
168
|
+
expect(client.session.expired?).to eq(false)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -186,16 +186,16 @@ describe SparkApi::Authentication::OpenIdOAuth2Hybrid do
|
|
186
186
|
end
|
187
187
|
describe "plugin" do
|
188
188
|
it "should load the hybrid authenticator" do
|
189
|
-
client.authenticator.class.
|
189
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OpenIdOAuth2Hybrid)
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
193
|
describe "#authorization_url" do
|
194
194
|
it "should include combined flow parameter" do
|
195
|
-
client.authenticator.authorization_url.
|
195
|
+
expect(client.authenticator.authorization_url).to match("openid.spark.combined_flow=true")
|
196
196
|
end
|
197
197
|
it "should allow custom parameters" do
|
198
|
-
client.authenticator.authorization_url({"joshua" => "iscool"}).
|
198
|
+
expect(client.authenticator.authorization_url({"joshua" => "iscool"})).to match("joshua=iscool")
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -215,24 +215,24 @@ describe SparkApi::Authentication::OpenId do
|
|
215
215
|
|
216
216
|
describe "plugin" do
|
217
217
|
it "should not include combined flow parameter" do
|
218
|
-
client.authenticator.authorization_url.
|
218
|
+
expect(client.authenticator.authorization_url).not_to match("openid.spark.combined_flow=true")
|
219
219
|
end
|
220
220
|
it "should load the oauth2 authenticator" do
|
221
|
-
client.authenticator.class.
|
221
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OpenId)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
225
|
describe "#authorization_url" do
|
226
226
|
it "should allow custom parameters" do
|
227
|
-
client.authenticator.authorization_url({"joshua" => "iscool"}).
|
227
|
+
expect(client.authenticator.authorization_url({"joshua" => "iscool"})).to match("joshua=iscool")
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
231
|
describe "forbidden methods" do
|
232
232
|
it "should not allow authentication" do
|
233
|
-
|
233
|
+
expect {
|
234
234
|
client.authenticate
|
235
|
-
}.
|
235
|
+
}.to raise_error(RuntimeError)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -240,12 +240,12 @@ end
|
|
240
240
|
describe SparkApi::Authentication::BaseOAuth2Provider do
|
241
241
|
context "session_timeout" do
|
242
242
|
it "should provide a default" do
|
243
|
-
subject.session_timeout.
|
243
|
+
expect(subject.session_timeout).to eq(86400)
|
244
244
|
end
|
245
245
|
describe TestOAuth2Provider do
|
246
246
|
subject { TestOAuth2Provider.new }
|
247
247
|
it "should be able to override the session timeout" do
|
248
|
-
subject.session_timeout.
|
248
|
+
expect(subject.session_timeout).to eq(57600)
|
249
249
|
end
|
250
250
|
end
|
251
251
|
end
|
@@ -260,18 +260,18 @@ describe "password authentication" do
|
|
260
260
|
with(:body =>
|
261
261
|
'{"client_id":"example-id","client_secret":"example-secret","grant_type":"password","password":"example-password","username":"example-user"}'
|
262
262
|
).to_return(:body => fixture("oauth2/access.json"), :status=>200)
|
263
|
-
subject.authenticate.access_token.
|
264
|
-
subject.authenticate.expires_in.
|
263
|
+
expect(subject.authenticate.access_token).to eq("04u7h-4cc355-70k3n")
|
264
|
+
expect(subject.authenticate.expires_in).to eq(60)
|
265
265
|
end
|
266
266
|
end
|
267
267
|
describe SparkApi::Authentication::OAuth2Impl do
|
268
268
|
it "should load a provider" do
|
269
269
|
example = "SparkApi::Authentication::OAuth2Impl::CLIProvider"
|
270
|
-
SparkApi::Authentication::OAuth2Impl.load_provider(example,{}).class.to_s.
|
270
|
+
expect(SparkApi::Authentication::OAuth2Impl.load_provider(example,{}).class.to_s).to eq(example)
|
271
271
|
prefix = "::#{example}"
|
272
|
-
SparkApi::Authentication::OAuth2Impl.load_provider(prefix,{}).class.to_s.
|
272
|
+
expect(SparkApi::Authentication::OAuth2Impl.load_provider(prefix,{}).class.to_s).to eq(example)
|
273
273
|
bad_example = "Derp::Derp::Derp::DerpProvider"
|
274
|
-
expect{SparkApi::Authentication::OAuth2Impl.load_provider(bad_example,{}).class.to_s.
|
274
|
+
expect{expect(SparkApi::Authentication::OAuth2Impl.load_provider(bad_example,{}).class.to_s).to eq(bad_example)}.to raise_error(ArgumentError)
|
275
275
|
end
|
276
276
|
|
277
277
|
end
|
@@ -286,8 +286,8 @@ describe SparkApi::Authentication::OAuthSession do
|
|
286
286
|
"start_time" => "2012-01-01T00:00:00+00:00"
|
287
287
|
}
|
288
288
|
session = SparkApi::Authentication::OAuthSession.new(args)
|
289
|
-
session.start_time.
|
290
|
-
JSON.parse(session.to_json).
|
289
|
+
expect(session.start_time).to eq(DateTime.parse(args["start_time"]))
|
290
|
+
expect(JSON.parse(session.to_json)).to eq(args)
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should accept symbolized parameters" do
|
@@ -299,12 +299,12 @@ describe SparkApi::Authentication::OAuthSession do
|
|
299
299
|
:start_time => "2012-01-01T00:00:00+00:00"
|
300
300
|
}
|
301
301
|
session = SparkApi::Authentication::OAuthSession.new(args)
|
302
|
-
session.start_time.
|
303
|
-
JSON.parse(session.to_json).
|
302
|
+
expect(session.start_time).to eq(DateTime.parse(args[:start_time]))
|
303
|
+
expect(JSON.parse(session.to_json)).to eq(JSON.parse(args.to_json))
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should not expire if expires_in is nil" do
|
307
307
|
session = SparkApi::Authentication::OAuthSession.new
|
308
|
-
session.expired
|
308
|
+
expect(session.expired?).to eq(false)
|
309
309
|
end
|
310
310
|
end
|
@@ -13,7 +13,7 @@ describe SparkApi::Authentication do
|
|
13
13
|
client = SparkApi.client
|
14
14
|
stub_auth_request
|
15
15
|
session = client.get "/session/c401736bf3d3f754f07c04e460e09573"
|
16
|
-
session[0]["AuthToken"].
|
16
|
+
expect(session[0]["AuthToken"]).to eq("c401736bf3d3f754f07c04e460e09573")
|
17
17
|
end
|
18
18
|
it "should delete a session" do
|
19
19
|
stub_auth_request
|
@@ -26,7 +26,7 @@ describe SparkApi::Authentication do
|
|
26
26
|
to_return(:body => fixture("success.json"))
|
27
27
|
client = SparkApi.client
|
28
28
|
client.logout
|
29
|
-
client.session.
|
29
|
+
expect(client.session).to eq(nil)
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -4,70 +4,70 @@ describe SparkApi::Configuration::YamlConfig, "Yaml Config" do
|
|
4
4
|
describe "api auth" do
|
5
5
|
let(:api_file){ "spec/config/spark_api/test_key.yml" }
|
6
6
|
it "should load a configured api key for development" do
|
7
|
-
subject.
|
8
|
-
subject.api_env.
|
7
|
+
allow(subject).to receive(:env){ {} }
|
8
|
+
expect(subject.api_env).to eq("development")
|
9
9
|
subject.load_file(api_file)
|
10
|
-
subject.oauth2
|
11
|
-
subject.ssl_verify
|
12
|
-
subject.api_key.
|
13
|
-
subject.api_secret.
|
14
|
-
subject.endpoint.
|
15
|
-
subject.name.
|
16
|
-
subject.client_keys.keys.
|
17
|
-
subject.oauth2_keys.keys.
|
10
|
+
expect(subject.oauth2?).to eq(false)
|
11
|
+
expect(subject.ssl_verify?).to eq(false)
|
12
|
+
expect(subject.api_key).to eq("demo_key")
|
13
|
+
expect(subject.api_secret).to eq("t3sts3cr3t")
|
14
|
+
expect(subject.endpoint).to eq("https://developers.sparkapi.com")
|
15
|
+
expect(subject.name).to eq("test_key")
|
16
|
+
expect(subject.client_keys.keys).to match_array([:api_key, :api_secret, :endpoint, :ssl_verify])
|
17
|
+
expect(subject.oauth2_keys.keys).to eq([])
|
18
18
|
end
|
19
19
|
it "should load a configured api key for production" do
|
20
|
-
subject.
|
21
|
-
subject.api_env.
|
20
|
+
allow(subject).to receive(:env){ {"SPARK_API_ENV" => "production"} }
|
21
|
+
expect(subject.api_env).to eq("production")
|
22
22
|
subject.load_file(api_file)
|
23
|
-
subject.oauth2
|
24
|
-
subject.api_key.
|
25
|
-
subject.api_secret.
|
26
|
-
subject.endpoint.
|
23
|
+
expect(subject.oauth2?).to eq(false)
|
24
|
+
expect(subject.api_key).to eq("prod_demo_key")
|
25
|
+
expect(subject.api_secret).to eq("prod_t3sts3cr3t")
|
26
|
+
expect(subject.endpoint).to eq("https://api.sparkapi.com")
|
27
27
|
end
|
28
28
|
it "should raise an error for a bad configuration" do
|
29
|
-
subject.
|
29
|
+
allow(subject).to receive(:env){ {} }
|
30
30
|
expect { subject.load_file("spec/config/spark_api/some_random_key.yml")}.to raise_error
|
31
|
-
subject.
|
31
|
+
allow(subject).to receive(:env){ {"RAILS_ENV" => "fake_env"} }
|
32
32
|
expect { subject.load_file(api_file)}.to raise_error
|
33
33
|
end
|
34
34
|
end
|
35
35
|
describe "oauth2" do
|
36
36
|
let(:oauth2_file){ "spec/config/spark_api/test_oauth.yml" }
|
37
37
|
it "should load a configured api key for development" do
|
38
|
-
subject.
|
39
|
-
subject.api_env.
|
38
|
+
allow(subject).to receive(:env){ {} }
|
39
|
+
expect(subject.api_env).to eq("development")
|
40
40
|
subject.load_file(oauth2_file)
|
41
|
-
subject.oauth2
|
42
|
-
subject.authorization_uri.
|
43
|
-
subject.access_uri.
|
44
|
-
subject.redirect_uri.
|
45
|
-
subject.client_id.
|
46
|
-
subject.client_secret.
|
47
|
-
subject.endpoint.
|
48
|
-
subject.oauth2_provider.
|
49
|
-
subject.name.
|
50
|
-
subject.client_keys.keys.
|
51
|
-
subject.oauth2_keys.keys.
|
41
|
+
expect(subject.oauth2?).to eq(true)
|
42
|
+
expect(subject.authorization_uri).to eq("https://developers.sparkplatform.com/oauth2")
|
43
|
+
expect(subject.access_uri).to eq("https://developers.sparkapi.com/v1/oauth2/grant")
|
44
|
+
expect(subject.redirect_uri).to eq("http://localhost/oauth2/callback")
|
45
|
+
expect(subject.client_id).to eq("developmentid124nj4qu3pua")
|
46
|
+
expect(subject.client_secret).to eq("developmentsecret4orkp29f")
|
47
|
+
expect(subject.endpoint).to eq("https://developers.sparkapi.com")
|
48
|
+
expect(subject.oauth2_provider).to eq("SparkApi::TestOAuth2Provider")
|
49
|
+
expect(subject.name).to eq("test_oauth")
|
50
|
+
expect(subject.client_keys.keys).to match_array([:endpoint, :oauth2_provider])
|
51
|
+
expect(subject.oauth2_keys.keys).to match_array([:authorization_uri, :client_id, :access_uri, :client_secret, :redirect_uri, :sparkbar_uri])
|
52
52
|
end
|
53
53
|
it "should load a configured api key for production" do
|
54
|
-
subject.
|
55
|
-
subject.api_env.
|
54
|
+
allow(subject).to receive(:env){ {"SPARK_API_ENV" => "production"} }
|
55
|
+
expect(subject.api_env).to eq("production")
|
56
56
|
subject.load_file(oauth2_file)
|
57
|
-
subject.oauth2
|
58
|
-
subject.authorization_uri.
|
59
|
-
subject.access_uri.
|
60
|
-
subject.redirect_uri.
|
61
|
-
subject.client_id.
|
62
|
-
subject.client_secret.
|
63
|
-
subject.endpoint.
|
64
|
-
subject.oauth2_provider.
|
65
|
-
subject.name.
|
57
|
+
expect(subject.oauth2?).to eq(true)
|
58
|
+
expect(subject.authorization_uri).to eq("https://sparkplatform.com/oauth2")
|
59
|
+
expect(subject.access_uri).to eq("https://api.sparkapi.com/v1/oauth2/grant")
|
60
|
+
expect(subject.redirect_uri).to eq("http://localhost/oauth2/callback")
|
61
|
+
expect(subject.client_id).to eq("production1id124nj4qu3pua")
|
62
|
+
expect(subject.client_secret).to eq("productionsecret4orkp29fv")
|
63
|
+
expect(subject.endpoint).to eq("https://api.sparkapi.com")
|
64
|
+
expect(subject.oauth2_provider).to eq(subject.class::DEFAULT_OAUTH2_PROVIDER)
|
65
|
+
expect(subject.name).to eq("test_oauth")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should list available keys" do
|
69
|
-
SparkApi::Configuration::YamlConfig.
|
70
|
-
subject.class.config_keys.
|
69
|
+
allow(SparkApi::Configuration::YamlConfig).to receive(:config_path) { "spec/config/spark_api" }
|
70
|
+
expect(subject.class.config_keys).to match_array(["test_key", "test_oauth", "test_single_session_oauth"])
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -3,18 +3,18 @@ require './spec/spec_helper'
|
|
3
3
|
describe SparkApi::Client, "Client config" do
|
4
4
|
describe "default settings" do
|
5
5
|
it "should return the proper defaults when called with no arguments" do
|
6
|
-
SparkApi.api_key.
|
7
|
-
SparkApi.api_secret.
|
8
|
-
SparkApi.version.
|
9
|
-
SparkApi.ssl_verify.
|
10
|
-
SparkApi.auth_endpoint.
|
11
|
-
SparkApi.endpoint.
|
12
|
-
SparkApi.user_agent.
|
6
|
+
expect(SparkApi.api_key).to be_nil
|
7
|
+
expect(SparkApi.api_secret).to be_nil
|
8
|
+
expect(SparkApi.version).to match("v1")
|
9
|
+
expect(SparkApi.ssl_verify).to be true
|
10
|
+
expect(SparkApi.auth_endpoint).to match("sparkplatform.com/openid")
|
11
|
+
expect(SparkApi.endpoint).to match("api.sparkapi.com")
|
12
|
+
expect(SparkApi.user_agent).to match(/Spark API Ruby Gem .*/)
|
13
13
|
SparkApi.api_key = "my_api_key"
|
14
|
-
SparkApi.api_key.
|
15
|
-
SparkApi.timeout.
|
16
|
-
SparkApi.request_id_chain.
|
17
|
-
SparkApi.middleware.
|
14
|
+
expect(SparkApi.api_key).to match("my_api_key")
|
15
|
+
expect(SparkApi.timeout).to eq(5)
|
16
|
+
expect(SparkApi.request_id_chain).to be_nil
|
17
|
+
expect(SparkApi.middleware).to eq('spark_api')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -28,30 +28,30 @@ describe SparkApi::Client, "Client config" do
|
|
28
28
|
:timeout => 15,
|
29
29
|
:request_id_chain => 'foobar')
|
30
30
|
|
31
|
-
client.api_key.
|
32
|
-
client.api_secret.
|
33
|
-
client.api_user.
|
34
|
-
client.auth_endpoint.
|
35
|
-
client.endpoint.
|
36
|
-
client.version.
|
37
|
-
client.timeout.
|
38
|
-
client.request_id_chain.
|
31
|
+
expect(client.api_key).to match("key_of_wade")
|
32
|
+
expect(client.api_secret).to match("TopSecret")
|
33
|
+
expect(client.api_user).to match("1234")
|
34
|
+
expect(client.auth_endpoint).to match("https://login.wade.dev.fbsdata.com")
|
35
|
+
expect(client.endpoint).to match("http://api.wade.dev.fbsdata.com")
|
36
|
+
expect(client.version).to match("v1")
|
37
|
+
expect(client.timeout).to eq(15)
|
38
|
+
expect(client.request_id_chain).to eq('foobar')
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should allow unverified ssl certificates when verification is off" do
|
42
42
|
client = SparkApi::Client.new(:auth_endpoint => "https://login.wade.dev.fbsdata.com",
|
43
43
|
:endpoint => "https://api.wade.dev.fbsdata.com",
|
44
44
|
:ssl_verify => false)
|
45
|
-
client.ssl_verify.
|
46
|
-
client.connection.ssl.verify.
|
45
|
+
expect(client.ssl_verify).to be false
|
46
|
+
expect(client.connection.ssl.verify).to be false
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should allow restrict ssl certificates when verification is on" do
|
50
50
|
client = SparkApi::Client.new(:auth_endpoint => "https://login.wade.dev.fbsdata.com",
|
51
51
|
:endpoint => "https://api.wade.dev.fbsdata.com",
|
52
52
|
:ssl_verify => true)
|
53
|
-
client.ssl_verify.
|
54
|
-
client.connection.ssl.
|
53
|
+
expect(client.ssl_verify).to be true
|
54
|
+
expect(client.connection.ssl).to be_empty
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -67,11 +67,11 @@ describe SparkApi::Client, "Client config" do
|
|
67
67
|
|
68
68
|
it "should convert the configuration to oauth2 when specified" do
|
69
69
|
oauth2_client.oauthify!
|
70
|
-
oauth2_client.oauth2_provider.
|
70
|
+
expect(oauth2_client.oauth2_provider).to be_a(SparkApi::Authentication::SimpleProvider)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should say oauth2_enabled? when it is" do
|
74
|
-
oauth2_client.oauth2_enabled?().
|
74
|
+
expect(oauth2_client.oauth2_enabled?()).to be true
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should say oauth2_enabled? is false" do
|
@@ -80,11 +80,11 @@ describe SparkApi::Client, "Client config" do
|
|
80
80
|
:callback => "http://wade.dev.fbsdata.com/callback",
|
81
81
|
:auth_endpoint => "https://login.wade.dev.fbsdata.com",
|
82
82
|
:endpoint => "http://api.wade.dev.fbsdata.com")
|
83
|
-
client.oauth2_enabled?().
|
83
|
+
expect(client.oauth2_enabled?()).to be false
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should properly build a grant_uri from the endpoint" do
|
87
|
-
oauth2_client.grant_uri.
|
87
|
+
expect(oauth2_client.grant_uri).to eq("http://api.wade.dev.fbsdata.com/v1/oauth2/grant")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -100,14 +100,14 @@ describe SparkApi::Client, "Client config" do
|
|
100
100
|
config.timeout = 15
|
101
101
|
end
|
102
102
|
|
103
|
-
SparkApi.api_key.
|
104
|
-
SparkApi.api_secret.
|
105
|
-
SparkApi.api_user.
|
106
|
-
SparkApi.version.
|
107
|
-
SparkApi.endpoint.
|
108
|
-
SparkApi.user_agent.
|
109
|
-
SparkApi.oauth2_enabled?().
|
110
|
-
SparkApi.timeout.
|
103
|
+
expect(SparkApi.api_key).to match("my_key")
|
104
|
+
expect(SparkApi.api_secret).to match("my_secret")
|
105
|
+
expect(SparkApi.api_user).to match("1234")
|
106
|
+
expect(SparkApi.version).to match("veleventy")
|
107
|
+
expect(SparkApi.endpoint).to match("test.api.sparkapi.com")
|
108
|
+
expect(SparkApi.user_agent).to match("my useragent")
|
109
|
+
expect(SparkApi.oauth2_enabled?()).to be false
|
110
|
+
expect(SparkApi.timeout).to eq(15)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should correctly set up the client for oauth2" do
|
@@ -120,7 +120,7 @@ describe SparkApi::Client, "Client config" do
|
|
120
120
|
config.user_agent = "my useragent"
|
121
121
|
config.authentication_mode = SparkApi::Authentication::OAuth2
|
122
122
|
end
|
123
|
-
SparkApi.oauth2_enabled?().
|
123
|
+
expect(SparkApi.oauth2_enabled?()).to be true
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should reset" do
|
@@ -133,12 +133,11 @@ describe SparkApi::Client, "Client config" do
|
|
133
133
|
config.request_id_chain = 'foobar'
|
134
134
|
end
|
135
135
|
|
136
|
-
SparkApi.api_key.
|
137
|
-
SparkApi.request_id_chain.
|
136
|
+
expect(SparkApi.api_key).to match("my_key")
|
137
|
+
expect(SparkApi.request_id_chain).to eq("foobar")
|
138
138
|
SparkApi.reset
|
139
|
-
SparkApi.api_key.
|
140
|
-
SparkApi.request_id_chain.
|
141
|
-
|
139
|
+
expect(SparkApi.api_key).to eq(SparkApi::Configuration::DEFAULT_API_KEY)
|
140
|
+
expect(SparkApi.request_id_chain).to eq(SparkApi::Configuration::DEFAULT_REQUEST_ID_CHAIN)
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
@@ -152,7 +151,7 @@ describe SparkApi::Client, "Client config" do
|
|
152
151
|
}).
|
153
152
|
to_return(:body => '{"D":{"Success": true,"Results": [{"SSL":false}]}}')
|
154
153
|
|
155
|
-
SparkApi.client.get('/connections')[0]["SSL"].
|
154
|
+
expect(SparkApi.client.get('/connections')[0]["SSL"]).to eq(false)
|
156
155
|
end
|
157
156
|
|
158
157
|
it "should use https when ssl is enabled" do
|
@@ -165,7 +164,7 @@ describe SparkApi::Client, "Client config" do
|
|
165
164
|
to_return(:body => '{"D":{"Success": true,"Results": [{"SSL":true}]}}')
|
166
165
|
|
167
166
|
c = SparkApi::Client.new(:endpoint => "https://api.sparkapi.com", :ssl => true)
|
168
|
-
c.get('/connections')[0]["SSL"].
|
167
|
+
expect(c.get('/connections')[0]["SSL"]).to eq(true)
|
169
168
|
end
|
170
169
|
|
171
170
|
it "should have correct headers based on configuration" do
|
@@ -182,7 +181,7 @@ describe SparkApi::Client, "Client config" do
|
|
182
181
|
config.user_agent = "my useragent"
|
183
182
|
end
|
184
183
|
SparkApi.client.get '/headers'
|
185
|
-
WebMock.
|
184
|
+
expect(WebMock).to have_requested(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/headers?ApiUser=foobar&ApiSig=717a066c4f4302c5ca9507e484db4812&AuthToken=c401736bf3d3f754f07c04e460e09573").
|
186
185
|
with(:headers => {
|
187
186
|
'User-Agent' => SparkApi::Configuration::DEFAULT_USER_AGENT,
|
188
187
|
SparkApi::Configuration::X_SPARK_API_USER_AGENT => "my useragent",
|
@@ -206,7 +205,7 @@ describe SparkApi::Client, "Client config" do
|
|
206
205
|
config.request_id_chain = 'foobar'
|
207
206
|
end
|
208
207
|
SparkApi.client.get '/headers'
|
209
|
-
WebMock.
|
208
|
+
expect(WebMock).to have_requested(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/headers?ApiUser=foobar&ApiSig=717a066c4f4302c5ca9507e484db4812&AuthToken=c401736bf3d3f754f07c04e460e09573").
|
210
209
|
with(:headers => {
|
211
210
|
'User-Agent' => SparkApi::Configuration::DEFAULT_USER_AGENT,
|
212
211
|
SparkApi::Configuration::X_SPARK_API_USER_AGENT => "my useragent",
|
@@ -218,24 +217,24 @@ describe SparkApi::Client, "Client config" do
|
|
218
217
|
|
219
218
|
it "should not set gzip header by default" do
|
220
219
|
c = SparkApi::Client.new(:endpoint => "https://sparkapi.com")
|
221
|
-
c.connection.headers["Accept-Encoding"].
|
220
|
+
expect(c.connection.headers["Accept-Encoding"]).to be_nil
|
222
221
|
end
|
223
222
|
|
224
223
|
it "should set gzip header if compress option is set" do
|
225
224
|
c = SparkApi::Client.new(:endpoint => "https://api.sparkapi.com",
|
226
225
|
:compress => true)
|
227
|
-
c.connection.headers["Accept-Encoding"].
|
226
|
+
expect(c.connection.headers["Accept-Encoding"]).to eq("gzip, deflate")
|
228
227
|
end
|
229
228
|
|
230
229
|
it "should set default timeout of 5 seconds" do
|
231
230
|
c = SparkApi::Client.new(:endpoint => "https://sparkapi.com")
|
232
|
-
c.connection.options[:timeout].
|
231
|
+
expect(c.connection.options[:timeout]).to eq(5)
|
233
232
|
end
|
234
233
|
|
235
234
|
it "should set alternate timeout if specified" do
|
236
235
|
c = SparkApi::Client.new(:endpoint => "https://sparkapi.com",
|
237
236
|
:timeout => 15)
|
238
|
-
c.connection.options[:timeout].
|
237
|
+
expect(c.connection.options[:timeout]).to eq(15)
|
239
238
|
end
|
240
239
|
end
|
241
240
|
|
@@ -250,14 +249,14 @@ describe SparkApi::Client, "Client config" do
|
|
250
249
|
:middleware => 'reso_api',
|
251
250
|
:dictionary_version => '1.6')
|
252
251
|
|
253
|
-
client.api_key.
|
254
|
-
client.api_secret.
|
255
|
-
client.api_user.
|
256
|
-
client.endpoint.
|
257
|
-
client.timeout.
|
258
|
-
client.request_id_chain.
|
259
|
-
client.middleware.
|
260
|
-
client.dictionary_version.
|
252
|
+
expect(client.api_key).to match("key_of_cody")
|
253
|
+
expect(client.api_secret).to match("TopSecret")
|
254
|
+
expect(client.api_user).to match("1234")
|
255
|
+
expect(client.endpoint).to match("http://api.coolio.dev.fbsdata.com")
|
256
|
+
expect(client.timeout).to eq(15)
|
257
|
+
expect(client.request_id_chain).to eq('foobar')
|
258
|
+
expect(client.middleware).to eq('reso_api')
|
259
|
+
expect(client.dictionary_version).to eq('1.6')
|
261
260
|
end
|
262
261
|
end
|
263
262
|
end
|