Skip to content

Commit

Permalink
Merge pull request #95 from Fullscreen/add-since
Browse files Browse the repository at this point in the history
Add since option for posts and videos of a page
  • Loading branch information
kangkyu committed Oct 5, 2017
2 parents 41cf136 + 7afd94e commit 8769aa6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/funky/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def self.find(page_id)
#
# @return [Array<Funky::Video>] multiple Funky::Video objects containing data
# fetched by Facebook Graph API.
def videos
videos = Funky::Connection::API.fetch(
"#{id}/videos?fields=id,title,description,created_time,length,comments.limit(0).summary(true),likes.limit(0).summary(true),reactions.limit(0).summary(true)",
is_array: true)
def videos(options = {})
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)"
path_query << "&since=#{options[:since]}" if options[:since]
videos = Funky::Connection::API.fetch_all(path_query)
videos.map {|video| Video.new(video) }
end

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

Expand Down
14 changes: 14 additions & 0 deletions spec/pages/posts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@
end
end
end

describe '#posts with since option' do
let(:page) { Funky::Page.find(page_id) }
let(:posts) { page.posts(since: since_date) }

context 'given an existing page ID and since date' do
let(:page_id) { fullscreen_page_id }
let(:since_date) { "2017-07-27" }

specify 'returns the first post of since date as the last' do
expect(posts.last.id).to eq('221406534569729_1516478451729191')
end
end
end
end
14 changes: 14 additions & 0 deletions spec/pages/videos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,18 @@
end
end
end

describe '#videos with since option' do
let(:page) { Funky::Page.find(page_id) }
let(:videos) { page.videos(since: since_date) }

context 'given an existing page ID and since date' do
let(:page_id) { fullscreen_page_id }
let(:since_date) { "2017-07-27" }

specify 'returns the first video of since date as the last' do
expect(videos.last.id).to eq('1517225178321185')
end
end
end
end

0 comments on commit 8769aa6

Please sign in to comment.