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,19 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Constraint do
|
5
|
+
|
6
|
+
subject do
|
7
|
+
Constraint.new(
|
8
|
+
"RuleValue" => 1000000.0,
|
9
|
+
"Value" => 1000001.0,
|
10
|
+
"RuleFieldValue" => 1.0,
|
11
|
+
"RuleField" => "ListPrice",
|
12
|
+
"RuleName" => "MaxValue")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should print to string" do
|
16
|
+
subject.to_s.should eq("MaxValue: Field(ListPrice,1.0) Value(1000000.0,1000001.0)")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,108 @@
|
|
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(SparkApi::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(SparkApi::ClientError){ |e| e.status.should == 500 }
|
72
|
+
expect{ c.save }.to raise_error(SparkApi::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
|
@@ -0,0 +1,108 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Document do
|
4
|
+
before(:each) do
|
5
|
+
@document = Document.new({
|
6
|
+
:Uri => "http://images.dev.fbsdata.com/documents/cda/20060725224801143085000000.pdf",
|
7
|
+
:ResourceUri => "/v1/listings/20060725224713296297000000/documents/20060725224801143085000000",
|
8
|
+
:Name => "Disclosure",
|
9
|
+
:Id => "20110105165843978012000000",
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond to a few methods" do
|
14
|
+
Document.should respond_to(:find_by_listing_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "/listings/<listing_id>/documents" do
|
18
|
+
on_get_it "should get documents for a listing" do
|
19
|
+
stub_auth_request
|
20
|
+
stub_api_get('/listings/1234/documents','listings/document_index.json')
|
21
|
+
|
22
|
+
v = Document.find_by_listing_key('1234')
|
23
|
+
v.should be_an(Array)
|
24
|
+
v.length.should == 2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
@document = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,127 @@
|
|
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(SparkApi::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
|
@@ -0,0 +1,127 @@
|
|
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
|