spark_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +139 -0
- data/LICENSE +14 -0
- data/README.md +153 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/bin/spark_api +8 -0
- data/bin/spark_api~ +8 -0
- data/lib/spark_api.rb +46 -0
- data/lib/spark_api/authentication.rb +55 -0
- data/lib/spark_api/authentication/api_auth.rb +104 -0
- data/lib/spark_api/authentication/api_auth.rb~ +104 -0
- data/lib/spark_api/authentication/base_auth.rb +47 -0
- data/lib/spark_api/authentication/base_auth.rb~ +47 -0
- data/lib/spark_api/authentication/oauth2.rb +198 -0
- data/lib/spark_api/authentication/oauth2.rb~ +199 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +87 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +87 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb +48 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +49 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb +44 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +45 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb +35 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +36 -0
- data/lib/spark_api/authentication/oauth2_impl/middleware.rb +38 -0
- data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +39 -0
- data/lib/spark_api/authentication/oauth2_impl/password_provider.rb +24 -0
- data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +25 -0
- data/lib/spark_api/cli.rb +158 -0
- data/lib/spark_api/cli.rb~ +158 -0
- data/lib/spark_api/cli/api_auth.rb +8 -0
- data/lib/spark_api/cli/api_auth.rb~ +8 -0
- data/lib/spark_api/cli/oauth2.rb +14 -0
- data/lib/spark_api/cli/oauth2.rb~ +14 -0
- data/lib/spark_api/cli/setup.rb +47 -0
- data/lib/spark_api/cli/setup.rb~ +47 -0
- data/lib/spark_api/client.rb +27 -0
- data/lib/spark_api/configuration.rb +54 -0
- data/lib/spark_api/configuration.rb~ +54 -0
- data/lib/spark_api/configuration/yaml.rb +101 -0
- data/lib/spark_api/configuration/yaml.rb~ +101 -0
- data/lib/spark_api/connection.rb +42 -0
- data/lib/spark_api/faraday.rb +64 -0
- data/lib/spark_api/faraday.rb~ +64 -0
- data/lib/spark_api/models.rb +33 -0
- data/lib/spark_api/models.rb~ +33 -0
- data/lib/spark_api/models/account.rb +115 -0
- data/lib/spark_api/models/account.rb~ +115 -0
- data/lib/spark_api/models/base.rb +118 -0
- data/lib/spark_api/models/base.rb~ +118 -0
- data/lib/spark_api/models/connect_prefs.rb +10 -0
- data/lib/spark_api/models/connect_prefs.rb~ +10 -0
- data/lib/spark_api/models/constraint.rb +16 -0
- data/lib/spark_api/models/constraint.rb~ +16 -0
- data/lib/spark_api/models/contact.rb +49 -0
- data/lib/spark_api/models/contact.rb~ +49 -0
- data/lib/spark_api/models/custom_fields.rb +12 -0
- data/lib/spark_api/models/custom_fields.rb~ +12 -0
- data/lib/spark_api/models/document.rb +11 -0
- data/lib/spark_api/models/document.rb~ +11 -0
- data/lib/spark_api/models/finders.rb +45 -0
- data/lib/spark_api/models/finders.rb~ +45 -0
- data/lib/spark_api/models/idx_link.rb +47 -0
- data/lib/spark_api/models/idx_link.rb~ +47 -0
- data/lib/spark_api/models/listing.rb +197 -0
- data/lib/spark_api/models/listing.rb~ +197 -0
- data/lib/spark_api/models/listing_cart.rb +72 -0
- data/lib/spark_api/models/listing_cart.rb~ +72 -0
- data/lib/spark_api/models/market_statistics.rb +33 -0
- data/lib/spark_api/models/market_statistics.rb~ +33 -0
- data/lib/spark_api/models/message.rb +21 -0
- data/lib/spark_api/models/message.rb~ +21 -0
- data/lib/spark_api/models/note.rb +41 -0
- data/lib/spark_api/models/note.rb~ +41 -0
- data/lib/spark_api/models/notification.rb +42 -0
- data/lib/spark_api/models/notification.rb~ +42 -0
- data/lib/spark_api/models/open_house.rb +24 -0
- data/lib/spark_api/models/open_house.rb~ +24 -0
- data/lib/spark_api/models/photo.rb +70 -0
- data/lib/spark_api/models/photo.rb~ +70 -0
- data/lib/spark_api/models/property_types.rb +7 -0
- data/lib/spark_api/models/property_types.rb~ +7 -0
- data/lib/spark_api/models/saved_search.rb +16 -0
- data/lib/spark_api/models/saved_search.rb~ +16 -0
- data/lib/spark_api/models/shared_listing.rb +35 -0
- data/lib/spark_api/models/shared_listing.rb~ +35 -0
- data/lib/spark_api/models/standard_fields.rb +50 -0
- data/lib/spark_api/models/standard_fields.rb~ +50 -0
- data/lib/spark_api/models/subresource.rb +19 -0
- data/lib/spark_api/models/subresource.rb~ +19 -0
- data/lib/spark_api/models/system_info.rb +14 -0
- data/lib/spark_api/models/system_info.rb~ +14 -0
- data/lib/spark_api/models/tour_of_home.rb +24 -0
- data/lib/spark_api/models/tour_of_home.rb~ +24 -0
- data/lib/spark_api/models/video.rb +16 -0
- data/lib/spark_api/models/video.rb~ +16 -0
- data/lib/spark_api/models/virtual_tour.rb +18 -0
- data/lib/spark_api/models/virtual_tour.rb~ +18 -0
- data/lib/spark_api/multi_client.rb +59 -0
- data/lib/spark_api/multi_client.rb~ +59 -0
- data/lib/spark_api/paginate.rb +109 -0
- data/lib/spark_api/paginate.rb~ +109 -0
- data/lib/spark_api/primary_array.rb +29 -0
- data/lib/spark_api/primary_array.rb~ +29 -0
- data/lib/spark_api/request.rb +96 -0
- data/lib/spark_api/request.rb~ +96 -0
- data/lib/spark_api/response.rb +70 -0
- data/lib/spark_api/response.rb~ +70 -0
- data/lib/spark_api/version.rb +4 -0
- data/lib/spark_api/version.rb~ +4 -0
- data/script/console +6 -0
- data/script/console~ +6 -0
- data/script/example.rb +27 -0
- data/script/example.rb~ +27 -0
- data/spec/fixtures/accounts/all.json +160 -0
- data/spec/fixtures/accounts/my.json +74 -0
- data/spec/fixtures/accounts/my_portal.json +20 -0
- data/spec/fixtures/accounts/my_put.json +5 -0
- data/spec/fixtures/accounts/my_save.json +5 -0
- data/spec/fixtures/accounts/office.json +142 -0
- data/spec/fixtures/accounts/password_save.json +6 -0
- data/spec/fixtures/authentication_failure.json +7 -0
- data/spec/fixtures/base.json +13 -0
- data/spec/fixtures/contacts/contacts.json +28 -0
- data/spec/fixtures/contacts/my.json +19 -0
- data/spec/fixtures/contacts/new.json +11 -0
- data/spec/fixtures/contacts/new_empty.json +8 -0
- data/spec/fixtures/contacts/new_notify.json +11 -0
- data/spec/fixtures/contacts/post.json +10 -0
- data/spec/fixtures/contacts/tags.json +11 -0
- data/spec/fixtures/count.json +10 -0
- data/spec/fixtures/empty.json +3 -0
- data/spec/fixtures/errors/expired.json +7 -0
- data/spec/fixtures/errors/failure.json +5 -0
- data/spec/fixtures/errors/failure_with_constraint.json +17 -0
- data/spec/fixtures/errors/failure_with_msg.json +7 -0
- data/spec/fixtures/generic_delete.json +1 -0
- data/spec/fixtures/generic_failure.json +5 -0
- data/spec/fixtures/listing_carts/add_listing.json +13 -0
- data/spec/fixtures/listing_carts/add_listing_post.json +5 -0
- data/spec/fixtures/listing_carts/empty.json +5 -0
- data/spec/fixtures/listing_carts/listing_cart.json +19 -0
- data/spec/fixtures/listing_carts/new.json +12 -0
- data/spec/fixtures/listing_carts/post.json +10 -0
- data/spec/fixtures/listing_carts/remove_listing.json +13 -0
- data/spec/fixtures/listings/constraints.json +18 -0
- data/spec/fixtures/listings/constraints_with_pagination.json +24 -0
- data/spec/fixtures/listings/document_index.json +19 -0
- data/spec/fixtures/listings/multiple.json +69 -0
- data/spec/fixtures/listings/no_subresources.json +38 -0
- data/spec/fixtures/listings/open_houses.json +21 -0
- data/spec/fixtures/listings/photos/index.json +469 -0
- data/spec/fixtures/listings/photos/new.json +12 -0
- data/spec/fixtures/listings/photos/post.json +20 -0
- data/spec/fixtures/listings/put.json +5 -0
- data/spec/fixtures/listings/put_expiration_date.json +5 -0
- data/spec/fixtures/listings/saved_search.json +17 -0
- data/spec/fixtures/listings/shared_listing_get.json +14 -0
- data/spec/fixtures/listings/shared_listing_new.json +9 -0
- data/spec/fixtures/listings/shared_listing_post.json +10 -0
- data/spec/fixtures/listings/tour_of_homes.json +23 -0
- data/spec/fixtures/listings/videos_index.json +18 -0
- data/spec/fixtures/listings/virtual_tours_index.json +42 -0
- data/spec/fixtures/listings/with_documents.json +52 -0
- data/spec/fixtures/listings/with_permissions.json +44 -0
- data/spec/fixtures/listings/with_photos.json +110 -0
- data/spec/fixtures/listings/with_supplement.json +39 -0
- data/spec/fixtures/listings/with_videos.json +54 -0
- data/spec/fixtures/listings/with_vtour.json +48 -0
- data/spec/fixtures/logo_fbs.png +0 -0
- data/spec/fixtures/messages/new.json +14 -0
- data/spec/fixtures/messages/new_empty.json +7 -0
- data/spec/fixtures/messages/new_with_recipients.json +15 -0
- data/spec/fixtures/messages/post.json +5 -0
- data/spec/fixtures/notes/add.json +11 -0
- data/spec/fixtures/notes/agent_shared.json +11 -0
- data/spec/fixtures/notes/agent_shared_empty.json +7 -0
- data/spec/fixtures/notes/new.json +5 -0
- data/spec/fixtures/notifications/mark_read.json +1 -0
- data/spec/fixtures/notifications/new.json +8 -0
- data/spec/fixtures/notifications/new_empty.json +7 -0
- data/spec/fixtures/notifications/notifications.json +43 -0
- data/spec/fixtures/notifications/post.json +10 -0
- data/spec/fixtures/notifications/unread.json +10 -0
- data/spec/fixtures/oauth2/access.json +3 -0
- data/spec/fixtures/oauth2/access_with_old_refresh.json +5 -0
- data/spec/fixtures/oauth2/access_with_refresh.json +5 -0
- data/spec/fixtures/oauth2/authorization_code_body.json +7 -0
- data/spec/fixtures/oauth2/error.json +3 -0
- data/spec/fixtures/oauth2/password_body.json +7 -0
- data/spec/fixtures/oauth2/refresh_body.json +7 -0
- data/spec/fixtures/oauth2_error.json +3 -0
- data/spec/fixtures/property_types/property_types.json +31 -0
- data/spec/fixtures/session.json +10 -0
- data/spec/fixtures/standardfields/city.json +1031 -0
- data/spec/fixtures/standardfields/nearby.json +53 -0
- data/spec/fixtures/standardfields/standardfields.json +188 -0
- data/spec/fixtures/standardfields/stateorprovince.json +36 -0
- data/spec/fixtures/success.json +5 -0
- data/spec/json_helper.rb +76 -0
- data/spec/mock_helper.rb +124 -0
- data/spec/oauth2_helper.rb +68 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/unit/flexmls_api_spec.rb~ +23 -0
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +169 -0
- data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +169 -0
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +10 -0
- data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +10 -0
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +10 -0
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +10 -0
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +205 -0
- data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +205 -0
- data/spec/unit/spark_api/authentication_spec.rb +38 -0
- data/spec/unit/spark_api/authentication_spec.rb~ +38 -0
- data/spec/unit/spark_api/configuration/yaml_spec.rb +72 -0
- data/spec/unit/spark_api/configuration/yaml_spec.rb~ +72 -0
- data/spec/unit/spark_api/configuration_spec.rb +122 -0
- data/spec/unit/spark_api/configuration_spec.rb~ +122 -0
- data/spec/unit/spark_api/faraday_spec.rb +90 -0
- data/spec/unit/spark_api/faraday_spec.rb~ +90 -0
- data/spec/unit/spark_api/models/account_spec.rb +176 -0
- data/spec/unit/spark_api/models/base_spec.rb +106 -0
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +9 -0
- data/spec/unit/spark_api/models/constraint_spec.rb +19 -0
- data/spec/unit/spark_api/models/contact_spec.rb +108 -0
- data/spec/unit/spark_api/models/contact_spec.rb~ +108 -0
- data/spec/unit/spark_api/models/document_spec.rb +32 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb +127 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb~ +127 -0
- data/spec/unit/spark_api/models/listing_spec.rb +320 -0
- data/spec/unit/spark_api/models/listing_spec.rb~ +320 -0
- data/spec/unit/spark_api/models/message_spec.rb +47 -0
- data/spec/unit/spark_api/models/message_spec.rb~ +47 -0
- data/spec/unit/spark_api/models/note_spec.rb +63 -0
- data/spec/unit/spark_api/models/note_spec.rb~ +63 -0
- data/spec/unit/spark_api/models/notification_spec.rb +62 -0
- data/spec/unit/spark_api/models/notification_spec.rb~ +62 -0
- data/spec/unit/spark_api/models/open_house_spec.rb +39 -0
- data/spec/unit/spark_api/models/photo_spec.rb +92 -0
- data/spec/unit/spark_api/models/property_types_spec.rb +33 -0
- data/spec/unit/spark_api/models/saved_search_spec.rb +40 -0
- data/spec/unit/spark_api/models/shared_listing_spec.rb +45 -0
- data/spec/unit/spark_api/models/shared_listing_spec.rb~ +45 -0
- data/spec/unit/spark_api/models/standard_fields_spec.rb +60 -0
- data/spec/unit/spark_api/models/system_info_spec.rb +83 -0
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +44 -0
- data/spec/unit/spark_api/models/video_spec.rb +36 -0
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +44 -0
- data/spec/unit/spark_api/multi_client_spec.rb +56 -0
- data/spec/unit/spark_api/multi_client_spec.rb~ +56 -0
- data/spec/unit/spark_api/paginate_spec.rb +224 -0
- data/spec/unit/spark_api/paginate_spec.rb~ +224 -0
- data/spec/unit/spark_api/primary_array_spec.rb +41 -0
- data/spec/unit/spark_api/primary_array_spec.rb~ +41 -0
- data/spec/unit/spark_api/request_spec.rb +344 -0
- data/spec/unit/spark_api/request_spec.rb~ +344 -0
- data/spec/unit/spark_api_spec.rb +23 -0
- metadata +725 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Message do
|
5
|
+
before(:each) do
|
6
|
+
stub_auth_request
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
m = Message.new
|
11
|
+
m.attributes["Type"] = "ShowingRequest"
|
12
|
+
m.attributes["EventDateTime"] = "2011-09-15T14:00:00"
|
13
|
+
m.attributes["SenderId"] = "20110112234857732941000000"
|
14
|
+
m.attributes["Subject"] = "Showing Request For 123 Main St, MLS # 12-345"
|
15
|
+
m.attributes["Body"] = "A showing is requested for ..."
|
16
|
+
m.attributes["ListingId"] = "20110112234857732941000000"
|
17
|
+
m
|
18
|
+
end
|
19
|
+
|
20
|
+
context "/messages", :support do
|
21
|
+
on_get_it "should get all my messages"
|
22
|
+
|
23
|
+
on_post_it "should save a new message" do
|
24
|
+
stub_api_post("/messages", 'messages/new.json', 'messages/post.json')
|
25
|
+
subject.save.should be(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
on_post_it "should save a new message with recipients" do
|
29
|
+
stub_api_post("/messages", 'messages/new_with_recipients.json', 'messages/post.json')
|
30
|
+
subject.attributes["Recipients"] = ["20110112234857732941000000","20110092234857738467000000"]
|
31
|
+
subject.save.should be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
on_post_it "should fail saving" do
|
35
|
+
stub_api_post("/messages", 'messages/new_empty.json') do |request|
|
36
|
+
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
37
|
+
end
|
38
|
+
m=subject.class.new
|
39
|
+
m.save.should be(false)
|
40
|
+
expect{ m.save! }.to raise_error(SparkApi::ClientError){ |e| e.status.should == 400 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "/messages/<message_id>", :support do
|
45
|
+
on_get_it "should get a single message"
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Message do
|
5
|
+
before(:each) do
|
6
|
+
stub_auth_request
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
m = Message.new
|
11
|
+
m.attributes["Type"] = "ShowingRequest"
|
12
|
+
m.attributes["EventDateTime"] = "2011-09-15T14:00:00"
|
13
|
+
m.attributes["SenderId"] = "20110112234857732941000000"
|
14
|
+
m.attributes["Subject"] = "Showing Request For 123 Main St, MLS # 12-345"
|
15
|
+
m.attributes["Body"] = "A showing is requested for ..."
|
16
|
+
m.attributes["ListingId"] = "20110112234857732941000000"
|
17
|
+
m
|
18
|
+
end
|
19
|
+
|
20
|
+
context "/messages", :support do
|
21
|
+
on_get_it "should get all my messages"
|
22
|
+
|
23
|
+
on_post_it "should save a new message" do
|
24
|
+
stub_api_post("/messages", 'messages/new.json', 'messages/post.json')
|
25
|
+
subject.save.should be(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
on_post_it "should save a new message with recipients" do
|
29
|
+
stub_api_post("/messages", 'messages/new_with_recipients.json', 'messages/post.json')
|
30
|
+
subject.attributes["Recipients"] = ["20110112234857732941000000","20110092234857738467000000"]
|
31
|
+
subject.save.should be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
on_post_it "should fail saving" do
|
35
|
+
stub_api_post("/messages", 'messages/new_empty.json') do |request|
|
36
|
+
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
37
|
+
end
|
38
|
+
m=subject.class.new
|
39
|
+
m.save.should be(false)
|
40
|
+
expect{ m.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "/messages/<message_id>", :support do
|
45
|
+
on_get_it "should get a single message"
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Note do
|
4
|
+
|
5
|
+
it "responds to instance and class methods" do
|
6
|
+
Note.should respond_to(:get)
|
7
|
+
Note.new.should respond_to(:save)
|
8
|
+
Note.new.should respond_to(:save!)
|
9
|
+
Note.new.should respond_to(:delete)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when shared with a contact" do
|
13
|
+
before :each do
|
14
|
+
@note = Listing.new(:ListingKey => "1234").shared_notes("5678")
|
15
|
+
stub_auth_request
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have the correct path" do
|
19
|
+
@note.path.should == "/listings/1234/shared/notes/contacts/5678"
|
20
|
+
end
|
21
|
+
|
22
|
+
context "/listings/<listing_id>/shared/notes/contacts/<contact_id>", :support do
|
23
|
+
on_get_it "GET should get my notes" do
|
24
|
+
stub_api_get("#{@note.path}", 'notes/agent_shared.json')
|
25
|
+
ret = @note.get
|
26
|
+
ret.Note.should == "lorem ipsum dolor sit amet"
|
27
|
+
end
|
28
|
+
|
29
|
+
on_get_it "should return a nil when no shared notes exist" do
|
30
|
+
stub_api_get("#{@note.path}", 'notes/agent_shared_empty.json')
|
31
|
+
@note.get.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
on_delete_it "should allow you to delete an existing note" do
|
35
|
+
stub_api_delete("#{@note.path}", 'generic_delete.json')
|
36
|
+
@note.new.delete # test that no exceptions are raised
|
37
|
+
end
|
38
|
+
|
39
|
+
on_put_it "should raise an exception when adding a note fails" do
|
40
|
+
n = @note.new(:Note => "lorem ipsum dolor")
|
41
|
+
|
42
|
+
stub_api_put("#{@note.path}", 'notes/new.json') do |request|
|
43
|
+
request.to_return(:status => 500, :body => fixture('generic_failure.json'))
|
44
|
+
end
|
45
|
+
|
46
|
+
expect { n.save! }.to raise_error(SparkApi::ClientError) { |e| e.status.should == 500 }
|
47
|
+
expect { n.save }.to raise_error(SparkApi::ClientError) { |e| e.status.should == 500 }
|
48
|
+
end
|
49
|
+
|
50
|
+
on_put_it "should allow adding of a note" do
|
51
|
+
n = @note.new(:Note => "lorem ipsum dolor")
|
52
|
+
stub_api_put("#{@note.path}", 'notes/new.json', 'notes/add.json')
|
53
|
+
n.save
|
54
|
+
n.ResourceUri.should == '/v1/listings/20100909200152674436000000/shared/notes/contacts/20110407212043616271000000/'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
after :each do
|
60
|
+
@note = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Note do
|
4
|
+
|
5
|
+
it "responds to instance and class methods" do
|
6
|
+
Note.should respond_to(:get)
|
7
|
+
Note.new.should respond_to(:save)
|
8
|
+
Note.new.should respond_to(:save!)
|
9
|
+
Note.new.should respond_to(:delete)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when shared with a contact" do
|
13
|
+
before :each do
|
14
|
+
@note = Listing.new(:ListingKey => "1234").shared_notes("5678")
|
15
|
+
stub_auth_request
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have the correct path" do
|
19
|
+
@note.path.should == "/listings/1234/shared/notes/contacts/5678"
|
20
|
+
end
|
21
|
+
|
22
|
+
context "/listings/<listing_id>/shared/notes/contacts/<contact_id>", :support do
|
23
|
+
on_get_it "GET should get my notes" do
|
24
|
+
stub_api_get("#{@note.path}", 'notes/agent_shared.json')
|
25
|
+
ret = @note.get
|
26
|
+
ret.Note.should == "lorem ipsum dolor sit amet"
|
27
|
+
end
|
28
|
+
|
29
|
+
on_get_it "should return a nil when no shared notes exist" do
|
30
|
+
stub_api_get("#{@note.path}", 'notes/agent_shared_empty.json')
|
31
|
+
@note.get.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
on_delete_it "should allow you to delete an existing note" do
|
35
|
+
stub_api_delete("#{@note.path}", 'generic_delete.json')
|
36
|
+
@note.new.delete # test that no exceptions are raised
|
37
|
+
end
|
38
|
+
|
39
|
+
on_put_it "should raise an exception when adding a note fails" do
|
40
|
+
n = @note.new(:Note => "lorem ipsum dolor")
|
41
|
+
|
42
|
+
stub_api_put("#{@note.path}", 'notes/new.json') do |request|
|
43
|
+
request.to_return(:status => 500, :body => fixture('generic_failure.json'))
|
44
|
+
end
|
45
|
+
|
46
|
+
expect { n.save! }.to raise_error(FlexmlsApi::ClientError) { |e| e.status.should == 500 }
|
47
|
+
expect { n.save }.to raise_error(FlexmlsApi::ClientError) { |e| e.status.should == 500 }
|
48
|
+
end
|
49
|
+
|
50
|
+
on_put_it "should allow adding of a note" do
|
51
|
+
n = @note.new(:Note => "lorem ipsum dolor")
|
52
|
+
stub_api_put("#{@note.path}", 'notes/new.json', 'notes/add.json')
|
53
|
+
n.save
|
54
|
+
n.ResourceUri.should == '/v1/listings/20100909200152674436000000/shared/notes/contacts/20110407212043616271000000/'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
after :each do
|
60
|
+
@note = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Notification do
|
4
|
+
before(:each) do
|
5
|
+
stub_auth_request
|
6
|
+
end
|
7
|
+
|
8
|
+
subject do
|
9
|
+
m = Notification.new
|
10
|
+
m.attributes['Type'] = 'OperationComplete'
|
11
|
+
m.attributes['Message'] = 'Your PDF generation has completed!'
|
12
|
+
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
13
|
+
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
14
|
+
m
|
15
|
+
end
|
16
|
+
|
17
|
+
context "/notifications", :support do
|
18
|
+
on_get_it "should get my notifications" do
|
19
|
+
stub_api_get('/notifications', 'notifications/notifications.json')
|
20
|
+
|
21
|
+
notifications = Notification.get
|
22
|
+
notifications.should be_an(Array)
|
23
|
+
notifications.count.should equal(3)
|
24
|
+
end
|
25
|
+
|
26
|
+
on_post_it "should create a new notification" do
|
27
|
+
stub_api_post("/notifications", 'notifications/new.json', 'notifications/post.json')
|
28
|
+
subject.save.should be(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
on_post_it "should fail saving" do
|
32
|
+
stub_api_post("/notifications", 'notifications/new_empty.json') do |request|
|
33
|
+
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
34
|
+
end
|
35
|
+
m = subject.class.new
|
36
|
+
m.attributes['Message'] = 'Your PDF generation has completed!'
|
37
|
+
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
38
|
+
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
39
|
+
m.save.should be(false)
|
40
|
+
expect{ m.save! }.to raise_error(SparkApi::ClientError){ |e| e.status.should == 400 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "/notifications/<notification_id1>,<notification_id2>,...<notification_idN>", :support do
|
45
|
+
on_put_it "should mark notifications as read" do
|
46
|
+
to_mark = [12345678901234567890000001,12345678901234567890000002]
|
47
|
+
stub_api_put("/notifications/#{to_mark.join(',')}",
|
48
|
+
'notifications/mark_read.json', 'success.json')
|
49
|
+
|
50
|
+
Notification.mark_read(to_mark)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "/notifications/unread", :support do
|
55
|
+
on_get_it "should get a count of unread notifications" do
|
56
|
+
stub_api_get('/notifications/unread', 'notifications/unread.json', {:_pagination => 'count'})
|
57
|
+
|
58
|
+
notification_count = Notification.unread
|
59
|
+
notification_count.should equal(30)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Notification do
|
4
|
+
before(:each) do
|
5
|
+
stub_auth_request
|
6
|
+
end
|
7
|
+
|
8
|
+
subject do
|
9
|
+
m = Notification.new
|
10
|
+
m.attributes['Type'] = 'OperationComplete'
|
11
|
+
m.attributes['Message'] = 'Your PDF generation has completed!'
|
12
|
+
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
13
|
+
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
14
|
+
m
|
15
|
+
end
|
16
|
+
|
17
|
+
context "/notifications", :support do
|
18
|
+
on_get_it "should get my notifications" do
|
19
|
+
stub_api_get('/notifications', 'notifications/notifications.json')
|
20
|
+
|
21
|
+
notifications = Notification.get
|
22
|
+
notifications.should be_an(Array)
|
23
|
+
notifications.count.should equal(3)
|
24
|
+
end
|
25
|
+
|
26
|
+
on_post_it "should create a new notification" do
|
27
|
+
stub_api_post("/notifications", 'notifications/new.json', 'notifications/post.json')
|
28
|
+
subject.save.should be(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
on_post_it "should fail saving" do
|
32
|
+
stub_api_post("/notifications", 'notifications/new_empty.json') do |request|
|
33
|
+
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
34
|
+
end
|
35
|
+
m = subject.class.new
|
36
|
+
m.attributes['Message'] = 'Your PDF generation has completed!'
|
37
|
+
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
38
|
+
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
39
|
+
m.save.should be(false)
|
40
|
+
expect{ m.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "/notifications/<notification_id1>,<notification_id2>,...<notification_idN>", :support do
|
45
|
+
on_put_it "should mark notifications as read" do
|
46
|
+
to_mark = [12345678901234567890000001,12345678901234567890000002]
|
47
|
+
stub_api_put("/notifications/#{to_mark.join(',')}",
|
48
|
+
'notifications/mark_read.json', 'success.json')
|
49
|
+
|
50
|
+
Notification.mark_read(to_mark)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "/notifications/unread", :support do
|
55
|
+
on_get_it "should get a count of unread notifications" do
|
56
|
+
stub_api_get('/notifications/unread', 'notifications/unread.json', {:_pagination => 'count'})
|
57
|
+
|
58
|
+
notification_count = Notification.unread
|
59
|
+
notification_count.should equal(30)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
describe OpenHouse do
|
6
|
+
subject do
|
7
|
+
OpenHouse.new(
|
8
|
+
'ResourceUri'=>"/v1/listings/20060412165917817933000000/openhouses/20101127153422574618000000",
|
9
|
+
'Id'=>"20060412165917817933000000",
|
10
|
+
'Date'=>"10/01/2010",
|
11
|
+
'StartTime'=>"09:00:00-07:00",
|
12
|
+
'EndTime'=>"12:00:00-07:00"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should respond to a few methods" do
|
17
|
+
subject.class.should respond_to(:find_by_listing_key)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return date and times" do
|
21
|
+
start_time = DateTime.new(2010,10,1,9,0,0, "-0700")
|
22
|
+
end_time = DateTime.new(2010,10,1,12,0,0, "-0700")
|
23
|
+
subject.Date.should eq(Date.new(2010,10,1))
|
24
|
+
subject.StartTime.should eq(Time.parse(start_time.to_s))
|
25
|
+
subject.EndTime.should eq(Time.parse(end_time.to_s))
|
26
|
+
end
|
27
|
+
|
28
|
+
context "/listings/<listing_id>/openhouses", :support do
|
29
|
+
on_get_it "should get open house for a listing" do
|
30
|
+
stub_auth_request
|
31
|
+
stub_api_get('/listings/20060412165917817933000000/openhouses','listings/open_houses.json')
|
32
|
+
houses = subject.class.find_by_listing_key('20060412165917817933000000')
|
33
|
+
houses.should be_an(Array)
|
34
|
+
houses.length.should eq(2)
|
35
|
+
houses.first.Id.should eq("20101127153422574618000000")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Photo do
|
4
|
+
describe "find" do
|
5
|
+
subject do
|
6
|
+
Photo.new({
|
7
|
+
"ResourceUri" => "/listings/20100815153524571646000000/photos/20101124153422574618000000",
|
8
|
+
"Id" => "20101124153422574618000000",
|
9
|
+
"Name" => "Photo 1 name",
|
10
|
+
"Caption" => "caption here",
|
11
|
+
"UriThumb" => "http://photos.cdn.flexmls.com/xyz-t.jpg",
|
12
|
+
"Uri300" => "http://photos.cdn.flexmls.com/xyz.jpg",
|
13
|
+
"Uri640" => "http://cdn.resize.flexmls.com/az/640x480/true/20101124153422574618000000-o.jpg",
|
14
|
+
"Uri800" => "http://cdn.resize.flexmls.com/az/800x600/true/20101124153422574618000000-o.jpg",
|
15
|
+
"Uri1024" => "http://cdn.resize.flexmls.com/az/1024x768/true/20101124153422574618000000-o.jpg",
|
16
|
+
"Uri1280" => "http://cdn.resize.flexmls.com/az/1280x1024/true/20101124153422574618000000-o.jpg",
|
17
|
+
"UriLarge" => "http://photos.cdn.flexmls.com/xyz-o.jpg",
|
18
|
+
"Primary" => true
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "responds to" do
|
23
|
+
subject.should respond_to(:primary?)
|
24
|
+
Photo.should respond_to(:find_by_listing_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "knows if it's the primary photo" do
|
28
|
+
subject.primary?.should be_true
|
29
|
+
subject.Primary = false
|
30
|
+
subject.primary?.should be_false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "URIs" do
|
35
|
+
subject do
|
36
|
+
p = Photo.build_subclass.tap do |photo|
|
37
|
+
photo.prefix = "/listings/1234"
|
38
|
+
photo.element_name ="/photos"
|
39
|
+
end.new
|
40
|
+
p.update_path = "/listings/1234/photos"
|
41
|
+
p
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be scoped to a listing" do
|
45
|
+
subject.class.path.should eq("/listings/1234/photos")
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "/listings/<listing_id>/photos", :support do
|
49
|
+
before(:each) do
|
50
|
+
stub_auth_request
|
51
|
+
stub_api_get('/listings/1234/photos', 'listings/photos/index.json')
|
52
|
+
end
|
53
|
+
|
54
|
+
on_get_it "should get an array of photos" do
|
55
|
+
p = Photo.find_by_listing_key('1234')
|
56
|
+
p.should be_an(Array)
|
57
|
+
end
|
58
|
+
|
59
|
+
on_post_it "should upload a new photo" do
|
60
|
+
stub_api_post('/listings/1234/photos', 'listings/photos/new.json', 'listings/photos/post.json')
|
61
|
+
subject.Name = "FBS Logo"
|
62
|
+
subject.Caption = "Creators of flexMLS!"
|
63
|
+
subject.load_picture("spec/fixtures/logo_fbs.png")
|
64
|
+
subject.save!
|
65
|
+
subject.Id.should eq("20110826220032167405000000")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "/listings/<listing_id>/photos/<photo_id>", :support do
|
70
|
+
before(:each) do
|
71
|
+
stub_auth_request
|
72
|
+
end
|
73
|
+
|
74
|
+
on_put_it "should upload a modified photo" do
|
75
|
+
stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/new.json', 'listings/photos/post.json')
|
76
|
+
subject.Id = "20110826220032167405000000"
|
77
|
+
subject.Name = "FBS Logo"
|
78
|
+
subject.Caption = "Creators of flexMLS!"
|
79
|
+
subject.load_picture("spec/fixtures/logo_fbs.png")
|
80
|
+
subject.save!
|
81
|
+
subject.Id.should eq("20110826220032167405000000")
|
82
|
+
end
|
83
|
+
|
84
|
+
on_delete_it "should delete a photo" do
|
85
|
+
stub_api_delete('/listings/1234/photos/20110826220032167405000000','success.json')
|
86
|
+
subject.Id = "20110826220032167405000000"
|
87
|
+
subject.delete
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|