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
@@ -6,9 +6,9 @@ describe SparkApi::OptionsHash do
|
|
6
6
|
"parameter_two" => 2,
|
7
7
|
3 => 3}
|
8
8
|
o_h = SparkApi::OptionsHash.new(h)
|
9
|
-
o_h.keys.size.
|
10
|
-
o_h["parameter_one"].
|
11
|
-
o_h["parameter_two"].
|
12
|
-
o_h[3].
|
9
|
+
expect(o_h.keys.size).to eq(3)
|
10
|
+
expect(o_h["parameter_one"]).to eq(1)
|
11
|
+
expect(o_h["parameter_two"]).to eq(2)
|
12
|
+
expect(o_h[3]).to eq(3)
|
13
13
|
end
|
14
14
|
end
|
@@ -37,54 +37,54 @@ describe SparkApi::PaginateResponse do
|
|
37
37
|
json = "{#{paginate_json}}"
|
38
38
|
hash = JSON.parse(json)
|
39
39
|
results = subject.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
40
|
-
results.offset.
|
41
|
-
results.next_page.
|
42
|
-
results.previous_page.
|
43
|
-
results.current_page.
|
44
|
-
results.per_page.
|
45
|
-
results.total_pages.
|
46
|
-
results.total_entries.
|
47
|
-
results[0].
|
40
|
+
expect(results.offset).to eq(0)
|
41
|
+
expect(results.next_page).to eq(2)
|
42
|
+
expect(results.previous_page).to eq(nil)
|
43
|
+
expect(results.current_page).to eq(1)
|
44
|
+
expect(results.per_page).to eq(10)
|
45
|
+
expect(results.total_pages).to eq(4)
|
46
|
+
expect(results.total_entries).to eq(38)
|
47
|
+
expect(results[0]).to eq(1)
|
48
48
|
end
|
49
49
|
it "should give me the second page" do
|
50
50
|
json = "{#{paginate_json(2)}}"
|
51
51
|
hash = JSON.parse(json)
|
52
52
|
results = subject.paginate_response([11,12,13,14,15,16,17,18,19,20], hash["Pagination"])
|
53
|
-
results.offset.
|
54
|
-
results.next_page.
|
55
|
-
results.previous_page.
|
56
|
-
results.current_page.
|
57
|
-
results.per_page.
|
58
|
-
results.total_pages.
|
59
|
-
results.total_entries.
|
60
|
-
results[0].
|
53
|
+
expect(results.offset).to eq(10)
|
54
|
+
expect(results.next_page).to eq(3)
|
55
|
+
expect(results.previous_page).to eq(1)
|
56
|
+
expect(results.current_page).to eq(2)
|
57
|
+
expect(results.per_page).to eq(10)
|
58
|
+
expect(results.total_pages).to eq(4)
|
59
|
+
expect(results.total_entries).to eq(38)
|
60
|
+
expect(results[0]).to eq(11)
|
61
61
|
end
|
62
62
|
it "should give me the third page" do
|
63
63
|
json = "{#{paginate_json(3)}}"
|
64
64
|
hash = JSON.parse(json)
|
65
65
|
results = subject.paginate_response([21,22,23,24,25,26,27,28,29,30], hash["Pagination"])
|
66
|
-
results.offset.
|
67
|
-
results.next_page.
|
68
|
-
results.previous_page.
|
69
|
-
results.current_page.
|
70
|
-
results.per_page.
|
71
|
-
results.total_pages.
|
72
|
-
results.total_entries.
|
73
|
-
results[0].
|
66
|
+
expect(results.offset).to eq(20)
|
67
|
+
expect(results.next_page).to eq(4)
|
68
|
+
expect(results.previous_page).to eq(2)
|
69
|
+
expect(results.current_page).to eq(3)
|
70
|
+
expect(results.per_page).to eq(10)
|
71
|
+
expect(results.total_pages).to eq(4)
|
72
|
+
expect(results.total_entries).to eq(38)
|
73
|
+
expect(results[0]).to eq(21)
|
74
74
|
end
|
75
75
|
it "should give me the last page" do
|
76
76
|
json = "{#{paginate_json(4)}}"
|
77
77
|
hash = JSON.parse(json)
|
78
78
|
results = subject.paginate_response([31,32,33,34,35,36,37,38], hash["Pagination"])
|
79
|
-
results.offset.
|
80
|
-
results.next_page.
|
81
|
-
results.previous_page.
|
82
|
-
results.current_page.
|
83
|
-
results.per_page.
|
84
|
-
results.total_pages.
|
85
|
-
results.total_entries.
|
86
|
-
results[0].
|
87
|
-
results[-1].
|
79
|
+
expect(results.offset).to eq(30)
|
80
|
+
expect(results.next_page).to eq(nil)
|
81
|
+
expect(results.previous_page).to eq(3)
|
82
|
+
expect(results.current_page).to eq(4)
|
83
|
+
expect(results.per_page).to eq(10)
|
84
|
+
expect(results.total_pages).to eq(4)
|
85
|
+
expect(results.total_entries).to eq(38)
|
86
|
+
expect(results[0]).to eq(31)
|
87
|
+
expect(results[-1]).to eq(38)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -93,27 +93,27 @@ describe SparkApi::Paginate do
|
|
93
93
|
describe "paginate" do
|
94
94
|
it "should give me a will paginate collection" do
|
95
95
|
results = PaginateModelTester.paginate(:page => 1)
|
96
|
-
results.
|
97
|
-
results.offset.
|
98
|
-
results.next_page.
|
99
|
-
results.previous_page.
|
100
|
-
results.current_page.
|
101
|
-
results.per_page.
|
102
|
-
results.total_pages.
|
103
|
-
results.total_entries.
|
96
|
+
expect(results).to be_a(WillPaginate::Collection)
|
97
|
+
expect(results.offset).to eq(0)
|
98
|
+
expect(results.next_page).to eq(2)
|
99
|
+
expect(results.previous_page).to eq(nil)
|
100
|
+
expect(results.current_page).to eq(1)
|
101
|
+
expect(results.per_page).to eq(10)
|
102
|
+
expect(results.total_pages).to eq(4)
|
103
|
+
expect(results.total_entries).to eq(38)
|
104
104
|
|
105
|
-
results[0].
|
106
|
-
results[0].val.
|
105
|
+
expect(results[0]).to be_a(PaginateModelTester)
|
106
|
+
expect(results[0].val).to eq(1)
|
107
107
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should give me pagination options" do
|
111
111
|
PaginateModelTester.paginate(:page => 1)
|
112
112
|
opts = PaginateModelTester.options
|
113
|
-
opts["_pagination"].
|
114
|
-
opts["_limit"].
|
115
|
-
opts["_page"].
|
116
|
-
opts.has_key?(:page).
|
113
|
+
expect(opts["_pagination"]).to eq(1)
|
114
|
+
expect(opts["_limit"]).to eq(25)
|
115
|
+
expect(opts["_page"]).to eq(1)
|
116
|
+
expect(opts.has_key?(:page)).to eq(false)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -121,7 +121,7 @@ describe SparkApi::Paginate do
|
|
121
121
|
it "should set the default model max results per page" do
|
122
122
|
results = PaginateModelTester50.paginate(:page => 1)
|
123
123
|
opts = PaginateModelTester50.options
|
124
|
-
opts["_limit"].
|
124
|
+
expect(opts["_limit"]).to eq(50)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -151,18 +151,18 @@ describe SparkApi::Paginate do
|
|
151
151
|
}).
|
152
152
|
to_return(:body => json)
|
153
153
|
results = subject.paginate(:page=>1, :per_page=>10)
|
154
|
-
results.
|
155
|
-
results.offset.
|
156
|
-
results.next_page.
|
157
|
-
results.previous_page.
|
158
|
-
results.current_page.
|
159
|
-
results.per_page.
|
160
|
-
results.total_pages.
|
161
|
-
results.total_entries.
|
162
|
-
results.length.
|
154
|
+
expect(results).to be_a(WillPaginate::Collection)
|
155
|
+
expect(results.offset).to eq(0)
|
156
|
+
expect(results.next_page).to eq(2)
|
157
|
+
expect(results.previous_page).to eq(nil)
|
158
|
+
expect(results.current_page).to eq(1)
|
159
|
+
expect(results.per_page).to eq(10)
|
160
|
+
expect(results.total_pages).to eq(4)
|
161
|
+
expect(results.total_entries).to eq(38)
|
162
|
+
expect(results.length).to eq(10)
|
163
163
|
|
164
|
-
results[0].
|
165
|
-
results[0].ListPrice.
|
164
|
+
expect(results[0]).to be_a(subject)
|
165
|
+
expect(results[0].ListPrice).to eq(50000.0)
|
166
166
|
|
167
167
|
end
|
168
168
|
it "gives me page two of listings" do
|
@@ -184,9 +184,9 @@ describe SparkApi::Paginate do
|
|
184
184
|
}).
|
185
185
|
to_return(:body => json)
|
186
186
|
results = subject.paginate(:page=>2, :per_page=>10)
|
187
|
-
results.next_page.
|
188
|
-
results.previous_page.
|
189
|
-
results.current_page.
|
187
|
+
expect(results.next_page).to eq(3)
|
188
|
+
expect(results.previous_page).to eq(1)
|
189
|
+
expect(results.current_page).to eq(2)
|
190
190
|
end
|
191
191
|
it "gives me page four of listings" do
|
192
192
|
json = <<-JSON
|
@@ -207,16 +207,16 @@ describe SparkApi::Paginate do
|
|
207
207
|
}).
|
208
208
|
to_return(:body => json)
|
209
209
|
results = subject.paginate(:page=>4, :per_page=>10)
|
210
|
-
results.next_page.
|
211
|
-
results.previous_page.
|
212
|
-
results.current_page.
|
213
|
-
results.per_page.
|
214
|
-
results.total_pages.
|
215
|
-
results.total_entries.
|
210
|
+
expect(results.next_page).to eq(nil)
|
211
|
+
expect(results.previous_page).to eq(3)
|
212
|
+
expect(results.current_page).to eq(4)
|
213
|
+
expect(results.per_page).to eq(10)
|
214
|
+
expect(results.total_pages).to eq(4)
|
215
|
+
expect(results.total_entries).to eq(38)
|
216
216
|
|
217
|
-
results.length.
|
218
|
-
results[0].
|
219
|
-
results[0].ListPrice.
|
217
|
+
expect(results.length).to eq(8)
|
218
|
+
expect(results[0]).to be_a(subject)
|
219
|
+
expect(results[0].ListPrice).to eq(50000.0)
|
220
220
|
end
|
221
221
|
|
222
222
|
end
|
@@ -18,12 +18,12 @@ describe SparkApi::PrimaryArray do
|
|
18
18
|
d = PrimaryModel.new(4, true)
|
19
19
|
e = PrimaryModel.new(5)
|
20
20
|
tester = subject.class.new([d,e])
|
21
|
-
tester.primary.
|
21
|
+
expect(tester.primary).to eq(d)
|
22
22
|
tester = subject.class.new([a,b,c,d,e])
|
23
|
-
tester.primary.
|
23
|
+
expect(tester.primary).to eq(d)
|
24
24
|
# Note, it doesn't care if there is more than one primary, just returns first in the list.
|
25
25
|
b.Primary = true
|
26
|
-
tester.primary.
|
26
|
+
expect(tester.primary).to eq(b)
|
27
27
|
end
|
28
28
|
it "should return nil when there is no primary element" do
|
29
29
|
a = PrimaryModel.new(1)
|
@@ -32,9 +32,9 @@ describe SparkApi::PrimaryArray do
|
|
32
32
|
d = PrimaryModel.new(4)
|
33
33
|
e = PrimaryModel.new(5)
|
34
34
|
tester = subject.class.new([])
|
35
|
-
tester.primary.
|
35
|
+
expect(tester.primary).to be(nil)
|
36
36
|
tester = subject.class.new([a,b,c,d,e])
|
37
|
-
tester.primary.
|
37
|
+
expect(tester.primary).to be(nil)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -4,45 +4,45 @@ describe SparkApi do
|
|
4
4
|
describe SparkApi::ClientError do
|
5
5
|
subject { SparkApi::ClientError.new({:message=>"OMG FAIL", :code=>1234, :status=>500, :request_path => '/v1/foo', :request_id => 'deadbeef'}) }
|
6
6
|
it "should print a helpful to_s" do
|
7
|
-
subject.to_s.
|
8
|
-
subject.message.
|
7
|
+
expect(subject.to_s).to eq("OMG FAIL")
|
8
|
+
expect(subject.message).to eq("OMG FAIL")
|
9
9
|
end
|
10
10
|
it "should have an api code" do
|
11
|
-
subject.code.
|
11
|
+
expect(subject.code).to eq(1234)
|
12
12
|
end
|
13
13
|
it "should have an http status" do
|
14
|
-
subject.status.
|
14
|
+
expect(subject.status).to eq(500)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have a request_path" do
|
18
|
-
subject.request_path.
|
18
|
+
expect(subject.request_path).to eq('/v1/foo')
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should have a request_id" do
|
22
|
-
subject.request_id.
|
22
|
+
expect(subject.request_id).to eq('deadbeef')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise and exception with attached message" do
|
26
26
|
expect { raise subject.class, {:message=>"My Message", :code=>1000, :status=>404}}.to raise_error(SparkApi::ClientError) do |e|
|
27
|
-
e.message.
|
28
|
-
e.code.
|
29
|
-
e.status.
|
27
|
+
expect(e.message).to eq("My Message")
|
28
|
+
expect(e.code).to eq(1000)
|
29
|
+
expect(e.status).to eq(404)
|
30
30
|
end
|
31
31
|
expect { raise subject.class.new({:message=>"My Message", :code=>1000, :status=>404}) }.to raise_error(SparkApi::ClientError) do |e|
|
32
|
-
e.message.
|
33
|
-
e.code.
|
34
|
-
e.status.
|
32
|
+
expect(e.message).to eq("My Message")
|
33
|
+
expect(e.code).to eq(1000)
|
34
|
+
expect(e.status).to eq(404)
|
35
35
|
end
|
36
36
|
expect { raise subject.class.new({:code=>1000, :status=>404}), "My Message"}.to raise_error(SparkApi::ClientError) do |e|
|
37
|
-
e.message.
|
38
|
-
e.code.
|
39
|
-
e.status.
|
37
|
+
expect(e.message).to eq("My Message")
|
38
|
+
expect(e.code).to eq(1000)
|
39
|
+
expect(e.status).to eq(404)
|
40
40
|
end
|
41
41
|
expect { raise subject.class, "My Message"}.to raise_error(SparkApi::ClientError) do |e|
|
42
|
-
e.message.
|
43
|
-
e.code.
|
44
|
-
e.status.
|
45
|
-
e.request_id.
|
42
|
+
expect(e.message).to eq("My Message")
|
43
|
+
expect(e.code).to eq(nil)
|
44
|
+
expect(e.status).to eq(nil)
|
45
|
+
expect(e.request_id).to eq(nil)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -54,34 +54,34 @@ describe SparkApi do
|
|
54
54
|
end
|
55
55
|
it "should have results when successful" do
|
56
56
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => true, "Results" => []}})
|
57
|
-
r.success
|
58
|
-
r.results.empty
|
59
|
-
r.request_id.
|
57
|
+
expect(r.success?).to be(true)
|
58
|
+
expect(r.results.empty?).to be(true)
|
59
|
+
expect(r.request_id).to eq nil
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should return the request_id" do
|
63
63
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => true, "Results" => []}}, 'foobar')
|
64
|
-
r.success
|
65
|
-
r.request_id.
|
64
|
+
expect(r.success?).to be(true)
|
65
|
+
expect(r.request_id).to eq('foobar')
|
66
66
|
end
|
67
67
|
it "should have a message on error" do
|
68
68
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure."}})
|
69
|
-
r.success
|
70
|
-
r.message.
|
69
|
+
expect(r.success?).to be(false)
|
70
|
+
expect(r.message).to eq("I am a failure.")
|
71
71
|
end
|
72
72
|
it "should have SparkQLErrors when present" do
|
73
73
|
err = {"Token" => "ExpirationDate", "Status" => "Dropped"}
|
74
74
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure from .",
|
75
75
|
"SparkQLErrors" => [err]
|
76
76
|
}})
|
77
|
-
r.sparkql_errors.first.
|
77
|
+
expect(r.sparkql_errors.first).to eq(err)
|
78
78
|
end
|
79
79
|
it "should have Errors when present" do
|
80
80
|
err = {"Type" => "InvalidAttribute", "Attribute" => "DisplayName", "Message" => "DisplayName is wrong."}
|
81
81
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure from .",
|
82
82
|
"Errors" => [err]
|
83
83
|
}})
|
84
|
-
r.errors.first.
|
84
|
+
expect(r.errors.first).to eq(err)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -118,6 +118,8 @@ describe SparkApi do
|
|
118
118
|
stub.put('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234', '{"D":{"Contacts":[{"DisplayName":"WLMCEWENS Contact","PrimaryEmail":"wlmcewen789@fbsdata.com"}]}}') { [200, {}, '{"D": {
|
119
119
|
"Success": true}}']
|
120
120
|
}
|
121
|
+
stub.put('/v1/arraydata?ApiSig=SignedToken&AuthToken=1234', '{"D":["A","B","C"]}') {[200, {}, '{"D": {
|
122
|
+
"Success": true}}']}
|
121
123
|
stub.delete('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234') { [200, {}, '{"D": {
|
122
124
|
"Success": true}}']
|
123
125
|
}
|
@@ -191,55 +193,59 @@ describe SparkApi do
|
|
191
193
|
r
|
192
194
|
end
|
193
195
|
it "should get a service" do
|
194
|
-
subject.get('/system')[0]["Name"].
|
196
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
195
197
|
end
|
196
198
|
it "should get a service with parameters" do
|
197
|
-
subject.get('/marketstatistics/price', "Options" => "ActiveAverageListPrice")[0]["ActiveAverageListPrice"].
|
199
|
+
expect(subject.get('/marketstatistics/price', "Options" => "ActiveAverageListPrice")[0]["ActiveAverageListPrice"]).to eq([100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000])
|
198
200
|
end
|
199
201
|
it "should post to a service" do
|
200
202
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
201
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
203
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
202
204
|
end
|
203
205
|
it "should put to a service" do
|
204
206
|
# This is a hypothetical unsupported service action at this time
|
205
207
|
data = {"Contacts" => [{"DisplayName"=>"WLMCEWENS Contact","PrimaryEmail"=>"wlmcewen789@fbsdata.com"}]}
|
206
|
-
subject.put('/contacts/1000', data).size.
|
208
|
+
expect(subject.put('/contacts/1000', data).size).to be(0)
|
207
209
|
# No validation here, if no error is raised, everything is hunky dory
|
208
210
|
end
|
209
211
|
it "should delete from a service" do
|
210
212
|
# This is a hypothetical unsupported service action at this time
|
211
|
-
subject.delete('/contacts/1000').size.
|
213
|
+
expect(subject.delete('/contacts/1000').size).to be(0)
|
212
214
|
# No validation here, if no error is raised, everything is hunky dory
|
213
215
|
end
|
214
216
|
|
215
217
|
it "should escape a path correctly" do
|
216
|
-
subject.get('/test path with spaces').length.
|
218
|
+
expect(subject.get('/test path with spaces').length).to eq(0)
|
217
219
|
# now try this with an already escaped path. Kaboom!
|
218
220
|
expect { subject.get('/test%20path%20with%20spaces') }.to raise_error()
|
219
221
|
end
|
220
222
|
|
221
223
|
it "post data should support non json data" do
|
222
224
|
# Other MISC requests
|
223
|
-
subject.post('/stringdata', 'I am a lonely String!').success
|
225
|
+
expect(subject.post('/stringdata', 'I am a lonely String!').success?).to eq(true)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should support arrays in the body" do
|
229
|
+
expect(subject.put('/arraydata', ["A","B","C"]).success?).to be true
|
224
230
|
end
|
225
231
|
|
226
232
|
it "should allow response object to be returned instead of body" do
|
227
233
|
r = subject.get('/system', { full_response: true })
|
228
234
|
|
229
|
-
r.is_a?(Faraday::Response).
|
230
|
-
r.status.
|
235
|
+
expect(r.is_a?(Faraday::Response)).to be(true)
|
236
|
+
expect(r.status).to eq(200)
|
231
237
|
end
|
232
238
|
|
233
239
|
it "should give me BigDecimal results for large floating point numbers" do
|
234
|
-
MultiJson.default_adapter.
|
240
|
+
expect(MultiJson.default_adapter).to eq(:yajl) unless jruby?
|
235
241
|
result = subject.get('/listings/1000')[0]
|
236
|
-
result["StandardFields"]["BuildingAreaTotal"].
|
237
|
-
|
238
|
-
result["StandardFields"]["BuildingAreaTotal"].
|
242
|
+
expect(result["StandardFields"]["BuildingAreaTotal"]).to be_a(Float)
|
243
|
+
skip("our JSON parser does not support large decimal types. Anyone feel like writing some c code?") do
|
244
|
+
expect(result["StandardFields"]["BuildingAreaTotal"]).to be_a(BigDecimal)
|
239
245
|
number = BigDecimal.new(result["StandardFields"]["BuildingAreaTotal"].to_s)
|
240
|
-
number.to_s.
|
246
|
+
expect(number.to_s).to eq(BigDecimal.new("0.000000000000000000000000001").to_s)
|
241
247
|
number = BigDecimal.new(result["StandardFields"]["ListPrice"].to_s)
|
242
|
-
number.to_s.
|
248
|
+
expect(number.to_s).to eq(BigDecimal.new("9999999999999999999999999.99").to_s)
|
243
249
|
end
|
244
250
|
end
|
245
251
|
|
@@ -273,11 +279,11 @@ describe SparkApi do
|
|
273
279
|
r
|
274
280
|
end
|
275
281
|
it "should authenticate and then get a service" do
|
276
|
-
subject.get('/system')[0]["Name"].
|
282
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
277
283
|
end
|
278
284
|
it "should authenticate and then post to a service" do
|
279
285
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
280
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
286
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
281
287
|
end
|
282
288
|
end
|
283
289
|
|
@@ -316,13 +322,13 @@ describe SparkApi do
|
|
316
322
|
r
|
317
323
|
end
|
318
324
|
it "should reauthenticate and then get a service" do
|
319
|
-
subject.get('/system')[0]["Name"].
|
320
|
-
subject.reauthenticated
|
325
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
326
|
+
expect(subject.reauthenticated?).to eq(true)
|
321
327
|
end
|
322
328
|
it "should reauthenticate and then post to a service" do
|
323
329
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
324
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
325
|
-
subject.reauthenticated
|
330
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
331
|
+
expect(subject.reauthenticated?).to eq(true)
|
326
332
|
end
|
327
333
|
end
|
328
334
|
|
@@ -334,13 +340,13 @@ describe SparkApi do
|
|
334
340
|
r
|
335
341
|
end
|
336
342
|
it "should reauthenticate and then get a service" do
|
337
|
-
subject.get('/system')[0]["Name"].
|
338
|
-
subject.reauthenticated
|
343
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
344
|
+
expect(subject.reauthenticated?).to eq(true)
|
339
345
|
end
|
340
346
|
it "should reauthenticate and then post to a service" do
|
341
347
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
342
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
343
|
-
subject.reauthenticated
|
348
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
349
|
+
expect(subject.reauthenticated?).to eq(true)
|
344
350
|
end
|
345
351
|
end
|
346
352
|
|
@@ -378,19 +384,19 @@ describe SparkApi do
|
|
378
384
|
end
|
379
385
|
it "should fail horribly on a get" do
|
380
386
|
expect { subject.get('/system')}.to raise_error(SparkApi::PermissionDenied) do |e|
|
381
|
-
e.code.
|
382
|
-
e.request_path.
|
387
|
+
expect(e.code).to eq(SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED)
|
388
|
+
expect(e.request_path.to_s).to match(/\/system/)
|
383
389
|
end
|
384
|
-
subject.reauthenticated.
|
390
|
+
expect(subject.reauthenticated).to eq(2)
|
385
391
|
|
386
392
|
end
|
387
393
|
it "should fail horribly on a post" do
|
388
394
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
389
395
|
expect { subject.post('/contacts', data)}.to raise_error(SparkApi::PermissionDenied) do |e|
|
390
|
-
e.code.
|
391
|
-
e.request_path.
|
396
|
+
expect(e.code).to eq(SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED)
|
397
|
+
expect(e.request_path.to_s).to match(/\/contacts/)
|
392
398
|
end
|
393
|
-
subject.reauthenticated.
|
399
|
+
expect(subject.reauthenticated).to eq(2)
|
394
400
|
end
|
395
401
|
end
|
396
402
|
|