Skip to content

Commit 87a6432

Browse files
committed
adding newsfeeds method to saved searches model
1 parent 6a2a8b3 commit 87a6432

File tree

6 files changed

+50
-15
lines changed

6 files changed

+50
-15
lines changed

lib/spark_api/models/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def method_missing(method_symbol, *arguments)
9494
end
9595
else
9696
return attributes[method_name] if attributes.include?(method_name)
97-
super # GTFO
97+
super
9898
end
9999
end
100100

lib/spark_api/models/finders.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def last(*arguments)
3131
private
3232

3333
def find_every(options)
34-
collect(connection.get("/#{element_name}", options))
34+
collect(connection.get("#{path}", options))
3535
end
3636

3737
def find_single(scope, options)
38-
resp = connection.get("/#{element_name}/#{scope}", options)
38+
resp = connection.get("#{path}/#{scope}", options)
3939
new(resp.first)
4040
end
4141

lib/spark_api/models/listing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def method_missing(method_symbol, *arguments)
233233
else
234234
return attributes[method_name] if attributes.include?(method_name)
235235
return @attributes['StandardFields'][method_name] if attributes['StandardFields'].include?(method_name)
236-
super # GTFO
236+
super
237237
end
238238
end
239239

lib/spark_api/models/saved_search.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ class SavedSearch < Base
66
include Concerns::Savable,
77
Concerns::Destroyable
88

9+
attr_accessor :newsfeeds
10+
911
self.element_name="savedsearches"
1012

13+
def initialize(attributes={})
14+
@newsfeeds = nil
15+
super(attributes)
16+
end
17+
1118
def self.provided()
1219
Class.new(self).tap do |provided|
1320
provided.element_name = '/savedsearches'
@@ -49,16 +56,14 @@ def contacts
4956
end
5057
end
5158

52-
# This section is on hold until https://jira.fbsdata.com/browse/API-2766 has been completed.
53-
#
54-
# return the newsfeed attached to this saved search
55-
# def newsfeeds
56-
# Newsfeed.find(:all, :_filter => "Subscription.Id Eq '#{@attributes["Id"]}'")
57-
# end
58-
59-
# def newsfeed_for(user)
60-
# self.newsfeeds.select { |feed| feed.OwnerId == user.Id }
61-
# end
59+
def newsfeeds
60+
if @newsfeeds.nil?
61+
response = SparkApi.client.get("/savedsearches/#{@attributes["Id"]}", _expand: "NewsFeeds").first["NewsFeeds"]
62+
# the response from the api is just a bunch of hashes, but we can turn them into Newsfeed instances
63+
@newsfeeds = response.map { |hash| Newsfeed.new(hash) }
64+
end
65+
@newsfeeds
66+
end
6267

6368
def can_have_newsfeed?
6469

spec/fixtures/saved_searches/with_newsfeed.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,24 @@
1111
],
1212
"NewsFeedSubscriptionSummary": {
1313
"ActiveSubscription": true
14-
}
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+
]
1532
}
1633
]
1734
}

spec/unit/spark_api/models/saved_search_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,17 @@
176176

177177
end
178178

179+
describe "newsfeed" do
180+
181+
it "should return the newsfeed for the saved search" do
182+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
183+
184+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
185+
{ "_expand" => "NewsFeeds" } )
186+
187+
resource = subject.class.find(id)
188+
resource.newsfeeds.should be_an(Array)
189+
end
190+
end
191+
179192
end

0 commit comments

Comments
 (0)