Skip to content

Commit 8769aa6

Browse files
authored
Merge pull request #95 from Fullscreen/add-since
Add since option for posts and videos of a page
2 parents 41cf136 + 7afd94e commit 8769aa6

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

lib/funky/page.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def self.find(page_id)
2929
#
3030
# @return [Array<Funky::Video>] multiple Funky::Video objects containing data
3131
# fetched by Facebook Graph API.
32-
def videos
33-
videos = Funky::Connection::API.fetch(
34-
"#{id}/videos?fields=id,title,description,created_time,length,comments.limit(0).summary(true),likes.limit(0).summary(true),reactions.limit(0).summary(true)",
35-
is_array: true)
32+
def videos(options = {})
33+
path_query = "#{id}/videos?fields=id,title,description,created_time,length,comments.limit(0).summary(true),likes.limit(0).summary(true),reactions.limit(0).summary(true)"
34+
path_query << "&since=#{options[:since]}" if options[:since]
35+
videos = Funky::Connection::API.fetch_all(path_query)
3636
videos.map {|video| Video.new(video) }
3737
end
3838

@@ -46,8 +46,10 @@ def videos
4646
#
4747
# @return [Array<Funky::Post>] multiple Funky::Post objects containing data
4848
# fetched by Facebook Graph API.
49-
def posts
50-
posts = Funky::Connection::API.fetch_all("#{id}/posts?fields=type,created_time")
49+
def posts(options = {})
50+
path_query = "#{id}/posts?fields=type,created_time"
51+
path_query << "&since=#{options[:since]}" if options[:since]
52+
posts = Funky::Connection::API.fetch_all(path_query)
5153
posts.map {|post| Post.new(post)}
5254
end
5355

spec/pages/posts_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,18 @@
2727
end
2828
end
2929
end
30+
31+
describe '#posts with since option' do
32+
let(:page) { Funky::Page.find(page_id) }
33+
let(:posts) { page.posts(since: since_date) }
34+
35+
context 'given an existing page ID and since date' do
36+
let(:page_id) { fullscreen_page_id }
37+
let(:since_date) { "2017-07-27" }
38+
39+
specify 'returns the first post of since date as the last' do
40+
expect(posts.last.id).to eq('221406534569729_1516478451729191')
41+
end
42+
end
43+
end
3044
end

spec/pages/videos_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,18 @@
8080
end
8181
end
8282
end
83+
84+
describe '#videos with since option' do
85+
let(:page) { Funky::Page.find(page_id) }
86+
let(:videos) { page.videos(since: since_date) }
87+
88+
context 'given an existing page ID and since date' do
89+
let(:page_id) { fullscreen_page_id }
90+
let(:since_date) { "2017-07-27" }
91+
92+
specify 'returns the first video of since date as the last' do
93+
expect(videos.last.id).to eq('1517225178321185')
94+
end
95+
end
96+
end
8397
end

0 commit comments

Comments
 (0)