flexmls_api 0.4.5 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/Gemfile +2 -17
  2. data/Gemfile.lock +35 -27
  3. data/README.md +23 -1
  4. data/Rakefile +18 -5
  5. data/VERSION +1 -1
  6. data/bin/flexmls_api +8 -0
  7. data/lib/flexmls_api.rb +2 -0
  8. data/lib/flexmls_api/authentication.rb +5 -6
  9. data/lib/flexmls_api/authentication/api_auth.rb +4 -2
  10. data/lib/flexmls_api/authentication/oauth2.rb +51 -99
  11. data/lib/flexmls_api/authentication/oauth2_impl/grant_type_base.rb +85 -0
  12. data/lib/flexmls_api/authentication/oauth2_impl/grant_type_code.rb +48 -0
  13. data/lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb +45 -0
  14. data/lib/flexmls_api/authentication/oauth2_impl/grant_type_refresh.rb +36 -0
  15. data/lib/flexmls_api/authentication/oauth2_impl/middleware.rb +39 -0
  16. data/lib/flexmls_api/cli.rb +132 -0
  17. data/lib/flexmls_api/cli/api_auth.rb +8 -0
  18. data/lib/flexmls_api/cli/oauth2.rb +43 -0
  19. data/lib/flexmls_api/cli/setup.rb +44 -0
  20. data/lib/flexmls_api/configuration.rb +6 -6
  21. data/lib/flexmls_api/faraday.rb +11 -21
  22. data/lib/flexmls_api/models.rb +3 -0
  23. data/lib/flexmls_api/models/account.rb +48 -5
  24. data/lib/flexmls_api/models/base.rb +27 -2
  25. data/lib/flexmls_api/models/contact.rb +28 -9
  26. data/lib/flexmls_api/models/listing_cart.rb +72 -0
  27. data/lib/flexmls_api/models/note.rb +0 -2
  28. data/lib/flexmls_api/models/saved_search.rb +16 -0
  29. data/lib/flexmls_api/models/shared_listing.rb +35 -0
  30. data/lib/flexmls_api/multi_client.rb +37 -0
  31. data/lib/flexmls_api/paginate.rb +5 -0
  32. data/lib/flexmls_api/request.rb +7 -3
  33. data/script/console +6 -0
  34. data/script/example.rb +27 -0
  35. data/spec/fixtures/accounts/all.json +160 -0
  36. data/spec/fixtures/accounts/my.json +74 -0
  37. data/spec/fixtures/accounts/my_portal.json +20 -0
  38. data/spec/fixtures/accounts/my_put.json +5 -0
  39. data/spec/fixtures/accounts/my_save.json +5 -0
  40. data/spec/fixtures/accounts/office.json +142 -0
  41. data/spec/fixtures/base.json +13 -0
  42. data/spec/fixtures/contact_my.json +19 -0
  43. data/spec/fixtures/contact_new.json +11 -0
  44. data/spec/fixtures/contact_new_empty.json +8 -0
  45. data/spec/fixtures/contact_new_notify.json +11 -0
  46. data/spec/fixtures/contact_tags.json +11 -0
  47. data/spec/fixtures/contacts.json +6 -3
  48. data/spec/fixtures/contacts_post.json +10 -0
  49. data/spec/fixtures/empty.json +3 -0
  50. data/spec/fixtures/errors/failure.json +5 -0
  51. data/spec/fixtures/listing_cart.json +19 -0
  52. data/spec/fixtures/listing_cart_add_listing.json +13 -0
  53. data/spec/fixtures/listing_cart_add_listing_post.json +5 -0
  54. data/spec/fixtures/listing_cart_empty.json +5 -0
  55. data/spec/fixtures/listing_cart_new.json +12 -0
  56. data/spec/fixtures/listing_cart_post.json +10 -0
  57. data/spec/fixtures/listing_cart_remove_listing.json +13 -0
  58. data/spec/fixtures/note_new.json +5 -0
  59. data/spec/fixtures/{oauth2_access.json → oauth2/access.json} +0 -0
  60. data/spec/fixtures/oauth2/access_with_old_refresh.json +5 -0
  61. data/spec/fixtures/oauth2/access_with_refresh.json +5 -0
  62. data/spec/fixtures/oauth2/authorization_code_body.json +7 -0
  63. data/spec/fixtures/oauth2/error.json +3 -0
  64. data/spec/fixtures/oauth2/password_body.json +7 -0
  65. data/spec/fixtures/oauth2/refresh_body.json +7 -0
  66. data/spec/fixtures/saved_search.json +17 -0
  67. data/spec/fixtures/shared_listing_new.json +9 -0
  68. data/spec/fixtures/shared_listing_post.json +10 -0
  69. data/spec/mock_helper.rb +123 -0
  70. data/spec/oauth2_helper.rb +69 -0
  71. data/spec/spec_helper.rb +1 -57
  72. data/spec/unit/flexmls_api/authentication/api_auth_spec.rb +1 -0
  73. data/spec/unit/flexmls_api/authentication/oauth2_impl/grant_type_base_spec.rb +10 -0
  74. data/spec/unit/flexmls_api/authentication/oauth2_spec.rb +74 -79
  75. data/spec/unit/flexmls_api/configuration_spec.rb +25 -4
  76. data/spec/unit/flexmls_api/models/account_spec.rb +152 -85
  77. data/spec/unit/flexmls_api/models/base_spec.rb +69 -25
  78. data/spec/unit/flexmls_api/models/contact_spec.rb +48 -34
  79. data/spec/unit/flexmls_api/models/document_spec.rb +1 -7
  80. data/spec/unit/flexmls_api/models/listing_cart_spec.rb +114 -0
  81. data/spec/unit/flexmls_api/models/listing_spec.rb +8 -56
  82. data/spec/unit/flexmls_api/models/note_spec.rb +8 -38
  83. data/spec/unit/flexmls_api/models/photo_spec.rb +1 -11
  84. data/spec/unit/flexmls_api/models/saved_search_spec.rb +34 -0
  85. data/spec/unit/flexmls_api/models/shared_listing_spec.rb +30 -0
  86. data/spec/unit/flexmls_api/models/standard_fields_spec.rb +50 -30
  87. data/spec/unit/flexmls_api/models/tour_of_home_spec.rb +1 -7
  88. data/spec/unit/flexmls_api/models/video_spec.rb +1 -10
  89. data/spec/unit/flexmls_api/models/virtual_tour_spec.rb +1 -7
  90. data/spec/unit/flexmls_api/multi_client_spec.rb +48 -0
  91. data/spec/unit/flexmls_api/request_spec.rb +42 -5
  92. metadata +239 -93
  93. data/spec/unit/flexmls_api/standard_fields_spec.rb +0 -86
@@ -4,12 +4,6 @@ require './spec/spec_helper'
4
4
  class MyExampleModel < Base
5
5
  self.element_name = "example"
6
6
  self.prefix = "/test/"
7
- def self.connection
8
- @connection ||= Base.connection
9
- end
10
- def self.connection=(con)
11
- @connection = con
12
- end
13
7
  end
14
8
 
15
9
  class MyDefaultModel < Base
@@ -31,24 +25,9 @@ describe Base, "Base model" do
31
25
  MyDefaultModel.path.should eq("/resource")
32
26
  end
33
27
  describe "finders" do
34
- before(:all) do
35
- stubs = Faraday::Adapter::Test::Stubs.new do |stub|
36
- stub.get('/v1/test/example?ApiSig=9fd7299fc210d0c3dcc24782d9cb7894&ApiUser=foobar&AuthToken=1234') { [200, {}, '{"D": {
37
- "Success": true,
38
- "Results": [{
39
- "Id": 1,
40
- "Name": "My Example",
41
- "Test": true
42
- },
43
- {
44
- "Id": 2,
45
- "Name": "My Example2",
46
- "Test": false
47
- }]}
48
- }']
49
- }
50
- end
51
- MyExampleModel.connection = mock_client(stubs)
28
+ before(:each) do
29
+ stub_auth_request
30
+ stub_api_get("/test/example", 'base.json')
52
31
  end
53
32
  it "should get all results" do
54
33
  MyExampleModel.get.length.should == 2
@@ -58,5 +37,70 @@ describe Base, "Base model" do
58
37
  end
59
38
  end
60
39
  end
61
-
40
+
41
+ describe "attribute accessors, setters, and predicates" do
42
+ before(:each) do
43
+ stub_auth_request
44
+ stub_api_get("/test/example", 'base.json')
45
+ @model = MyExampleModel.first
46
+ end
47
+
48
+ it "should access existing attributes" do
49
+ @model.Name.should == 'My Example'
50
+ end
51
+
52
+ it "should raise errors on access to non-existant attributes" do
53
+ lambda { @model.Nonsense }.should raise_error(NoMethodError)
54
+ end
55
+
56
+ it "should set existing attributes" do
57
+ new_name = 'John Jacob Jingleheimerschmidt'
58
+ @model.Name = new_name
59
+ @model.Name.should == new_name
60
+ end
61
+
62
+ it "should set non-existant attributes" do
63
+ nonsense = 'nonsense'
64
+ @model.Nonsense = nonsense
65
+ @model.Nonsense.should == nonsense
66
+ end
67
+
68
+ it "should return a boolean for a predicate for an existing attribute" do
69
+ @model.Name?.should satisfy { |p| [true, false].include?(p) }
70
+ end
71
+
72
+ it "should raise an Error for a predicate for a non-existant attribute" do
73
+ lambda { @model.Nonsense? }.should raise_error(NoMethodError)
74
+ end
75
+
76
+ it "should repond_to existing attributes" do
77
+ @model.should respond_to(:Name)
78
+ end
79
+
80
+ it "should not respond_to non-existant attributes" do
81
+ @model.should_not respond_to(:Nonsense)
82
+ end
83
+
84
+ it "should respond_to a setter for an existing attribute" do
85
+ @model.should respond_to(:Name=)
86
+ end
87
+
88
+ it "should respond_to a setter for a non-existant attribute" do
89
+ @model.should respond_to(:Nonsense=)
90
+ end
91
+
92
+ it "should respond_to a predicate for an existing attribute" do
93
+ @model.should respond_to(:Name?)
94
+ end
95
+
96
+ it "should not respond_to a predicate for a non-existant attribute" do
97
+ @model.should_not respond_to(:Nonsense?)
98
+ end
99
+
100
+ it "should respond_to methods inherited from parent classes" do
101
+ @model.should respond_to(:freeze)
102
+ end
103
+
104
+ end
105
+
62
106
  end
@@ -1,46 +1,51 @@
1
1
  require './spec/spec_helper'
2
2
 
3
3
 
4
- class Contact
5
- class << self
6
- # Neato trick, using the accessor function nested here acts on the class methods!
7
- attr_accessor :connection
8
- end
9
- end
10
-
11
4
  describe Contact do
12
- before(:all) do
13
- stubs = Faraday::Adapter::Test::Stubs.new do |stub|
14
- stub.get('/v1/contacts?ApiSig=33e3b6d6436c85c3f9944d21f6f0cf9a&ApiUser=foobar&AuthToken=1234') { [200, {}, fixture('contacts.json')]
15
- }
16
- stub.post('/v1/contacts?ApiSig=1c78fb9f798fbb739a0b8152528cd453&ApiUser=foobar&AuthToken=1234', '{"D":{"Contacts":[{"DisplayName":"Contact Four","PrimaryEmail":"contact4@fbsdata.com"}]}}') { [201, {}, '{"D": {
17
- "Success": true,
18
- "Results": [
19
- {
20
- "ResourceUri":"/v1/contacts/20101230223226074204000000"
21
- }]}
22
- }']
23
- }
24
- stub.post('/v1/contacts?ApiSig=ea132fe27a8deb7d6c096b102972ce3e&ApiUser=foobar&AuthToken=1234', '{"D":{"Contacts":[{}]}}') { [400, {}, '{"D": {
25
- "Success": false}
26
- }']
27
- }
28
- end
29
- Contact.connection = mock_client(stubs)
5
+ before(:each) do
6
+ stub_auth_request
30
7
  end
31
8
 
32
9
  it "should include the finders module" do
33
10
  Contact.should respond_to(:find)
11
+ Contact.should respond_to(:my)
34
12
  end
35
13
 
36
14
  it "should get all my contacts" do
15
+ stub_api_get("/contacts", 'contacts.json')
37
16
  contacts = Contact.get
38
17
  contacts.should be_an(Array)
39
18
  contacts.length.should eq(3)
40
19
  contacts.first.Id.should eq("20101230223226074201000000")
41
20
  end
42
21
 
22
+ it "should get a single contact when using #my" do
23
+ stub_api_get("/my/contact", 'contact_my.json')
24
+ contact = Contact.my
25
+ contact.should be_a(Contact)
26
+ contact.Id.should == '20090928182824338901000000'
27
+ contact.DisplayName.should == 'BH FOO'
28
+ end
29
+
30
+ it "should get all my Tags" do
31
+ stub_api_get("/contacts/tags", 'contact_tags.json')
32
+ tags = Contact.tags
33
+ tags.should be_an(Array)
34
+ tags.length.should eq(4)
35
+ tags.first["Tag"].should eq("Current Buyers")
36
+ end
37
+
38
+ it "should get all my Tags" do
39
+ stub_api_get("/contacts/tags/IDX%20Lead", 'contacts.json')
40
+ contacts = Contact.by_tag("IDX Lead")
41
+ contacts.should be_an(Array)
42
+ contacts.length.should eq(3)
43
+ contacts.first.Id.should eq("20101230223226074201000000")
44
+ contacts.first.Tags[0].should eq("IDX Lead")
45
+ end
46
+
43
47
  it "should save a new contact" do
48
+ stub_api_post("/contacts", 'contact_new.json', 'contacts_post.json')
44
49
  c=Contact.new
45
50
  c.attributes["DisplayName"] = "Contact Four"
46
51
  c.attributes["PrimaryEmail"] = "contact4@fbsdata.com"
@@ -48,23 +53,32 @@ describe Contact do
48
53
  c.Id.should eq('20101230223226074204000000')
49
54
  end
50
55
 
56
+ it "should save a new contact and notify" do
57
+ stub_api_post("/contacts", 'contact_new_notify.json', 'contacts_post.json')
58
+ c=Contact.new
59
+ c.notify=true
60
+ c.attributes["DisplayName"] = "Contact Four"
61
+ c.attributes["PrimaryEmail"] = "contact4@fbsdata.com"
62
+ c.save.should be(true)
63
+ c.Id.should eq('20101230223226074204000000')
64
+ end
65
+
51
66
  it "should fail saving" do
67
+ stub_api_post("/contacts", 'contact_new_empty.json') do |request|
68
+ request.to_return(:status => 400, :body => fixture('errors/failure.json'))
69
+ end
70
+
52
71
  c=Contact.new
53
72
  c.save.should be(false)
54
73
  expect{ c.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
55
74
  end
56
75
 
57
76
  context "on an epic fail" do
58
- before(:all) do
59
- stubs = Faraday::Adapter::Test::Stubs.new do |stub|
60
- stub.post('/v1/contacts?ApiSig=ea132fe27a8deb7d6c096b102972ce3e&ApiUser=foobar&AuthToken=1234', '{"D":{"Contacts":[{}]}}') { [500, {}, '{"D": {
61
- "Success": false}
62
- }']
63
- }
64
- end
65
- Contact.connection = mock_client(stubs)
66
- end
67
77
  it "should fail saving and asplode" do
78
+ stub_api_post("/contacts", 'contact_new_empty.json') do |request|
79
+ request.to_return(:status => 500, :body => fixture('errors/failure.json'))
80
+ end
81
+
68
82
  c=Contact.new()
69
83
  expect{ c.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 500 }
70
84
  expect{ c.save }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 500 }
@@ -16,13 +16,7 @@ describe Document do
16
16
 
17
17
  it "should get documents for a listing" do
18
18
  stub_auth_request
19
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234/documents").
20
- with( :query => {
21
- :ApiSig => "82f62b685e4318a1ab6bc3fc5a031c5a",
22
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
23
- :ApiUser => "foobar"
24
- }).
25
- to_return(:body => fixture('listing_document_index.json'))
19
+ stub_api_get('/listings/1234/documents','listing_document_index.json')
26
20
 
27
21
  v = Document.find_by_listing_key('1234')
28
22
  v.should be_an(Array)
@@ -0,0 +1,114 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe ListingCart do
4
+
5
+ it "should get all listing carts" do
6
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
7
+ resources = subject.class.get
8
+ resources.should be_an(Array)
9
+ resources.length.should eq(2)
10
+ resources.first.Id.should eq("20100912153422758914000000")
11
+ end
12
+
13
+ it "should get a listing cart" do
14
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
15
+ resource = subject.class.get.first
16
+ resource.Id.should eq("20100912153422758914000000")
17
+ resource.Name.should eq("My Listing Cart")
18
+ resource.ListingCount.should eq(10)
19
+ end
20
+
21
+ it "should add a listing to a cart" do
22
+ list_id = "20110621133454434543000000"
23
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
24
+ resource = subject.class.get.first
25
+ resource.Id.should eq("20100912153422758914000000")
26
+ stub_api_post("/#{subject.class.element_name}/#{resource.Id}",'listing_cart_add_listing_post.json', 'listing_cart_add_listing.json')
27
+ resource.ListingCount.should eq(10)
28
+ resource.add_listing(list_id)
29
+ resource.ListingCount.should eq(11)
30
+ end
31
+
32
+ it "should remove a listing from a cart" do
33
+ list_id = "20110621133454434543000000"
34
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
35
+ resource = subject.class.get.first
36
+ resource.Id.should eq("20100912153422758914000000")
37
+ stub_api_delete("/#{subject.class.element_name}/#{resource.Id}/listings/#{list_id}", 'listing_cart_remove_listing.json')
38
+ resource.ListingCount.should eq(10)
39
+ resource.remove_listing(list_id)
40
+ resource.ListingCount.should eq(9)
41
+ end
42
+
43
+ let(:listing){ Listing.new(:Id => "20110112234857732941000000") }
44
+ it "should get all carts for a listing" do
45
+ stub_api_get("/#{subject.class.element_name}/for/#{listing.Id}", 'listing_cart.json')
46
+ [listing, listing.Id ].each do |l|
47
+ resources = subject.class.for(l)
48
+ resources.should be_an(Array)
49
+ resources.length.should eq(2)
50
+ resources.first.Id.should eq("20100912153422758914000000")
51
+ end
52
+ end
53
+
54
+ it "should get the carts for a user" do
55
+ stub_api_get("/my/#{subject.class.element_name}", 'listing_cart.json')
56
+ resources = subject.class.my
57
+ resources.should be_an(Array)
58
+ resources.length.should eq(2)
59
+ resources.first.Id.should eq("20100912153422758914000000")
60
+ end
61
+
62
+ it "should get the carts specific to a portal user" do
63
+ stub_api_get("/#{subject.class.element_name}/portal", 'listing_cart.json')
64
+ resources = subject.class.portal
65
+ resources.should be_an(Array)
66
+ resources.length.should eq(2)
67
+ resources.first.Id.should eq("20100912153422758914000000")
68
+ end
69
+
70
+ it "should save a new listing cart" do
71
+ stub_api_post("/#{subject.class.element_name}", 'listing_cart_new.json', 'listing_cart_post.json')
72
+ subject.ListingIds = [
73
+ '20110112234857732941000000',
74
+ '20110302120238448431000000',
75
+ '20110510011212354751000000']
76
+ subject.Name = "My Cart's Name"
77
+ subject.save.should be(true)
78
+ subject.ResourceUri.should eq("/v1/listingcarts/20100912153422758914000000")
79
+ end
80
+
81
+ it "should save a listing cart" do
82
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
83
+ resource = subject.class.get.first
84
+ stub_api_put("/#{subject.class.element_name}/#{resource.Id}", 'listing_cart_new.json', 'success.json')
85
+ resource.ListingIds = [
86
+ '20110112234857732941000000',
87
+ '20110302120238448431000000',
88
+ '20110510011212354751000000']
89
+
90
+ resource.Name = "My Cart's Name"
91
+ resource.save.should be(true)
92
+ resource.ResourceUri.should eq("/v1/listingcarts/20100912153422758914000000")
93
+ end
94
+
95
+ it "should fail saving" do
96
+ stub_api_post("/#{subject.class.element_name}",'listing_cart_empty.json') do |request|
97
+ request.to_return(:status => 400, :body => fixture('errors/failure.json'))
98
+ end
99
+ subject
100
+ subject.save.should be(false)
101
+ expect{ subject.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
102
+ end
103
+
104
+ it "should delete a listing cart" do
105
+ stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
106
+ resource = subject.class.get.first
107
+ resource.Id.should eq("20100912153422758914000000")
108
+ resource.Name.should eq("My Listing Cart")
109
+ resource.ListingCount.should eq(10)
110
+ stub_api_delete("/#{subject.class.element_name}/#{resource.Id}", 'success.json')
111
+ resource.delete.should be(nil)
112
+ end
113
+
114
+ end
@@ -90,14 +90,7 @@ describe Listing do
90
90
 
91
91
  it "should return the count" do
92
92
  stub_auth_request
93
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
94
- with(:query => {
95
- :_pagination => "count",
96
- :ApiSig => "9028191e427eee6774527e7d19f489cb",
97
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
98
- :ApiUser => "foobar"
99
- }).
100
- to_return(:body => fixture('count.json'))
93
+ stub_api_get("/listings", 'count.json', { :_pagination => "count"})
101
94
  count = Listing.count()
102
95
  count.should == 2001
103
96
  end
@@ -108,16 +101,8 @@ describe Listing do
108
101
  stub_auth_request
109
102
  end
110
103
 
111
-
112
104
  it "should return an array of photos" do
113
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
114
- with(:query => {
115
- :ApiSig => "3c942a2d6746299c476dd2e30d10966b",
116
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
117
- :ApiUser => "foobar",
118
- :_expand => "Photos"
119
- }).
120
- to_return(:body => fixture('listing_with_photos.json'))
105
+ stub_api_get("/listings/1234", 'listing_with_photos.json', { :_expand => "Photos" })
121
106
 
122
107
  l = Listing.find('1234', :_expand => "Photos")
123
108
  l.photos.length.should == 5
@@ -127,14 +112,7 @@ describe Listing do
127
112
  end
128
113
 
129
114
  it "should return an array of documents" do
130
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
131
- with(:query => {
132
- :ApiSig => "554b6e2a3efec8719b782647c19d238d",
133
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
134
- :ApiUser => "foobar",
135
- :_expand => "Documents"
136
- }).
137
- to_return(:body => fixture('listing_with_documents.json'))
115
+ stub_api_get("/listings/1234", 'listing_with_documents.json', { :_expand => "Documents" })
138
116
 
139
117
  l = Listing.find('1234', :_expand => "Documents")
140
118
  l.photos.length.should == 0
@@ -144,14 +122,7 @@ describe Listing do
144
122
  end
145
123
 
146
124
  it "should return an array of virtual tours" do
147
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
148
- with(:query => {
149
- :ApiSig => "cc966b538640dd6b37dce0067cea2e5a",
150
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
151
- :ApiUser => "foobar",
152
- :_expand => "VirtualTours"
153
- }).
154
- to_return(:body => fixture('listing_with_vtour.json'))
125
+ stub_api_get("/listings/1234", 'listing_with_vtour.json', { :_expand => "VirtualTours" })
155
126
 
156
127
  l = Listing.find('1234', :_expand => "VirtualTours")
157
128
  l.virtual_tours.length.should == 1
@@ -162,14 +133,7 @@ describe Listing do
162
133
 
163
134
 
164
135
  it "should return an array of videos" do
165
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/1234").
166
- with(:query => {
167
- :ApiSig => "12afd7ef1d98ca35c613040f5ddb92b2",
168
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
169
- :ApiUser => "foobar",
170
- :_expand => "Videos"
171
- }).
172
- to_return(:body => fixture('listing_with_videos.json'))
136
+ stub_api_get("/listings/1234", 'listing_with_videos.json', { :_expand => "Videos" })
173
137
 
174
138
  l = Listing.find('1234', :_expand => "Videos")
175
139
  l.videos.length.should == 2
@@ -179,21 +143,9 @@ describe Listing do
179
143
  end
180
144
 
181
145
  it "should return tour of homes" do
182
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/20060725224713296297000000").
183
- with(:query => {
184
- :ApiSig => "b3ae2bec3500ba4620bf8224dee28d20",
185
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
186
- :ApiUser => "foobar"
187
- }).
188
- to_return(:body => fixture('listing_no_subresources.json'))
189
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings/20060725224713296297000000/tourofhomes").
190
- with( :query => {
191
- :ApiSig => "153446de6d1db765d541587d34ed0fcf",
192
- :AuthToken => "c401736bf3d3f754f07c04e460e09573",
193
- :ApiUser => "foobar"
194
- }).
195
- to_return(:body => fixture('tour_of_homes.json'))
196
-
146
+ stub_api_get("/listings/20060725224713296297000000", 'listing_no_subresources.json')
147
+ stub_api_get("/listings/20060725224713296297000000/tourofhomes", 'tour_of_homes.json')
148
+
197
149
  l = Listing.find('20060725224713296297000000')
198
150
  l.tour_of_homes().length.should == 2
199
151
  l.videos.length.should == 0