spark_api 1.4.34 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/request.rb +1 -1
- 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_spec.rb +20 -20
- 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 +4 -4
- 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 +18 -18
- 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 +60 -60
- data/spec/unit/spark_api_spec.rb +6 -6
- metadata +162 -233
@@ -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
|
@@ -64,13 +64,13 @@ describe SparkApi do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should raised exception when token is expired" do
|
67
|
-
expect { @connection.get('/expired')}.to raise_error(SparkApi::PermissionDenied){ |e| e.code.
|
67
|
+
expect { @connection.get('/expired')}.to raise_error(SparkApi::PermissionDenied){ |e| expect(e.code).to eq(SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED) }
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should raised exception on error" do
|
71
|
-
expect { @connection.get('/methodnotallowed')}.to raise_error(SparkApi::NotAllowed){ |e| e.message.
|
72
|
-
expect { @connection.get('/epicfail')}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
73
|
-
expect { @connection.get('/unknownerror')}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
71
|
+
expect { @connection.get('/methodnotallowed')}.to raise_error(SparkApi::NotAllowed){ |e| expect(e.message).to eq("Method Not Allowed") }
|
72
|
+
expect { @connection.get('/epicfail')}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to be(500) }
|
73
|
+
expect { @connection.get('/unknownerror')}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to be(499) }
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should raised exception on invalid responses" do
|
@@ -81,20 +81,20 @@ describe SparkApi do
|
|
81
81
|
|
82
82
|
it "should give me a session response" do
|
83
83
|
response = @connection.post('/session').body
|
84
|
-
response.success.
|
84
|
+
expect(response.success).to eq(true)
|
85
85
|
session = SparkApi::Authentication::Session.new(response.results[0])
|
86
|
-
session.auth_token.
|
86
|
+
expect(session.auth_token).to eq("xxxxx")
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should give me an api response" do
|
90
90
|
response = @connection.get('/system').body
|
91
|
-
response.success.
|
92
|
-
response.results.length.
|
91
|
+
expect(response.success).to eq(true)
|
92
|
+
expect(response.results.length).to be > 0
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should include the errors in the response" do
|
96
96
|
expect { @connection.get('/badresourcerequest')}.to raise_error(SparkApi::BadResourceRequest){ |e|
|
97
|
-
e.errors.
|
97
|
+
expect(e.errors).to eq("Some errors and stuff.")
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
@@ -111,7 +111,7 @@ describe SparkApi do
|
|
111
111
|
:response_headers => {}
|
112
112
|
}
|
113
113
|
|
114
|
-
middleware.decompress_body(env).
|
114
|
+
expect(middleware.decompress_body(env)).to eq("UNCOMPRESSED")
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should unzip gzipped data" do
|
@@ -129,7 +129,7 @@ describe SparkApi do
|
|
129
129
|
}
|
130
130
|
}
|
131
131
|
|
132
|
-
middleware.decompress_body(env).
|
132
|
+
expect(middleware.decompress_body(env)).to eq(bod)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should inflate deflated data" do
|
@@ -143,7 +143,7 @@ describe SparkApi do
|
|
143
143
|
}
|
144
144
|
}
|
145
145
|
|
146
|
-
middleware.decompress_body(env).
|
146
|
+
expect(middleware.decompress_body(env)).to eq(bod)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -101,20 +101,20 @@ describe Account do
|
|
101
101
|
|
102
102
|
it "should respond to attributes" do
|
103
103
|
['Name','Id','Mls','MlsId','Office'].each do |k|
|
104
|
-
(@account.send k.to_sym).
|
104
|
+
expect(@account.send k.to_sym).to be_a(String)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should have primary subresources" do
|
109
|
-
@account.emails.primary.Address.
|
110
|
-
@account.phones.primary.Number.
|
111
|
-
@account.addresses.primary.Address.
|
112
|
-
@account.websites.primary.Uri.
|
109
|
+
expect(@account.emails.primary.Address).to eq("work@test.com")
|
110
|
+
expect(@account.phones.primary.Number).to eq("701-555-1212")
|
111
|
+
expect(@account.addresses.primary.Address).to eq("101 Main Ave, Phoenix, AZ 12345")
|
112
|
+
expect(@account.websites.primary.Uri).to eq("http://iamthebestagent.com")
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should be able to provide a primary image" do
|
116
|
-
@account.primary_img("Photo").Name.
|
117
|
-
@account.primary_img("Logo").Name.
|
116
|
+
expect(@account.primary_img("Photo").Name).to eq('My Photo 1')
|
117
|
+
expect(@account.primary_img("Logo").Name).to eq('1 My Logo')
|
118
118
|
end
|
119
119
|
|
120
120
|
after(:each) do
|
@@ -131,19 +131,19 @@ describe Account do
|
|
131
131
|
on_get_it "should get my account" do
|
132
132
|
stub_api_get("/my/account", 'accounts/my.json')
|
133
133
|
account = Account.my
|
134
|
-
account.Id.
|
135
|
-
account.websites.first.Name.
|
134
|
+
expect(account.Id).to eq("20000426173054342350000000")
|
135
|
+
expect(account.websites.first.Name).to eq('My Work Website')
|
136
136
|
end
|
137
137
|
|
138
138
|
on_put_it "should save my portal account" do
|
139
139
|
stub_api_get("/my/account", 'accounts/my_portal.json')
|
140
140
|
stub_api_put("/my/account", 'accounts/my_save.json', 'accounts/my_put.json')
|
141
141
|
account = Account.my
|
142
|
-
account.Id.
|
143
|
-
account.GetEmailUpdates.
|
142
|
+
expect(account.Id).to eq("20110426173054342350000000")
|
143
|
+
expect(account.GetEmailUpdates).to eq(false)
|
144
144
|
account.GetEmailUpdates = true
|
145
145
|
account.save!
|
146
|
-
account.GetEmailUpdates.
|
146
|
+
expect(account.GetEmailUpdates).to eq(true)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -151,10 +151,10 @@ describe Account do
|
|
151
151
|
on_get_it "should get all accounts" do
|
152
152
|
stub_api_get("/accounts", 'accounts/all.json')
|
153
153
|
accounts = Account.get
|
154
|
-
accounts.
|
155
|
-
accounts.length.
|
156
|
-
accounts.first.Id.
|
157
|
-
accounts.last.Id.
|
154
|
+
expect(accounts).to be_an(Array)
|
155
|
+
expect(accounts.length).to eq(3)
|
156
|
+
expect(accounts.first.Id).to eq("20000426173054342350000000")
|
157
|
+
expect(accounts.last.Id).to eq("20110126173054382350000000")
|
158
158
|
end
|
159
159
|
on_put_it "should save password" do
|
160
160
|
stub_api_get("/my/account", 'accounts/my.json')
|
@@ -162,7 +162,7 @@ describe Account do
|
|
162
162
|
stub_api_put("/accounts/#{account.Id}", 'accounts/password_save.json', 'accounts/my.json')
|
163
163
|
account.Password = "1"
|
164
164
|
account.PasswordValidation = "1"
|
165
|
-
account.save.
|
165
|
+
expect(account.save).to be(true)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -170,10 +170,10 @@ describe Account do
|
|
170
170
|
on_get_it "should all office accounts" do
|
171
171
|
stub_api_get("/accounts/by/office/20030426173014239760000000", 'accounts/office.json')
|
172
172
|
accounts = Account.by_office("20030426173014239760000000")
|
173
|
-
accounts.
|
174
|
-
accounts.length.
|
173
|
+
expect(accounts).to be_an(Array)
|
174
|
+
expect(accounts.length).to eq(2)
|
175
175
|
accounts.each do |account|
|
176
|
-
accounts.first.OfficeId.
|
176
|
+
expect(accounts.first.OfficeId).to eq("20030426173014239760000000")
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|