flexmls_api 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +14 -0
- data/README.md +128 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/lib/flexmls_api/authentication.rb +104 -0
- data/lib/flexmls_api/client.rb +20 -0
- data/lib/flexmls_api/configuration.rb +40 -0
- data/lib/flexmls_api/faraday.rb +52 -0
- data/lib/flexmls_api/models/base.rb +76 -0
- data/lib/flexmls_api/models/connect_prefs.rb +10 -0
- data/lib/flexmls_api/models/contact.rb +25 -0
- data/lib/flexmls_api/models/custom_fields.rb +12 -0
- data/lib/flexmls_api/models/document.rb +11 -0
- data/lib/flexmls_api/models/idx_link.rb +45 -0
- data/lib/flexmls_api/models/listing.rb +110 -0
- data/lib/flexmls_api/models/market_statistics.rb +33 -0
- data/lib/flexmls_api/models/photo.rb +15 -0
- data/lib/flexmls_api/models/property_types.rb +7 -0
- data/lib/flexmls_api/models/standard_fields.rb +7 -0
- data/lib/flexmls_api/models/subresource.rb +13 -0
- data/lib/flexmls_api/models/system_info.rb +7 -0
- data/lib/flexmls_api/models/video.rb +16 -0
- data/lib/flexmls_api/models/virtual_tour.rb +18 -0
- data/lib/flexmls_api/models.rb +21 -0
- data/lib/flexmls_api/paginate.rb +87 -0
- data/lib/flexmls_api/request.rb +172 -0
- data/lib/flexmls_api/version.rb +4 -0
- data/lib/flexmls_api.rb +41 -0
- data/spec/fixtures/contacts.json +25 -0
- data/spec/fixtures/listing_document_index.json +19 -0
- data/spec/fixtures/listing_no_subresources.json +38 -0
- data/spec/fixtures/listing_photos_index.json +469 -0
- data/spec/fixtures/listing_videos_index.json +18 -0
- data/spec/fixtures/listing_virtual_tours_index.json +42 -0
- data/spec/fixtures/listing_with_documents.json +52 -0
- data/spec/fixtures/listing_with_photos.json +110 -0
- data/spec/fixtures/listing_with_supplement.json +39 -0
- data/spec/fixtures/listing_with_videos.json +54 -0
- data/spec/fixtures/listing_with_vtour.json +48 -0
- data/spec/fixtures/session.json +10 -0
- data/spec/json_helper.rb +77 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/unit/flexmls_api/configuration_spec.rb +97 -0
- data/spec/unit/flexmls_api/faraday_spec.rb +94 -0
- data/spec/unit/flexmls_api/models/base_spec.rb +62 -0
- data/spec/unit/flexmls_api/models/connect_prefs_spec.rb +9 -0
- data/spec/unit/flexmls_api/models/contact_spec.rb +70 -0
- data/spec/unit/flexmls_api/models/document_spec.rb +39 -0
- data/spec/unit/flexmls_api/models/listing_spec.rb +174 -0
- data/spec/unit/flexmls_api/models/photo_spec.rb +59 -0
- data/spec/unit/flexmls_api/models/property_types_spec.rb +20 -0
- data/spec/unit/flexmls_api/models/standard_fields_spec.rb +42 -0
- data/spec/unit/flexmls_api/models/system_info_spec.rb +37 -0
- data/spec/unit/flexmls_api/models/video_spec.rb +43 -0
- data/spec/unit/flexmls_api/models/virtual_tour_spec.rb +46 -0
- data/spec/unit/flexmls_api/paginate_spec.rb +221 -0
- data/spec/unit/flexmls_api/request_spec.rb +288 -0
- data/spec/unit/flexmls_api_spec.rb +44 -0
- metadata +315 -0
@@ -0,0 +1,174 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Listing do
|
4
|
+
before(:each) do
|
5
|
+
@listing = Listing.new({
|
6
|
+
"ResourceUri"=>"/v1/listings/20080619000032866372000000",
|
7
|
+
"StandardFields"=>{
|
8
|
+
"StreetNumber"=>"********",
|
9
|
+
"ListingId"=>"07-32",
|
10
|
+
"City"=>"Fargo",
|
11
|
+
"Longitude"=>"",
|
12
|
+
"StreetName"=>"********",
|
13
|
+
"YearBuilt"=>nil,
|
14
|
+
"BuildingAreaTotal"=>"1321.0",
|
15
|
+
"PublicRemarks"=>nil,
|
16
|
+
"PostalCode"=>"55320",
|
17
|
+
"ListPrice"=>"100000.0",
|
18
|
+
"BathsThreeQuarter"=>nil,
|
19
|
+
"Latitude"=>"",
|
20
|
+
"StreetDirPrefix"=>nil,
|
21
|
+
"StreetAdditionalInfo"=>"********",
|
22
|
+
"PropertyType"=>"A",
|
23
|
+
"StateOrProvince"=>"ND",
|
24
|
+
"BathsTotal"=>"0.0",
|
25
|
+
"BathsFull"=>nil,
|
26
|
+
"ListingKey"=>"20080619000032866372000000",
|
27
|
+
"StreetDirSuffix"=>"********",
|
28
|
+
"BedsTotal"=>2,
|
29
|
+
"ModificationTimestamp"=>"2010-11-22T23:36:42Z",
|
30
|
+
"BathsHalf"=>nil,
|
31
|
+
"CountyOrParish"=>nil,
|
32
|
+
"Photos" => [{
|
33
|
+
"Uri300"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000.jpg",
|
34
|
+
"ResourceUri"=>"/v1/listings/20080619000032866372000000/photos/20101115201631519737000000",
|
35
|
+
"Name"=>"Designer Entry w/14' Ceilings",
|
36
|
+
"Primary"=>true,
|
37
|
+
"Id"=>"20101115201631519737000000",
|
38
|
+
"Uri800"=>"http=>//devresize.flexmls.com/fgo/800x600/true/20101115201631519737000000-o.jpg",
|
39
|
+
"Uri1024"=>"http=>//devresize.flexmls.com/fgo/1024x768/true/20101115201631519737000000-o.jpg",
|
40
|
+
"UriLarge"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000-o.jpg",
|
41
|
+
"Caption"=>"apostrophe test for CUR-10508",
|
42
|
+
"Uri1280"=>"http=>//devresize.flexmls.com/fgo/1280x1024/true/20101115201631519737000000-o.jpg",
|
43
|
+
"UriThumb"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000-t.jpg",
|
44
|
+
"Uri640"=>"http=>//devresize.flexmls.com/fgo/640x480/true/20101115201631519737000000-o.jpg"
|
45
|
+
}]
|
46
|
+
},
|
47
|
+
"Id"=>"20080619000032866372000000"
|
48
|
+
})
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "attributes" do
|
53
|
+
it "should allow access to fields" do
|
54
|
+
@listing.StandardFields.should be_a Hash
|
55
|
+
@listing.StandardFields['ListingId'].should be_a String
|
56
|
+
@listing.StandardFields['ListPrice'].should match @listing.ListPrice
|
57
|
+
@listing.photos.should be_a Array
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not respond to removed attributes" do
|
61
|
+
@listing.should_not respond_to(:Photos)
|
62
|
+
@listing.should_not respond_to(:Documents)
|
63
|
+
@listing.should_not respond_to(:VirtualTours)
|
64
|
+
@listing.should_not respond_to(:Videos)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "class methods" do
|
70
|
+
it "should respond to find" do
|
71
|
+
Listing.should respond_to(:find)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should respond to first" do
|
75
|
+
Listing.should respond_to(:first)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should respond to last" do
|
79
|
+
Listing.should respond_to(:last)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should respond to my" do
|
83
|
+
Listing.should respond_to(:my)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should respond to find_by_cart_id" do
|
87
|
+
Listing.should respond_to(:find_by_cart_id)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "subresources" do
|
92
|
+
before do
|
93
|
+
stub_auth_request
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
it "should return an array of photos" do
|
98
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
|
99
|
+
with(:query => {
|
100
|
+
:ApiSig => "3c942a2d6746299c476dd2e30d10966b",
|
101
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
102
|
+
:ApiUser => "foobar",
|
103
|
+
:_expand => "Photos"
|
104
|
+
}).
|
105
|
+
to_return(:body => fixture('listing_with_photos.json'))
|
106
|
+
|
107
|
+
l = Listing.find('1234', :ApiUser => "foobar", :_expand => "Photos")
|
108
|
+
l.photos.length.should == 5
|
109
|
+
l.documents.length.should == 0
|
110
|
+
l.videos.length.should == 0
|
111
|
+
l.virtual_tours.length.should == 0
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return an array of documents" do
|
115
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
|
116
|
+
with(:query => {
|
117
|
+
:ApiSig => "554b6e2a3efec8719b782647c19d238d",
|
118
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
119
|
+
:ApiUser => "foobar",
|
120
|
+
:_expand => "Documents"
|
121
|
+
}).
|
122
|
+
to_return(:body => fixture('listing_with_documents.json'))
|
123
|
+
|
124
|
+
l = Listing.find('1234', :ApiUser => "foobar", :_expand => "Documents")
|
125
|
+
l.photos.length.should == 0
|
126
|
+
l.documents.length.should == 2
|
127
|
+
l.videos.length.should == 0
|
128
|
+
l.virtual_tours.length.should == 0
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should return an array of virtual tours" do
|
132
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
|
133
|
+
with(:query => {
|
134
|
+
:ApiSig => "cc966b538640dd6b37dce0067cea2e5a",
|
135
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
136
|
+
:ApiUser => "foobar",
|
137
|
+
:_expand => "VirtualTours"
|
138
|
+
}).
|
139
|
+
to_return(:body => fixture('listing_with_vtour.json'))
|
140
|
+
|
141
|
+
l = Listing.find('1234', :ApiUser => "foobar", :_expand => "VirtualTours")
|
142
|
+
l.virtual_tours.length.should == 1
|
143
|
+
l.photos.length.should == 0
|
144
|
+
l.documents.length.should == 0
|
145
|
+
l.videos.length.should == 0
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
it "should return an array of videos" do
|
150
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
|
151
|
+
with(:query => {
|
152
|
+
:ApiSig => "12afd7ef1d98ca35c613040f5ddb92b2",
|
153
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
154
|
+
:ApiUser => "foobar",
|
155
|
+
:_expand => "Videos"
|
156
|
+
}).
|
157
|
+
to_return(:body => fixture('listing_with_videos.json'))
|
158
|
+
|
159
|
+
l = Listing.find('1234', :ApiUser => "foobar", :_expand => "Videos")
|
160
|
+
l.videos.length.should == 2
|
161
|
+
l.virtual_tours.length.should == 0
|
162
|
+
l.photos.length.should == 0
|
163
|
+
l.documents.length.should == 0
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
after(:each) do
|
170
|
+
@listing = nil
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Photo do
|
4
|
+
before(:each) do
|
5
|
+
@photo = Photo.new({
|
6
|
+
"ResourceUri" => "/listings/20100815153524571646000000/photos/20101124153422574618000000",
|
7
|
+
"Id" => "20101124153422574618000000",
|
8
|
+
"Name" => "Photo 1 name",
|
9
|
+
"Caption" => "caption here",
|
10
|
+
"UriThumb" => "http://photos.cdn.flexmls.com/xyz-t.jpg",
|
11
|
+
"Uri300" => "http://photos.cdn.flexmls.com/xyz.jpg",
|
12
|
+
"Uri640" => "http://cdn.resize.flexmls.com/az/640x480/true/20101124153422574618000000-o.jpg",
|
13
|
+
"Uri800" => "http://cdn.resize.flexmls.com/az/800x600/true/20101124153422574618000000-o.jpg",
|
14
|
+
"Uri1024" => "http://cdn.resize.flexmls.com/az/1024x768/true/20101124153422574618000000-o.jpg",
|
15
|
+
"Uri1280" => "http://cdn.resize.flexmls.com/az/1280x1024/true/20101124153422574618000000-o.jpg",
|
16
|
+
"UriLarge" => "http://photos.cdn.flexmls.com/xyz-o.jpg",
|
17
|
+
"Primary" => true
|
18
|
+
})
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
it "responds to" do
|
24
|
+
@photo.should respond_to(:primary?)
|
25
|
+
Photo.should respond_to(:find_by_listing_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "knows if it's the primary photo" do
|
29
|
+
@photo.primary?.should be_true
|
30
|
+
@photo.Primary = false
|
31
|
+
@photo.primary?.should be_false
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "find photos by listing id" do
|
35
|
+
before do
|
36
|
+
stub_auth_request
|
37
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234/photos").
|
38
|
+
with(:query => {
|
39
|
+
:ApiSig => "d060aa12d3ef573aff7298302e0237fa",
|
40
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
41
|
+
:ApiUser => "foobar"
|
42
|
+
}).
|
43
|
+
to_return(:body => fixture('listing_photos_index.json'))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should get an array of photos" do
|
47
|
+
p = Photo.find_by_listing_key('1234', 'foobar')
|
48
|
+
p.should be_an Array
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
after(:each) do
|
55
|
+
@photo = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe PropertyTypes do
|
4
|
+
before(:each) do
|
5
|
+
@proptypes = PropertyTypes.new({
|
6
|
+
"MlsName"=>"Residential",
|
7
|
+
"MlsCode"=>"A"
|
8
|
+
})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to get" do
|
12
|
+
PropertyTypes.should respond_to(:get)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
@proptypes = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe StandardFields do
|
4
|
+
before(:each) do
|
5
|
+
@stdfields = StandardFields.new({
|
6
|
+
"StreetNumber"=>{"Searchable"=>false},
|
7
|
+
"ListingId"=>{"Searchable"=>true},
|
8
|
+
"City"=>{"Searchable"=>true},
|
9
|
+
"Longitude"=>{"Searchable"=>false},
|
10
|
+
"StreetName"=>{"Searchable"=>false},
|
11
|
+
"YearBuilt"=>{"Searchable"=>true},
|
12
|
+
"BuildingAreaTotal"=>{"Searchable"=>true},
|
13
|
+
"PublicRemarks"=>{"Searchable"=>false},
|
14
|
+
"PostalCode"=>{"Searchable"=>true},
|
15
|
+
"ListPrice"=>{"Searchable"=>true},
|
16
|
+
"BathsThreeQuarter"=>{"Searchable"=>true},
|
17
|
+
"Latitude"=>{"Searchable"=>false},
|
18
|
+
"StreetDirPrefix"=>{"Searchable"=>false},
|
19
|
+
"StreetAdditionalInfo"=>{"Searchable"=>false},
|
20
|
+
"PropertyType"=>{"Searchable"=>true},
|
21
|
+
"StateOrProvince"=>{"Searchable"=>true},
|
22
|
+
"BathsTotal"=>{"Searchable"=>true},
|
23
|
+
"BathsFull"=>{"Searchable"=>true},
|
24
|
+
"ListingKey"=>{"Searchable"=>false},
|
25
|
+
"StreetDirSuffix"=>{"Searchable"=>false},
|
26
|
+
"BedsTotal"=>{"Searchable"=>true},
|
27
|
+
"ModificationTimestamp"=>{"Searchable"=>false},
|
28
|
+
"BathsHalf"=>{"Searchable"=>true},
|
29
|
+
"CountyOrParish"=>{"Searchable"=>true}
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should respond to get" do
|
34
|
+
StandardFields.should respond_to(:get)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
@stdfields = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe SystemInfo do
|
4
|
+
before(:each) do
|
5
|
+
@sysinfo = SystemInfo.new({
|
6
|
+
"Name"=>"beh apiuser",
|
7
|
+
"OfficeId"=>"20071029204441159539000000",
|
8
|
+
"Configuration"=>[{
|
9
|
+
"IdxDisclaimer"=>""
|
10
|
+
}],
|
11
|
+
"Id"=>"20101206154326670813000000",
|
12
|
+
"MlsId"=>"20000809145531659995000000",
|
13
|
+
"Office"=>"",
|
14
|
+
"Mls"=>"Fargo-Moorhead MLS"
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should respond to get" do
|
19
|
+
SystemInfo.should respond_to(:get)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should respond to attributes" do
|
23
|
+
['Name','OfficeId','Id','MlsId','Office','Mls'].each do |k|
|
24
|
+
(@sysinfo.send k.to_sym).should be_a String
|
25
|
+
end
|
26
|
+
@sysinfo.Configuration.should be_a Array
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have an array of config items" do
|
30
|
+
@sysinfo.Configuration.should be_a Array
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
@sysinfo = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Video do
|
4
|
+
|
5
|
+
|
6
|
+
it "responds to" do
|
7
|
+
Video.should respond_to(:find_by_listing_key)
|
8
|
+
Video.new.should respond_to(:branded?)
|
9
|
+
Video.new.should respond_to(:unbranded?)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a type" do
|
13
|
+
Video.new(:Type => "branded").branded?.should == true
|
14
|
+
Video.new(:Type => "unbranded").branded?.should == false
|
15
|
+
Video.new(:Type => "unbranded").unbranded?.should == true
|
16
|
+
Video.new(:Type => "branded").unbranded?.should == false
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe "find videos by listing id" do
|
21
|
+
before do
|
22
|
+
stub_auth_request
|
23
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234/videos").
|
24
|
+
with(:query => {
|
25
|
+
:ApiSig => "c95bfef766128b91a2643fcc2fa40dfc",
|
26
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
27
|
+
:ApiUser => "foobar"
|
28
|
+
}).
|
29
|
+
to_return(:body => fixture('listing_videos_index.json'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get an array of videos" do
|
33
|
+
p = Video.find_by_listing_key('1234', 'foobar')
|
34
|
+
p.should be_an Array
|
35
|
+
p.length.should == 2
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe VirtualTour do
|
4
|
+
before(:each) do
|
5
|
+
@virtualtour = VirtualTour.new({
|
6
|
+
:Uri => "http://www.flexmls.com/",
|
7
|
+
:ResourceUri => "/v1/listings/20060712220814669202000000/virtualtours/20110105165843978012000000",
|
8
|
+
:Name => "My Branded Tour",
|
9
|
+
:Id => "20110105165843978012000000",
|
10
|
+
:Type => "branded"
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should respond to a few methods" do
|
15
|
+
VirtualTour.should respond_to(:find_by_listing_key)
|
16
|
+
@virtualtour.should respond_to(:branded?)
|
17
|
+
@virtualtour.should respond_to(:unbranded?)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should know if it's branded" do
|
21
|
+
@virtualtour.branded?.should == true
|
22
|
+
@virtualtour.unbranded?.should == false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should get virtual tours for a listing" do
|
26
|
+
stub_auth_request
|
27
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234/virtualtours").
|
28
|
+
with( :query => {
|
29
|
+
:ApiSig => "1cb60934d68b64e5eaaab4aff4b7cd3a",
|
30
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
31
|
+
:ApiUser => "foobar"
|
32
|
+
}).
|
33
|
+
to_return(:body => fixture('listing_virtual_tours_index.json'))
|
34
|
+
|
35
|
+
v = VirtualTour.find_by_listing_key('1234', "foobar")
|
36
|
+
v.should be_an Array
|
37
|
+
v.length.should == 5
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
after(:each) do
|
43
|
+
@virtualtour = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
class PaginateResponseTester
|
4
|
+
include FlexmlsApi::PaginateResponse
|
5
|
+
end
|
6
|
+
|
7
|
+
class PaginateModelTester < FlexmlsApi::Models::Base
|
8
|
+
@tester = PaginateResponseTester.new
|
9
|
+
attr_accessor :val
|
10
|
+
def initialize (val)
|
11
|
+
@val = val
|
12
|
+
end
|
13
|
+
class << self
|
14
|
+
attr_accessor :options
|
15
|
+
def get(options)
|
16
|
+
@options = options
|
17
|
+
json = "{#{paginate_json}}"
|
18
|
+
hash = JSON.parse(json)
|
19
|
+
results = @tester.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
20
|
+
collect(results)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class PaginateModelTester50 < PaginateModelTester
|
26
|
+
@tester = PaginateResponseTester.new
|
27
|
+
def self.per_page
|
28
|
+
50
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe FlexmlsApi::PaginateResponse do
|
34
|
+
|
35
|
+
describe "paginate_response" do
|
36
|
+
subject { PaginateResponseTester.new }
|
37
|
+
it "should give me the first page" do
|
38
|
+
json = "{#{paginate_json}}"
|
39
|
+
hash = JSON.parse(json)
|
40
|
+
results = subject.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
41
|
+
results.offset.should eq 0
|
42
|
+
results.next_page.should eq 2
|
43
|
+
results.previous_page.should eq nil
|
44
|
+
results.current_page.should eq 1
|
45
|
+
results.per_page.should eq 10
|
46
|
+
results.total_pages.should eq 4
|
47
|
+
results.total_entries.should eq 38
|
48
|
+
results[0].should eq 1
|
49
|
+
end
|
50
|
+
it "should give me the second page" do
|
51
|
+
json = "{#{paginate_json(2)}}"
|
52
|
+
hash = JSON.parse(json)
|
53
|
+
results = subject.paginate_response([11,12,13,14,15,16,17,18,19,20], hash["Pagination"])
|
54
|
+
results.offset.should eq 10
|
55
|
+
results.next_page.should eq 3
|
56
|
+
results.previous_page.should eq 1
|
57
|
+
results.current_page.should eq 2
|
58
|
+
results.per_page.should eq 10
|
59
|
+
results.total_pages.should eq 4
|
60
|
+
results.total_entries.should eq 38
|
61
|
+
results[0].should eq 11
|
62
|
+
end
|
63
|
+
it "should give me the third page" do
|
64
|
+
json = "{#{paginate_json(3)}}"
|
65
|
+
hash = JSON.parse(json)
|
66
|
+
results = subject.paginate_response([21,22,23,24,25,26,27,28,29,30], hash["Pagination"])
|
67
|
+
results.offset.should eq 20
|
68
|
+
results.next_page.should eq 4
|
69
|
+
results.previous_page.should eq 2
|
70
|
+
results.current_page.should eq 3
|
71
|
+
results.per_page.should eq 10
|
72
|
+
results.total_pages.should eq 4
|
73
|
+
results.total_entries.should eq 38
|
74
|
+
results[0].should eq 21
|
75
|
+
end
|
76
|
+
it "should give me the last page" do
|
77
|
+
json = "{#{paginate_json(4)}}"
|
78
|
+
hash = JSON.parse(json)
|
79
|
+
results = subject.paginate_response([31,32,33,34,35,36,37,38], hash["Pagination"])
|
80
|
+
results.offset.should eq 30
|
81
|
+
results.next_page.should eq nil
|
82
|
+
results.previous_page.should eq 3
|
83
|
+
results.current_page.should eq 4
|
84
|
+
results.per_page.should eq 10
|
85
|
+
results.total_pages.should eq 4
|
86
|
+
results.total_entries.should eq 38
|
87
|
+
results[0].should eq 31
|
88
|
+
results[-1].should eq 38
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe FlexmlsApi::Paginate do
|
94
|
+
describe "paginate" do
|
95
|
+
it "should give me a will paginate collection" do
|
96
|
+
results = PaginateModelTester.paginate(:page => 1)
|
97
|
+
results.class.should eq WillPaginate::Collection
|
98
|
+
results.offset.should eq 0
|
99
|
+
results.next_page.should eq 2
|
100
|
+
results.previous_page.should eq nil
|
101
|
+
results.current_page.should eq 1
|
102
|
+
results.per_page.should eq 10
|
103
|
+
results.total_pages.should eq 4
|
104
|
+
results.total_entries.should eq 38
|
105
|
+
|
106
|
+
results[0].class.should eq PaginateModelTester
|
107
|
+
results[0].val.should eq 1
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should give me pagination options" do
|
112
|
+
PaginateModelTester.paginate(:page => 1)
|
113
|
+
opts = PaginateModelTester.options
|
114
|
+
opts["_pagination"].should eq 1
|
115
|
+
opts["_limit"].should eq 25
|
116
|
+
opts["_page"].should eq 1
|
117
|
+
opts.has_key?(:page).should eq false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "per_page" do
|
122
|
+
it "should set the default model max results per page" do
|
123
|
+
results = PaginateModelTester50.paginate(:page => 1)
|
124
|
+
opts = PaginateModelTester50.options
|
125
|
+
opts["_limit"].should eq 50
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# non unit-y real world test of paginations with listings
|
130
|
+
context "paginating listings" do
|
131
|
+
before do
|
132
|
+
stub_auth_request
|
133
|
+
end
|
134
|
+
|
135
|
+
subject { FlexmlsApi::Models::Listing }
|
136
|
+
it "gives me page one of listings" do
|
137
|
+
json = <<-JSON
|
138
|
+
{"D": {
|
139
|
+
"Success": true,
|
140
|
+
"Results": [#{ListingJson.create_all(10)}],
|
141
|
+
#{paginate_json}
|
142
|
+
}
|
143
|
+
JSON
|
144
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
145
|
+
with(:query => {
|
146
|
+
:ApiSig => "538a4c5ff5d24b0bbf3ad1ef27bdd4cd",
|
147
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
148
|
+
:_limit => '10',
|
149
|
+
:_page => '1',
|
150
|
+
:_pagination => '1'
|
151
|
+
}).
|
152
|
+
to_return(:body => json)
|
153
|
+
results = subject.paginate(:page=>1, :per_page=>10)
|
154
|
+
results.class.should eq WillPaginate::Collection
|
155
|
+
results.offset.should eq 0
|
156
|
+
results.next_page.should eq 2
|
157
|
+
results.previous_page.should eq nil
|
158
|
+
results.current_page.should eq 1
|
159
|
+
results.per_page.should eq 10
|
160
|
+
results.total_pages.should eq 4
|
161
|
+
results.total_entries.should eq 38
|
162
|
+
results.length.should eq 10
|
163
|
+
|
164
|
+
results[0].class.should eq subject
|
165
|
+
results[0].ListPrice.should eq 50000.0
|
166
|
+
|
167
|
+
end
|
168
|
+
it "gives me page two of listings" do
|
169
|
+
json = <<-JSON
|
170
|
+
{"D": {
|
171
|
+
"Success": true,
|
172
|
+
"Results": [#{ListingJson.create_all(10)}],
|
173
|
+
#{paginate_json(2)}
|
174
|
+
}
|
175
|
+
JSON
|
176
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
177
|
+
with(:query => {
|
178
|
+
:ApiSig => "1f156d976097026315573af0ce112174",
|
179
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
180
|
+
:_limit => '10',
|
181
|
+
:_page => '2',
|
182
|
+
:_pagination => '1'
|
183
|
+
}).
|
184
|
+
to_return(:body => json)
|
185
|
+
results = subject.paginate(:page=>2, :per_page=>10)
|
186
|
+
results.next_page.should eq 3
|
187
|
+
results.previous_page.should eq 1
|
188
|
+
results.current_page.should eq 2
|
189
|
+
end
|
190
|
+
it "gives me page four of listings" do
|
191
|
+
json = <<-JSON
|
192
|
+
{"D": {
|
193
|
+
"Success": true,
|
194
|
+
"Results": [#{ListingJson.create_all(8)}],
|
195
|
+
#{paginate_json(4)}
|
196
|
+
}
|
197
|
+
JSON
|
198
|
+
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
199
|
+
with(:query => {
|
200
|
+
:ApiSig => "a1961de57c3129a8b68cb1aae97b168d",
|
201
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
202
|
+
:_limit => '10',
|
203
|
+
:_page => '4',
|
204
|
+
:_pagination => '1'
|
205
|
+
}).
|
206
|
+
to_return(:body => json)
|
207
|
+
results = subject.paginate(:page=>4, :per_page=>10)
|
208
|
+
results.next_page.should eq nil
|
209
|
+
results.previous_page.should eq 3
|
210
|
+
results.current_page.should eq 4
|
211
|
+
results.per_page.should eq 10
|
212
|
+
results.total_pages.should eq 4
|
213
|
+
results.total_entries.should eq 38
|
214
|
+
|
215
|
+
results.length.should eq 8
|
216
|
+
results[0].class.should eq subject
|
217
|
+
results[0].ListPrice.should eq 50000.0
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
end
|