spark_api 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/README.md +86 -3
  2. data/VERSION +1 -1
  3. data/lib/spark_api.rb +1 -0
  4. data/lib/spark_api/authentication/oauth2.rb +43 -2
  5. data/lib/spark_api/configuration/oauth2_configurable.rb +3 -1
  6. data/lib/spark_api/models.rb +1 -0
  7. data/lib/spark_api/models/listing.rb +17 -1
  8. data/lib/spark_api/models/rental_calendar.rb +26 -0
  9. data/lib/spark_api/options_hash.rb +18 -0
  10. data/script/combined_flow_example.rb +55 -0
  11. data/script/oauth2_example.rb +2 -2
  12. data/spec/fixtures/listings/rental_calendar.json +19 -0
  13. data/spec/fixtures/listings/with_rental_calendar.json +52 -0
  14. data/spec/unit/spark_api/authentication/oauth2_spec.rb +79 -1
  15. data/spec/unit/spark_api/models/listing_spec.rb +7 -0
  16. data/spec/unit/spark_api/models/rental_calendar_spec.rb +30 -0
  17. data/spec/unit/spark_api/options_hash_spec.rb +14 -0
  18. metadata +15 -96
  19. data/bin/spark_api~ +0 -8
  20. data/lib/spark_api/authentication/api_auth.rb~ +0 -104
  21. data/lib/spark_api/authentication/base_auth.rb~ +0 -47
  22. data/lib/spark_api/authentication/oauth2.rb~ +0 -199
  23. data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +0 -87
  24. data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +0 -49
  25. data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +0 -45
  26. data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +0 -36
  27. data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +0 -39
  28. data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +0 -25
  29. data/lib/spark_api/cli.rb~ +0 -158
  30. data/lib/spark_api/cli/api_auth.rb~ +0 -8
  31. data/lib/spark_api/cli/oauth2.rb~ +0 -14
  32. data/lib/spark_api/cli/setup.rb~ +0 -47
  33. data/lib/spark_api/configuration.rb~ +0 -54
  34. data/lib/spark_api/configuration/yaml.rb~ +0 -101
  35. data/lib/spark_api/faraday.rb~ +0 -64
  36. data/lib/spark_api/models.rb~ +0 -33
  37. data/lib/spark_api/models/account.rb~ +0 -115
  38. data/lib/spark_api/models/base.rb~ +0 -118
  39. data/lib/spark_api/models/connect_prefs.rb~ +0 -10
  40. data/lib/spark_api/models/constraint.rb~ +0 -16
  41. data/lib/spark_api/models/contact.rb~ +0 -49
  42. data/lib/spark_api/models/custom_fields.rb~ +0 -12
  43. data/lib/spark_api/models/document.rb~ +0 -11
  44. data/lib/spark_api/models/finders.rb~ +0 -45
  45. data/lib/spark_api/models/idx_link.rb~ +0 -47
  46. data/lib/spark_api/models/listing.rb~ +0 -197
  47. data/lib/spark_api/models/listing_cart.rb~ +0 -72
  48. data/lib/spark_api/models/market_statistics.rb~ +0 -33
  49. data/lib/spark_api/models/message.rb~ +0 -21
  50. data/lib/spark_api/models/note.rb~ +0 -41
  51. data/lib/spark_api/models/notification.rb~ +0 -42
  52. data/lib/spark_api/models/open_house.rb~ +0 -24
  53. data/lib/spark_api/models/photo.rb~ +0 -70
  54. data/lib/spark_api/models/property_types.rb~ +0 -7
  55. data/lib/spark_api/models/saved_search.rb~ +0 -16
  56. data/lib/spark_api/models/shared_listing.rb~ +0 -35
  57. data/lib/spark_api/models/standard_fields.rb~ +0 -50
  58. data/lib/spark_api/models/subresource.rb~ +0 -19
  59. data/lib/spark_api/models/system_info.rb~ +0 -14
  60. data/lib/spark_api/models/tour_of_home.rb~ +0 -24
  61. data/lib/spark_api/models/video.rb~ +0 -16
  62. data/lib/spark_api/models/virtual_tour.rb~ +0 -18
  63. data/lib/spark_api/multi_client.rb~ +0 -59
  64. data/lib/spark_api/paginate.rb~ +0 -109
  65. data/lib/spark_api/primary_array.rb~ +0 -29
  66. data/lib/spark_api/request.rb~ +0 -96
  67. data/lib/spark_api/response.rb~ +0 -70
  68. data/lib/spark_api/version.rb~ +0 -4
  69. data/script/console~ +0 -6
  70. data/script/example.rb~ +0 -27
  71. data/spec/unit/flexmls_api_spec.rb~ +0 -23
  72. data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +0 -169
  73. data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +0 -10
  74. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +0 -10
  75. data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +0 -205
  76. data/spec/unit/spark_api/authentication_spec.rb~ +0 -38
  77. data/spec/unit/spark_api/configuration/yaml_spec.rb~ +0 -72
  78. data/spec/unit/spark_api/configuration_spec.rb~ +0 -122
  79. data/spec/unit/spark_api/faraday_spec.rb~ +0 -90
  80. data/spec/unit/spark_api/models/contact_spec.rb~ +0 -108
  81. data/spec/unit/spark_api/models/listing_cart_spec.rb~ +0 -127
  82. data/spec/unit/spark_api/models/listing_spec.rb~ +0 -320
  83. data/spec/unit/spark_api/models/message_spec.rb~ +0 -47
  84. data/spec/unit/spark_api/models/note_spec.rb~ +0 -63
  85. data/spec/unit/spark_api/models/notification_spec.rb~ +0 -62
  86. data/spec/unit/spark_api/models/shared_listing_spec.rb~ +0 -45
  87. data/spec/unit/spark_api/multi_client_spec.rb~ +0 -56
  88. data/spec/unit/spark_api/paginate_spec.rb~ +0 -224
  89. data/spec/unit/spark_api/primary_array_spec.rb~ +0 -41
  90. data/spec/unit/spark_api/request_spec.rb~ +0 -344
@@ -1,90 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- # Test out the faraday connection stack.
4
- describe FlexmlsApi do
5
- describe "FlexmlsMiddleware" do
6
- before(:all) do
7
- stubs = Faraday::Adapter::Test::Stubs.new do |stub|
8
- stub.post('/session') { [200, {}, '{"D": {
9
- "Success": true,
10
- "Results": [{
11
- "AuthToken": "xxxxx",
12
- "Expires": "2010-10-30T15:49:01-05:00",
13
- "Roles": ["idx"]
14
- }]
15
- }}']
16
- }
17
- stub.get('/system') { [200, {}, '{"D": {
18
- "Success": true,
19
- "Results": [{
20
- "Name": "My User",
21
- "OfficeId": "20070830184014994915000000",
22
- "Configuration": [],
23
- "Id": "20101202170654111629000000",
24
- "MlsId": "20000426143505724628000000",
25
- "Office": "test office",
26
- "Mls": "flexmls Web Demonstration Database"
27
- }]}
28
- }']
29
- }
30
- stub.get('/expired') { [401, {}, fixture('errors/expired.json')]
31
- }
32
- stub.get('/methodnotallowed') { [405, {}, '{"D": {
33
- "Success": false,
34
- "Message": "Method Not Allowed",
35
- "Code": "1234"
36
- }}']
37
- }
38
- stub.get('/epicfail') { [500, {}, '{"D": {
39
- "Success": false,
40
- "Message": "EPIC FAIL",
41
- "Code": "0000"
42
- }}']
43
- }
44
- stub.get('/unknownerror') { [499, {}, '{"D": {
45
- "Success": false,
46
- "Message": "Some random status error",
47
- "Code": "0000"
48
- }}']
49
- }
50
- stub.get('/invalidjson') { [200, {}, '{"OMG": "THIS IS NOT THE API JSON THAT I KNOW AND <3!!!"}'] }
51
- stub.get('/garbage') { [200, {}, 'THIS IS TOTAL GARBAGE!'] }
52
- end
53
-
54
- @connection = test_connection(stubs)
55
-
56
- end
57
-
58
- it "should raised exception when token is expired" do
59
- expect { @connection.get('/expired')}.to raise_error(FlexmlsApi::PermissionDenied){ |e| e.code.should == FlexmlsApi::ResponseCodes::SESSION_TOKEN_EXPIRED }
60
- end
61
-
62
- it "should raised exception on error" do
63
- expect { @connection.get('/methodnotallowed')}.to raise_error(FlexmlsApi::NotAllowed){ |e| e.message.should == "Method Not Allowed" }
64
- expect { @connection.get('/epicfail')}.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should be(500) }
65
- expect { @connection.get('/unknownerror')}.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should be(499) }
66
- end
67
-
68
- it "should raised exception on invalid responses" do
69
- expect { @connection.get('/invalidjson')}.to raise_error(FlexmlsApi::InvalidResponse)
70
- # This should be caught in the request code
71
- expect { @connection.get('/garbage')}.to raise_error(MultiJson::DecodeError)
72
- end
73
-
74
- it "should give me a session response" do
75
- response = @connection.post('/session').body
76
- response.success.should eq(true)
77
- session = FlexmlsApi::Authentication::Session.new(response.results[0])
78
- session.auth_token.should eq("xxxxx")
79
- end
80
-
81
- it "should give me an api response" do
82
- response = @connection.get('/system').body
83
- response.success.should eq(true)
84
- response.results.length.should be > 0
85
- end
86
-
87
- end
88
-
89
- end
90
-
@@ -1,108 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
-
4
- describe Contact do
5
- before(:each) do
6
- stub_auth_request
7
- end
8
-
9
- it "should include the finders module" do
10
- Contact.should respond_to(:find)
11
- Contact.should respond_to(:my)
12
- end
13
-
14
- context "/contacts", :support do
15
- on_get_it "should get all my contacts" do
16
- stub_api_get("/contacts", 'contacts/contacts.json')
17
- contacts = Contact.get
18
- contacts.should be_an(Array)
19
- contacts.length.should eq(3)
20
- contacts.first.Id.should eq("20101230223226074201000000")
21
- end
22
-
23
- on_post_it "should save a new contact" do
24
- stub_api_post("/contacts", 'contacts/new.json', 'contacts/post.json')
25
- c=Contact.new
26
- c.attributes["DisplayName"] = "Contact Four"
27
- c.attributes["PrimaryEmail"] = "contact4@fbsdata.com"
28
- c.save.should be(true)
29
- c.Id.should eq('20101230223226074204000000')
30
- end
31
-
32
- on_post_it "should save a new contact and notify" do
33
- stub_api_post("/contacts", 'contacts/new_notify.json', 'contacts/post.json')
34
- c=Contact.new
35
- c.notify=true
36
- c.attributes["DisplayName"] = "Contact Four"
37
- c.attributes["PrimaryEmail"] = "contact4@fbsdata.com"
38
- c.save.should be(true)
39
- c.Id.should eq('20101230223226074204000000')
40
- end
41
-
42
- on_post_it "should fail saving" do
43
- stub_api_post("/contacts", 'contacts/new_empty.json') do |request|
44
- request.to_return(:status => 400, :body => fixture('errors/failure.json'))
45
- end
46
-
47
- c=Contact.new
48
- c.save.should be(false)
49
- expect{ c.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
50
- end
51
-
52
- on_post_it "should fail saving and set @errors" do
53
- stub_api_post("/contacts", 'contacts/new_empty.json') do |request|
54
- request.to_return(:status => 400, :body => fixture('errors/failure_with_msg.json'))
55
- end
56
-
57
- c=Contact.new
58
- c.errors.length.should eq(0)
59
- c.save.should be_false
60
- c.errors.length.should eq(1)
61
- c.errors.first[:code].should eq(1055)
62
- end
63
-
64
- context "on an epic fail" do
65
- on_post_it "should fail saving and asplode" do
66
- stub_api_post("/contacts", 'contacts/new_empty.json') do |request|
67
- request.to_return(:status => 500, :body => fixture('errors/failure.json'))
68
- end
69
-
70
- c=Contact.new()
71
- expect{ c.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 500 }
72
- expect{ c.save }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 500 }
73
- end
74
- end
75
- end
76
-
77
- context "/my/contact", :support do
78
- on_get_it "should get a single contact when using #my" do
79
- stub_api_get("/my/contact", 'contacts/my.json')
80
- contact = Contact.my
81
- contact.should be_a(Contact)
82
- contact.Id.should == '20090928182824338901000000'
83
- contact.DisplayName.should == 'BH FOO'
84
- end
85
- end
86
-
87
- context "/contact/tags", :support do
88
- on_get_it "should get all my Tags" do
89
- stub_api_get("/contacts/tags", 'contacts/tags.json')
90
- tags = Contact.tags
91
- tags.should be_an(Array)
92
- tags.length.should eq(4)
93
- tags.first["Tag"].should eq("Current Buyers")
94
- end
95
- end
96
-
97
- context "/contact/tags/<tag_name>", :support do
98
- on_get_it "should get all contacts with Tag <tag_name>" do
99
- stub_api_get("/contacts/tags/IDX%20Lead", 'contacts/contacts.json')
100
- contacts = Contact.by_tag("IDX Lead")
101
- contacts.should be_an(Array)
102
- contacts.length.should eq(3)
103
- contacts.first.Id.should eq("20101230223226074201000000")
104
- contacts.first.Tags[0].should eq("IDX Lead")
105
- end
106
- end
107
-
108
- end
@@ -1,127 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe ListingCart do
4
- before(:each) do
5
- stub_auth_request
6
- end
7
-
8
- context "/listingcarts", :support do
9
- on_get_it "should get all listing carts" do
10
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
11
- resources = subject.class.get
12
- resources.should be_an(Array)
13
- resources.length.should eq(2)
14
- resources.first.Id.should eq("20100912153422758914000000")
15
- end
16
-
17
- on_post_it "should save a new listing cart" do
18
- stub_api_post("/#{subject.class.element_name}", 'listing_carts/new.json', 'listing_carts/post.json')
19
- subject.ListingIds = ['20110112234857732941000000',
20
- '20110302120238448431000000',
21
- '20110510011212354751000000']
22
- subject.Name = "My Cart's Name"
23
- subject.save.should be(true)
24
- subject.ResourceUri.should eq("/v1/listingcarts/20100912153422758914000000")
25
- end
26
-
27
- on_post_it "should fail saving" do
28
- stub_api_post("/#{subject.class.element_name}",'listing_carts/empty.json') do |request|
29
- request.to_return(:status => 400, :body => fixture('errors/failure.json'))
30
- end
31
- subject
32
- subject.save.should be(false)
33
- expect{ subject.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
34
- end
35
- end
36
-
37
- context "/listingcarts/<cart_id>", :support do
38
- on_get_it "should get a listing cart" do
39
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
40
- resource = subject.class.get.first
41
- resource.Id.should eq("20100912153422758914000000")
42
- resource.Name.should eq("My Listing Cart")
43
- resource.ListingCount.should eq(10)
44
- end
45
-
46
- on_put_it "should save a listing cart" do
47
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
48
- resource = subject.class.get.first
49
- stub_api_put("/#{subject.class.element_name}/#{resource.Id}", 'listing_carts/new.json', 'success.json')
50
- resource.ListingIds = ['20110112234857732941000000',
51
- '20110302120238448431000000',
52
- '20110510011212354751000000']
53
-
54
- resource.Name = "My Cart's Name"
55
- resource.save.should be(true)
56
- resource.ResourceUri.should eq("/v1/listingcarts/20100912153422758914000000")
57
- end
58
-
59
- on_post_it "should add a listing to a cart" do
60
- list_id = "20110621133454434543000000"
61
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
62
- resource = subject.class.get.first
63
- resource.Id.should eq("20100912153422758914000000")
64
- stub_api_post("/#{subject.class.element_name}/#{resource.Id}",'listing_carts/add_listing_post.json', 'listing_carts/add_listing.json')
65
- resource.ListingCount.should eq(10)
66
- resource.add_listing(list_id)
67
- resource.ListingCount.should eq(11)
68
- end
69
-
70
- on_delete_it "should delete a listing cart" do
71
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
72
- resource = subject.class.get.first
73
- resource.Id.should eq("20100912153422758914000000")
74
- resource.Name.should eq("My Listing Cart")
75
- resource.ListingCount.should eq(10)
76
- stub_api_delete("/#{subject.class.element_name}/#{resource.Id}", 'success.json')
77
- resource.delete.empty?.should be(true)
78
- end
79
- end
80
-
81
- context "/listingcarts/<cart_id>/listings/<listing_id>", :support do
82
- on_delete_it "should remove a listing from a cart" do
83
- list_id = "20110621133454434543000000"
84
- stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
85
- resource = subject.class.get.first
86
- resource.Id.should eq("20100912153422758914000000")
87
- stub_api_delete("/#{subject.class.element_name}/#{resource.Id}/listings/#{list_id}", 'listing_carts/remove_listing.json')
88
- resource.ListingCount.should eq(10)
89
- resource.remove_listing(list_id)
90
- resource.ListingCount.should eq(9)
91
- end
92
- end
93
-
94
- context "/listingcarts/for/<listing_id>", :support do
95
- let(:listing){ Listing.new(:Id => "20110112234857732941000000") }
96
- on_get_it "should get all carts for a listing" do
97
- stub_api_get("/#{subject.class.element_name}/for/#{listing.Id}", 'listing_carts/listing_cart.json')
98
- [listing, listing.Id ].each do |l|
99
- resources = subject.class.for(l)
100
- resources.should be_an(Array)
101
- resources.length.should eq(2)
102
- resources.first.Id.should eq("20100912153422758914000000")
103
- end
104
- end
105
- end
106
-
107
- context "/my/listingcarts", :support do
108
- on_get_it "should get the carts for a user" do
109
- stub_api_get("/my/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
110
- resources = subject.class.my
111
- resources.should be_an(Array)
112
- resources.length.should eq(2)
113
- resources.first.Id.should eq("20100912153422758914000000")
114
- end
115
- end
116
-
117
- context "/listingcarts/portal", :support do
118
- on_get_it "should get the carts specific to a portal user" do
119
- stub_api_get("/#{subject.class.element_name}/portal", 'listing_carts/listing_cart.json')
120
- resources = subject.class.portal
121
- resources.should be_an(Array)
122
- resources.length.should eq(2)
123
- resources.first.Id.should eq("20100912153422758914000000")
124
- end
125
- end
126
-
127
- end
@@ -1,320 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe Listing do
4
- before(:each) do
5
-
6
- @listing = Listing.new({
7
- "ResourceUri"=>"/v1/listings/20080619000032866372000000",
8
- "StandardFields"=>{
9
- "StreetNumber"=>"100",
10
- "ListingId"=>"07-32",
11
- "City"=>"Fargo",
12
- "Longitude"=>"",
13
- "StreetName"=>"Someone's",
14
- "YearBuilt"=>nil,
15
- "BuildingAreaTotal"=>"1321.0",
16
- "PublicRemarks"=>nil,
17
- "PostalCode"=>"55320",
18
- "ListPrice"=>"100000.0",
19
- "BathsThreeQuarter"=>nil,
20
- "Latitude"=>"",
21
- "StreetDirPrefix"=>nil,
22
- "StreetAdditionalInfo"=>"********",
23
- "PropertyType"=>"A",
24
- "StateOrProvince"=>"ND",
25
- "BathsTotal"=>"0.0",
26
- "BathsFull"=>nil,
27
- "ListingKey"=>"20080619000032866372000000",
28
- "StreetSuffix"=>"St",
29
- "StreetDirSuffix"=>"********",
30
- "BedsTotal"=>2,
31
- "ModificationTimestamp"=>"2010-11-22T23:36:42Z",
32
- "BathsHalf"=>nil,
33
- "CountyOrParish"=>nil,
34
- "Photos" => [{
35
- "Uri300"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000.jpg",
36
- "ResourceUri"=>"/v1/listings/20080619000032866372000000/photos/20101115201631519737000000",
37
- "Name"=>"Designer Entry w/14' Ceilings",
38
- "Primary"=>true,
39
- "Id"=>"20101115201631519737000000",
40
- "Uri800"=>"http=>//devresize.flexmls.com/fgo/800x600/true/20101115201631519737000000-o.jpg",
41
- "Uri1024"=>"http=>//devresize.flexmls.com/fgo/1024x768/true/20101115201631519737000000-o.jpg",
42
- "UriLarge"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000-o.jpg",
43
- "Caption"=>"apostrophe test for CUR-10508",
44
- "Uri1280"=>"http=>//devresize.flexmls.com/fgo/1280x1024/true/20101115201631519737000000-o.jpg",
45
- "UriThumb"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000-t.jpg",
46
- "Uri640"=>"http=>//devresize.flexmls.com/fgo/640x480/true/20101115201631519737000000-o.jpg"
47
- }]
48
- },
49
- "Id"=>"20080619000032866372000000"
50
- })
51
-
52
- end
53
-
54
- describe "attributes" do
55
- it "should allow access to fields" do
56
- @listing.StandardFields.should be_a(Hash)
57
- @listing.StandardFields['ListingId'].should be_a(String)
58
- @listing.StandardFields['ListPrice'].should match(@listing.ListPrice)
59
- @listing.photos.should be_a(Array)
60
- end
61
-
62
- it "should not respond to removed attributes" do
63
- @listing.should_not respond_to(:Photos)
64
- @listing.should_not respond_to(:Documents)
65
- @listing.should_not respond_to(:VirtualTours)
66
- @listing.should_not respond_to(:Videos)
67
- end
68
-
69
- it "should return street address" do
70
- @listing.street_address.should eq("100 Someone's St")
71
- end
72
-
73
- it "should return the regional address" do
74
- @listing.region_address.should eq("Fargo, ND 55320")
75
- end
76
-
77
- it "should return full address" do
78
- @listing.full_address.should eq("100 Someone's St, Fargo, ND 55320")
79
- end
80
- end
81
-
82
- describe "class methods" do
83
- it "should respond to find" do
84
- Listing.should respond_to(:find)
85
- end
86
-
87
- it "should respond to first" do
88
- Listing.should respond_to(:first)
89
- end
90
-
91
- it "should respond to last" do
92
- Listing.should respond_to(:last)
93
- end
94
-
95
- it "should respond to my" do
96
- Listing.should respond_to(:my)
97
- end
98
-
99
- it "should respond to find_by_cart_id" do
100
- Listing.should respond_to(:find_by_cart_id)
101
- end
102
-
103
- it "should respond to count" do
104
- Listing.should respond_to(:count)
105
- end
106
- end
107
-
108
- describe "URIs" do
109
- before(:each) do
110
- stub_auth_request
111
- end
112
-
113
- context "/listings", :support do
114
- on_get_it "should return listings" do
115
- filter_string = "PostalCode Eq '83805'"
116
- stub_api_get('/listings', 'listings/multiple.json', {:_filter => filter_string})
117
-
118
- listings = Listing.find(:all, :_filter => filter_string)
119
- listings.should be_an(Array)
120
- listings.count.should eq(2)
121
- end
122
-
123
- on_get_it "should return the count" do
124
- stub_api_get("/listings", 'count.json', { :_pagination => "count"})
125
- count = Listing.count()
126
- count.should == 2001
127
- end
128
- end
129
-
130
- context "/listings/<listing_id>", :support do
131
- on_get_it "should return a listing" do
132
- stub_api_get("/listings/20060725224713296297000000", 'listings/no_subresources.json')
133
-
134
- l = Listing.find('20060725224713296297000000')
135
- l.videos.length.should == 0
136
- l.photos.length.should == 0
137
- l.documents.length.should == 0
138
- l.Id.should eq('20060725224713296297000000')
139
- end
140
-
141
- on_put_it "should save a listing that has modified ListPrice" do
142
- list_id = "20060725224713296297000000"
143
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
144
- stub_api_put("/listings/#{list_id}", 'listings/put.json', 'success.json')
145
- l = Listing.find(list_id)
146
- l.ListPrice = 10000.0
147
- l.save.should be(true)
148
- end
149
-
150
- on_put_it "should save a listing that has modified ExpirationDate" do
151
- list_id = "20060725224713296297000000"
152
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
153
- stub_api_put("/listings/#{list_id}", 'listings/put_expiration_date.json', 'success.json')
154
- l = Listing.find(list_id)
155
- l.ExpirationDate = "2011-10-04"
156
- l.save.should be(true)
157
- end
158
-
159
- it "should not save a listing that does not exist", :method => 'PUT' do
160
- list_id = "20060725224713296297000000"
161
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
162
- stub_api_put("/listings/lolwut", 'listings/put.json') do |request|
163
- request.to_return(:status => 400, :body => fixture('errors/failure.json'))
164
- end
165
- l = Listing.find(list_id)
166
- l.Id = "lolwut"
167
- l.ListPrice = 10000.0
168
- l.save.should be(false)
169
- expect{ l.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
170
- end
171
-
172
- on_put_it "should save a listing with constraints" do
173
- list_id = "20060725224713296297000000"
174
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
175
- stub_api_put("/listings/#{list_id}", 'listings/put.json', 'listings/constraints.json')
176
- l = Listing.find(list_id)
177
- l.ListPrice = 10000.0
178
- l.save.should be(true)
179
- l.constraints.size.should eq(1)
180
- l.constraints.first.RuleName.should eq("MaxValue")
181
- end
182
-
183
- on_put_it "should fail saving a listing with constraints and provide the constraints" do
184
- list_id = "20060725224713296297000000"
185
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
186
- stub_api_put("/listings/#{list_id}", 'listings/put.json') do |request|
187
- request.to_return(:status => 400, :body => fixture('errors/failure_with_constraint.json'))
188
- end
189
-
190
- l = Listing.find(list_id)
191
- l.ListPrice = 10000.0
192
- l.save.should be_false
193
- l.constraints.size.should eq(1)
194
- l.constraints.first.RuleName.should eq("MaxIncreasePercent")
195
- l.errors.size.should eq(1)
196
- end
197
-
198
- context "with pagination" do
199
- # This is really a bogus call, but we should make sure our
200
- # pagination collection impl still behaves sanely
201
- on_put_it "should save a listing with constraints" do
202
- list_id = "20060725224713296297000000"
203
- stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
204
- stub_api_put("/listings/#{list_id}", 'listings/put.json', 'listings/constraints_with_pagination.json', :_pagination => '1')
205
- l = Listing.find(list_id)
206
- l.ListPrice = 10000.0
207
- l.save(:_pagination => '1').should be(true)
208
- l.constraints.size.should eq(1)
209
- l.constraints.first.RuleName.should eq("MaxValue")
210
- end
211
- end
212
-
213
- context "subresources" do
214
- on_get_it "should return an array of photos" do
215
- stub_api_get("/listings/1234", 'listings/with_photos.json', { :_expand => "Photos" })
216
-
217
- l = Listing.find('1234', :_expand => "Photos")
218
- l.photos.length.should == 5
219
- l.documents.length.should == 0
220
- l.videos.length.should == 0
221
- l.virtual_tours.length.should == 0
222
- end
223
-
224
- on_get_it "should return an array of documents" do
225
- stub_api_get("/listings/1234", 'listings/with_documents.json', { :_expand => "Documents" })
226
-
227
- l = Listing.find('1234', :_expand => "Documents")
228
- l.photos.length.should == 0
229
- l.documents.length.should == 2
230
- l.videos.length.should == 0
231
- l.virtual_tours.length.should == 0
232
- end
233
-
234
- on_get_it "should return an array of virtual tours" do
235
- stub_api_get("/listings/1234", 'listings/with_vtour.json', { :_expand => "VirtualTours" })
236
-
237
- l = Listing.find('1234', :_expand => "VirtualTours")
238
- l.virtual_tours.length.should == 1
239
- l.photos.length.should == 0
240
- l.documents.length.should == 0
241
- l.videos.length.should == 0
242
- end
243
-
244
- on_get_it "should return an array of videos" do
245
- stub_api_get("/listings/1234", 'listings/with_videos.json', { :_expand => "Videos" })
246
-
247
- l = Listing.find('1234', :_expand => "Videos")
248
- l.videos.length.should == 2
249
- l.virtual_tours.length.should == 0
250
- l.photos.length.should == 0
251
- l.documents.length.should == 0
252
- end
253
-
254
- on_get_it "should return tour of homes" do
255
- stub_api_get("/listings/20060725224713296297000000", 'listings/no_subresources.json')
256
- stub_api_get("/listings/20060725224713296297000000/tourofhomes", 'listings/tour_of_homes.json')
257
-
258
- l = Listing.find('20060725224713296297000000')
259
- l.tour_of_homes().length.should == 2
260
- l.videos.length.should == 0
261
- l.photos.length.should == 0
262
- l.documents.length.should == 0
263
- end
264
-
265
- on_get_it "should return permissions" do
266
- stub_api_get("/listings/20060725224713296297000000", 'listings/with_permissions.json', { :_expand => "Permissions" })
267
- l = Listing.find('20060725224713296297000000', :_expand => "Permissions")
268
- l.Permissions["Editable"].should eq(true)
269
- l.editable?().should eq(true)
270
- l.editable?(:PriceChange).should eq(true)
271
- l.editable?(:Photos).should eq(false)
272
- end
273
- end
274
- end
275
-
276
- context "/my/listings", :support do
277
- on_get_it "should return my listings" do
278
- stub_api_get('/my/listings', 'listings/multiple.json')
279
-
280
- listings = Listing.my
281
- listings.should be_an(Array)
282
- listings.count.should eq(2)
283
- end
284
- end
285
-
286
- context "/office/listings", :support do
287
- on_get_it "GET should return office listings" do
288
- stub_api_get('/office/listings', 'listings/multiple.json')
289
-
290
- listings = Listing.office
291
- listings.should be_an(Array)
292
- listings.count.should eq(2)
293
- end
294
- end
295
-
296
- context "/company/listings", :support do
297
- on_get_it "should return company listings" do
298
- stub_api_get('/company/listings', 'listings/multiple.json')
299
-
300
- listings = Listing.company
301
- listings.should be_an(Array)
302
- listings.count.should eq(2)
303
- end
304
- end
305
-
306
- context "/listings/nearby", :support do
307
- on_get_it "should return nearby homes" do
308
- stub_api_get("/listings/nearby",
309
- 'listings/no_subresources.json', {:Lat => "45.45", :Lon => "-93.98"})
310
- l = Listing.nearby(45.45, -93.98)
311
- l.length.should == 1
312
- end
313
- end
314
- end
315
-
316
- after(:each) do
317
- @listing = nil
318
- end
319
-
320
- end