spark_api 1.3.21 → 1.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.21
1
+ 1.3.23
@@ -34,7 +34,7 @@ module SparkApi
34
34
  end
35
35
 
36
36
  end
37
- Faraday.register_middleware :response, :oauth2_impl => FaradayMiddleware
37
+ Faraday::Response.register_middleware :oauth2_impl => FaradayMiddleware
38
38
 
39
39
  #==OAuth2 Faraday response middleware
40
40
  # HTTP Response after filter to package oauth2 responses and bubble up basic api errors.
@@ -62,7 +62,7 @@ module SparkApi
62
62
  end
63
63
 
64
64
  end
65
- Faraday.register_middleware :response, :sparkbar_impl => SparkbarFaradayMiddleware
65
+ Faraday::Response.register_middleware :sparkbar_impl => SparkbarFaradayMiddleware
66
66
 
67
67
  end
68
68
  end
@@ -80,6 +80,6 @@ module SparkApi
80
80
  end
81
81
 
82
82
  end
83
- Faraday.register_middleware :response, :spark_api => FaradayMiddleware
83
+ Faraday::Response.register_middleware :spark_api => FaradayMiddleware
84
84
 
85
85
  end
@@ -18,6 +18,7 @@ require 'spark_api/models/listing'
18
18
  require 'spark_api/models/listing_cart'
19
19
  require 'spark_api/models/market_statistics'
20
20
  require 'spark_api/models/message'
21
+ require 'spark_api/models/newsfeed'
21
22
  require 'spark_api/models/note'
22
23
  require 'spark_api/models/notification'
23
24
  require 'spark_api/models/open_house'
@@ -94,7 +94,7 @@ module SparkApi
94
94
  end
95
95
  else
96
96
  return attributes[method_name] if attributes.include?(method_name)
97
- super # GTFO
97
+ super
98
98
  end
99
99
  end
100
100
 
@@ -8,6 +8,7 @@ module SparkApi
8
8
  scope = arguments.slice!(0)
9
9
  options = arguments.slice!(0) || {}
10
10
  case scope
11
+ when nil then raise ArgumentError, "Argument for find() can't be nil"
11
12
  when :all then find_every(options)
12
13
  when :first then find_every(options).first
13
14
  when :last then find_every(options).last
@@ -31,11 +32,11 @@ module SparkApi
31
32
  private
32
33
 
33
34
  def find_every(options)
34
- collect(connection.get("/#{element_name}", options))
35
+ collect(connection.get("#{path}", options))
35
36
  end
36
37
 
37
38
  def find_single(scope, options)
38
- resp = connection.get("/#{element_name}/#{scope}", options)
39
+ resp = connection.get("#{path}/#{scope}", options)
39
40
  new(resp.first)
40
41
  end
41
42
 
@@ -233,7 +233,7 @@ module SparkApi
233
233
  else
234
234
  return attributes[method_name] if attributes.include?(method_name)
235
235
  return @attributes['StandardFields'][method_name] if attributes['StandardFields'].include?(method_name)
236
- super # GTFO
236
+ super
237
237
  end
238
238
  end
239
239
 
@@ -0,0 +1,12 @@
1
+ module SparkApi
2
+ module Models
3
+ class Newsfeed < Base
4
+
5
+ extend Finders
6
+ include Concerns::Savable
7
+
8
+ self.element_name = 'newsfeeds'
9
+
10
+ end
11
+ end
12
+ end
@@ -6,12 +6,25 @@ module SparkApi
6
6
  include Concerns::Savable,
7
7
  Concerns::Destroyable
8
8
 
9
+ attr_accessor :newsfeeds
10
+
9
11
  self.element_name="savedsearches"
10
12
 
13
+ def initialize(attributes={})
14
+ @newsfeeds = nil
15
+ super(attributes)
16
+ end
17
+
11
18
  def self.provided()
12
19
  Class.new(self).tap do |provided|
13
20
  provided.element_name = '/savedsearches'
14
21
  provided.prefix = '/provided'
22
+ def provided_search?
23
+ true
24
+ end
25
+ def newsfeeds
26
+ []
27
+ end
15
28
  SparkApi.logger.info("#{self.name}.path: #{provided.path}")
16
29
  end
17
30
  end
@@ -49,6 +62,65 @@ module SparkApi
49
62
  end
50
63
  end
51
64
 
65
+ def listings(args = {})
66
+ arguments = {:_filter => self.Filter}.merge(args)
67
+ @listings ||= Listing.collect(connection.get("/listings", arguments))
68
+ end
69
+
70
+ def newsfeeds
71
+ if @newsfeeds.nil?
72
+ response = SparkApi.client.get("/savedsearches/#{@attributes["Id"]}", :_expand => "NewsFeeds").first["NewsFeeds"]
73
+ # the response from the api is just a bunch of hashes, but we can turn them into Newsfeed instances
74
+ @newsfeeds = response.map { |hash| Newsfeed.new(hash) }
75
+ end
76
+ @newsfeeds
77
+ end
78
+
79
+ def provided_search?
80
+ false
81
+ end
82
+
83
+ def can_have_newsfeed?
84
+
85
+ return false if provided_search?
86
+ return true if has_active_newsfeed? || has_inactive_newsfeed?
87
+
88
+ # Newsfeed restriction criteria for saved searches:
89
+ # http://alpha.sparkplatform.com/docs/api_services/newsfeed/restrictions#criteria
90
+ standard_fields = %w(BathsTotal BedsTotal City CountyOrParish ListPrice Location MlsStatus PostalCode PropertyType RoomsTotal State)
91
+
92
+ number_of_filters = 0
93
+
94
+ standard_fields.each do |field|
95
+ number_of_filters += 1 if self.Filter.include? field
96
+ end
97
+
98
+ number_of_filters >= 3
99
+
100
+ end
101
+
102
+ def has_active_newsfeed?
103
+ return false if provided_search?
104
+
105
+ if self.respond_to? "NewsFeedSubscriptionSummary"
106
+ self.NewsFeedSubscriptionSummary['ActiveSubscription']
107
+ else
108
+ saved_search = SavedSearch.find( self.Id, {"_expand" => "NewsFeedSubscriptionSummary"})
109
+ saved_search.NewsFeedSubscriptionSummary['ActiveSubscription']
110
+ end
111
+ end
112
+
113
+ def has_inactive_newsfeed?
114
+ return false if provided_search?
115
+
116
+ if self.respond_to? "NewsFeedSubscriptionSummary"
117
+ !self.NewsFeedSubscriptionSummary['ActiveSubscription']
118
+ else
119
+ saved_search = SavedSearch.find( self.Id, {"_expand" => "NewsFeedSubscriptionSummary"})
120
+ !saved_search.NewsFeedSubscriptionSummary['ActiveSubscription']
121
+ end
122
+ end
123
+
52
124
  private
53
125
 
54
126
  def resource_pluralized; "SavedSearches" end
@@ -0,0 +1,30 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "Id": "20130625195235039712000000",
7
+ "ResourceUri": "/vX/newsfeeds/20130625195235039712000000",
8
+ "Active": true,
9
+ "NotificationsActive": true,
10
+ "Curated": false,
11
+ "Name": "My Newsfeed Subscription",
12
+ "Type": "SavedSearch",
13
+ "NotificationMethods": ["Email"],
14
+ "CreatedTimestamp": "2013-06-27T10:01:06-05:00",
15
+ "ModificationTimestamp": "2013-06-27T10:01:06-05:00",
16
+ "LastEventTimestamp": "2013-07-07T12:12:06-05:00",
17
+ "ExpirationDate": "2014-10-10",
18
+ "Subscription": {
19
+ "ResourceUri": "/vX/savedsearches/20100815220615294367000000",
20
+ "Id": "20100815220615294367000000",
21
+ "OwnerId": "20090815223215294334000000",
22
+ "Name": "Search name here",
23
+ "Description": "A longer description of the search",
24
+ "Filter": null,
25
+ "ModificationTimestamp": "2011-03-14T08:39:38-05:00"
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "Id": "20130625195235039712000000",
7
+ "ResourceUri": "/vX/newsfeeds/20130625195235039712000000",
8
+ "Active": false,
9
+ "NotificationsActive": true,
10
+ "Curated": false,
11
+ "Name": "My Newsfeed Subscription",
12
+ "Type": "SavedSearch",
13
+ "NotificationMethods": ["Email"],
14
+ "CreatedTimestamp": "2013-06-27T10:01:06-05:00",
15
+ "ModificationTimestamp": "2013-06-27T10:01:06-05:00",
16
+ "LastEventTimestamp": "2013-07-07T12:12:06-05:00",
17
+ "ExpirationDate": "2014-10-10",
18
+ "Subscription": {
19
+ "ResourceUri": "/vX/savedsearches/20100815220615294367000000",
20
+ "Id": "20100815220615294367000000",
21
+ "OwnerId": "20090815223215294334000000",
22
+ "Name": "Search name here",
23
+ "Description": "A longer description of the search",
24
+ "Filter": null,
25
+ "ModificationTimestamp": "2011-03-14T08:39:38-05:00"
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ }
@@ -6,6 +6,7 @@
6
6
  "ResourceUri": "/v1/savedsearches/20100815220615294367000000",
7
7
  "Id": "20100815220615294367000000",
8
8
  "Name": "Search name here",
9
+ "Filter": "City Eq 'Moorhead' And MlsStatus Eq 'Active' And PropertyType Eq 'A'",
9
10
  "ContactIds": [
10
11
  "20100815220615294367000000"
11
12
  ]
@@ -0,0 +1,35 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "ResourceUri": "/v1/savedsearches/20100815220615294367000000",
7
+ "Id": "20100815220615294367000000",
8
+ "Name": "Search name here",
9
+ "ContactIds": [
10
+ "20100815220615294367000000"
11
+ ],
12
+ "NewsFeedSubscriptionSummary": {
13
+ "ActiveSubscription": false
14
+ },
15
+ "NewsFeeds": [
16
+ {
17
+ "ResourceUri": "/v1/newsfeeds/20141203082619076323088319",
18
+ "Name": "My Very Special Newsfeed",
19
+ "OwnerId": "20000426143505724628000000",
20
+ "ProspectLinkId": "",
21
+ "CreatedTimestamp": "2014-12-03T08:26:19Z",
22
+ "Id": "20141203082619076323088319",
23
+ "Active": "false",
24
+ "ModificationTimestamp": "2014-12-03T08:26:19Z",
25
+ "ExpirationDate": "2015-03-03",
26
+ "Curated": "false",
27
+ "NotificationMethods": ["Email"],
28
+ "LastEventTimestamp": "",
29
+ "Type": "SavedSearch"
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "ResourceUri": "/v1/savedsearches/20100815220615294367000000",
7
+ "Id": "20100815220615294367000000",
8
+ "Name": "Search name here",
9
+ "ContactIds": [
10
+ "20100815220615294367000000"
11
+ ],
12
+ "NewsFeedSubscriptionSummary": {
13
+ "ActiveSubscription": true
14
+ },
15
+ "NewsFeeds": [
16
+ {
17
+ "ResourceUri": "/v1/newsfeeds/20141203082619076323088319",
18
+ "Name": "My Very Special Newsfeed",
19
+ "OwnerId": "20000426143505724628000000",
20
+ "ProspectLinkId": "",
21
+ "CreatedTimestamp": "2014-12-03T08:26:19Z",
22
+ "Id": "20141203082619076323088319",
23
+ "Active": "true",
24
+ "ModificationTimestamp": "2014-12-03T08:26:19Z",
25
+ "ExpirationDate": "2015-03-03",
26
+ "Curated": "false",
27
+ "NotificationMethods": ["Email"],
28
+ "LastEventTimestamp": "",
29
+ "Type": "SavedSearch"
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ }
@@ -39,7 +39,7 @@ describe SparkApi::Client, "Client config" do
39
39
  :endpoint => "https://api.wade.dev.fbsdata.com",
40
40
  :ssl_verify => false)
41
41
  client.ssl_verify.should be_false
42
- client.connection.ssl.should eq({:verify=>false})
42
+ client.connection.ssl.verify.should be_false
43
43
  end
44
44
 
45
45
  it "should allow restrict ssl certificates when verification is on" do
@@ -47,7 +47,7 @@ describe SparkApi::Client, "Client config" do
47
47
  :endpoint => "https://api.wade.dev.fbsdata.com",
48
48
  :ssl_verify => true)
49
49
  client.ssl_verify.should be_true
50
- client.connection.ssl.should eq({})
50
+ client.connection.ssl.should be_empty
51
51
  end
52
52
  end
53
53
 
@@ -32,4 +32,21 @@ describe Finders, "Finders model" do
32
32
  resource.Id.should eq(1)
33
33
  end
34
34
 
35
+ describe "find" do
36
+
37
+ it "should throw an error if no argument is passed" do
38
+ stub_api_get("/my_resource/", 'finders.json')
39
+ lambda {
40
+ MyResource.find()
41
+ }.should raise_error(ArgumentError)
42
+ end
43
+
44
+ it "should throw an error when the first argument is nil" do
45
+ stub_api_get("/my_resource/", 'finders.json', {:_limit => 1})
46
+ lambda {
47
+ MyResource.find(nil, {:_limit => 1})
48
+ }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ end
35
52
  end
@@ -0,0 +1,21 @@
1
+ require './spec/spec_helper'
2
+
3
+
4
+ describe Newsfeed do
5
+
6
+ before do
7
+ stub_auth_request
8
+ end
9
+
10
+ describe "update!" do
11
+ it "should update the attributes" do
12
+ stub_api_get("/newsfeeds/20130625195235039712000000", "newsfeeds/get.json")
13
+ stub_api_put("/newsfeeds/20130625195235039712000000", {:Active => false}, "newsfeeds/inactive.json")
14
+ @newsfeed = Newsfeed.find("20130625195235039712000000")
15
+ @newsfeed.update!(:Active => false)
16
+ expect(@newsfeed.Active) == false
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -136,4 +136,80 @@ describe SavedSearch do
136
136
  end
137
137
  end
138
138
 
139
+ describe "can_have_newsfeed?" do
140
+
141
+ it "should return false for a provided search" do
142
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
143
+ resource = subject.class.find(id)
144
+ resource.stub(:provided_search?) { true }
145
+ resource.can_have_newsfeed?.should == false
146
+ end
147
+
148
+ it "should return false without at least three filter parameters" do
149
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
150
+ resource = subject.class.find(id)
151
+ resource.stub(:provided_search?) { false }
152
+ resource.stub(:has_active_newsfeed?) { false }
153
+ resource.stub(:has_inactive_newsfeed?) { false }
154
+ resource.Filter = "City Eq 'Moorhead' And MlsStatus Eq 'Active'"
155
+ resource.can_have_newsfeed?.should == false
156
+ end
157
+
158
+ it "should return true with three filter parameters" do
159
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
160
+ resource = subject.class.find(id)
161
+ resource.stub(:provided_search?) { false }
162
+ resource.stub(:has_active_newsfeed?) { false }
163
+ resource.stub(:has_inactive_newsfeed?) { false }
164
+ resource.can_have_newsfeed?.should == true
165
+ end
166
+
167
+ end
168
+
169
+ describe "has_active_newsfeed?" do
170
+ it "should return true if the search already has a newsfeed" do
171
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
172
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
173
+ { "_expand" => "NewsFeedSubscriptionSummary" } )
174
+ resource = subject.class.find(id)
175
+ resource.stub(:provided_search?) { false }
176
+ resource.has_active_newsfeed?.should == true
177
+ end
178
+
179
+ it "should return false for a provided search" do
180
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
181
+ resource = subject.class.find(id)
182
+ resource.stub(:provided_search?) { true }
183
+ resource.has_active_newsfeed?.should == false
184
+ end
185
+ end
186
+
187
+ describe "has_inactive_newsfeed?" do
188
+ it "should return true if the search has an inactive newsfeed" do
189
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json')
190
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json',
191
+ { "_expand" => "NewsFeedSubscriptionSummary" } )
192
+ resource = subject.class.find(id)
193
+ resource.stub(:provided_search?) { false }
194
+ resource.has_inactive_newsfeed?.should == true
195
+ end
196
+
197
+ it "should return false for a provided search" do
198
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json')
199
+ resource = subject.class.find(id)
200
+ resource.stub(:provided_search?) { true }
201
+ resource.has_inactive_newsfeed?.should == false
202
+ end
203
+ end
204
+
205
+ describe "newsfeed" do
206
+ it "should return the newsfeed for the saved search" do
207
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
208
+ stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
209
+ { "_expand" => "NewsFeeds" } )
210
+ resource = subject.class.find(id)
211
+ resource.newsfeeds.should be_an(Array)
212
+ end
213
+ end
214
+
139
215
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 21
10
- version: 1.3.21
9
+ - 23
10
+ version: 1.3.23
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Hornseth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2015-01-12 00:00:00 Z
19
+ date: 2015-02-06 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 61
28
+ hash: 59
29
29
  segments:
30
30
  - 0
31
- - 8
32
- - 1
33
- version: 0.8.1
31
+ - 9
32
+ - 0
33
+ version: 0.9.0
34
34
  version_requirements: *id001
35
35
  prerelease: false
36
36
  name: faraday
@@ -339,6 +339,7 @@ files:
339
339
  - lib/spark_api/models/fields.rb
340
340
  - lib/spark_api/models/system_info.rb
341
341
  - lib/spark_api/models/document.rb
342
+ - lib/spark_api/models/newsfeed.rb
342
343
  - lib/spark_api/models/comment.rb
343
344
  - lib/spark_api/models/market_statistics.rb
344
345
  - lib/spark_api/models/photo.rb
@@ -415,6 +416,8 @@ files:
415
416
  - spec/fixtures/errors/failure_with_msg.json
416
417
  - spec/fixtures/errors/failure.json
417
418
  - spec/fixtures/errors/failure_with_constraint.json
419
+ - spec/fixtures/newsfeeds/inactive.json
420
+ - spec/fixtures/newsfeeds/get.json
418
421
  - spec/fixtures/property_types/property_types.json
419
422
  - spec/fixtures/empty.json
420
423
  - spec/fixtures/logo_fbs.png
@@ -424,7 +427,9 @@ files:
424
427
  - spec/fixtures/saved_searches/post.json
425
428
  - spec/fixtures/saved_searches/update.json
426
429
  - spec/fixtures/saved_searches/new.json
430
+ - spec/fixtures/saved_searches/with_newsfeed.json
427
431
  - spec/fixtures/saved_searches/get.json
432
+ - spec/fixtures/saved_searches/with_inactive_newsfeed.json
428
433
  - spec/fixtures/messages/post.json
429
434
  - spec/fixtures/messages/new_with_recipients.json
430
435
  - spec/fixtures/messages/new.json
@@ -514,6 +519,7 @@ files:
514
519
  - spec/unit/spark_api/models/notification_spec.rb
515
520
  - spec/unit/spark_api/models/note_spec.rb
516
521
  - spec/unit/spark_api/models/connect_prefs_spec.rb
522
+ - spec/unit/spark_api/models/newsfeed_spec.rb
517
523
  - spec/unit/spark_api/models/fields_spec.rb
518
524
  - spec/unit/spark_api/models/concerns/destroyable_spec.rb
519
525
  - spec/unit/spark_api/models/concerns/savable_spec.rb
@@ -621,6 +627,8 @@ test_files:
621
627
  - spec/fixtures/errors/failure_with_msg.json
622
628
  - spec/fixtures/errors/failure.json
623
629
  - spec/fixtures/errors/failure_with_constraint.json
630
+ - spec/fixtures/newsfeeds/inactive.json
631
+ - spec/fixtures/newsfeeds/get.json
624
632
  - spec/fixtures/property_types/property_types.json
625
633
  - spec/fixtures/empty.json
626
634
  - spec/fixtures/logo_fbs.png
@@ -630,7 +638,9 @@ test_files:
630
638
  - spec/fixtures/saved_searches/post.json
631
639
  - spec/fixtures/saved_searches/update.json
632
640
  - spec/fixtures/saved_searches/new.json
641
+ - spec/fixtures/saved_searches/with_newsfeed.json
633
642
  - spec/fixtures/saved_searches/get.json
643
+ - spec/fixtures/saved_searches/with_inactive_newsfeed.json
634
644
  - spec/fixtures/messages/post.json
635
645
  - spec/fixtures/messages/new_with_recipients.json
636
646
  - spec/fixtures/messages/new.json
@@ -720,6 +730,7 @@ test_files:
720
730
  - spec/unit/spark_api/models/notification_spec.rb
721
731
  - spec/unit/spark_api/models/note_spec.rb
722
732
  - spec/unit/spark_api/models/connect_prefs_spec.rb
733
+ - spec/unit/spark_api/models/newsfeed_spec.rb
723
734
  - spec/unit/spark_api/models/fields_spec.rb
724
735
  - spec/unit/spark_api/models/concerns/destroyable_spec.rb
725
736
  - spec/unit/spark_api/models/concerns/savable_spec.rb