From 70e50429f0b19501027807134b899603c22247ac Mon Sep 17 00:00:00 2001 From: nov Date: Mon, 2 Jun 2014 15:51:06 +0900 Subject: [PATCH] FbGraph2::Util & page edges --- lib/fb_graph2/edge/admins.rb | 4 ++-- lib/fb_graph2/edge/blocked.rb | 24 +++++++++++++++++++++ lib/fb_graph2/edge/global_brand_children.rb | 12 +++++++++++ lib/fb_graph2/edge/likes.rb | 4 ++-- lib/fb_graph2/edge/locations.rb | 14 ++++++++++++ lib/fb_graph2/edge/milestones.rb | 12 +++++++++++ lib/fb_graph2/edge/offers.rb | 12 +++++++++++ lib/fb_graph2/edge/promotable_posts.rb | 12 +++++++++++ lib/fb_graph2/milestone.rb | 9 ++++++++ lib/fb_graph2/node.rb | 2 +- lib/fb_graph2/offer.rb | 10 +++++++++ lib/fb_graph2/page.rb | 16 ++++++++++++++ lib/fb_graph2/util.rb | 13 +++++++++++ 13 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 lib/fb_graph2/edge/blocked.rb create mode 100644 lib/fb_graph2/edge/global_brand_children.rb create mode 100644 lib/fb_graph2/edge/locations.rb create mode 100644 lib/fb_graph2/edge/milestones.rb create mode 100644 lib/fb_graph2/edge/offers.rb create mode 100644 lib/fb_graph2/edge/promotable_posts.rb create mode 100644 lib/fb_graph2/milestone.rb create mode 100644 lib/fb_graph2/offer.rb create mode 100644 lib/fb_graph2/util.rb diff --git a/lib/fb_graph2/edge/admins.rb b/lib/fb_graph2/edge/admins.rb index 3e96d49..46f398b 100644 --- a/lib/fb_graph2/edge/admins.rb +++ b/lib/fb_graph2/edge/admins.rb @@ -8,8 +8,8 @@ module FbGraph2 end end - def admin?(user_id, params = {}) - users = self.edge :admins, params, edge_scope: user_id + def admin?(user, params = {}) + users = self.edge :admins, params, edge_scope: user users.present? end end diff --git a/lib/fb_graph2/edge/blocked.rb b/lib/fb_graph2/edge/blocked.rb new file mode 100644 index 0000000..21f816a --- /dev/null +++ b/lib/fb_graph2/edge/blocked.rb @@ -0,0 +1,24 @@ +module FbGraph2 + class Edge + module Blocked + def blocked(params = {}) + users = self.edge :blocked, params + users.collect do |user| + User.new(user[:id], user).authenticate self.access_token + end + end + + def block!(user, params = {}) + self.post params.merge( + user_id: Util.as_identifier(user) + ), edge: :blocked + end + + def unblock!(user, params = {}) + self.delete params.merge( + user_id: Util.as_identifier(user) + ), edge: :blocked + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/edge/global_brand_children.rb b/lib/fb_graph2/edge/global_brand_children.rb new file mode 100644 index 0000000..5ede5fa --- /dev/null +++ b/lib/fb_graph2/edge/global_brand_children.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module GlobalBrandChildren + def global_brand_children(params = {}) + pages = self.edge :global_brand_children, params + pages.collect do |page| + Page.new(page[:id], page).authenticate self.access_token + end + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/edge/likes.rb b/lib/fb_graph2/edge/likes.rb index f44cff5..2575a7c 100644 --- a/lib/fb_graph2/edge/likes.rb +++ b/lib/fb_graph2/edge/likes.rb @@ -9,8 +9,8 @@ module FbGraph2 end end - def liked?(page_id, params = {}) - pages = self.edge :likes, params, edge_scope: page_id + def liked?(page, params = {}) + pages = self.edge :likes, params, edge_scope: page pages.present? end end diff --git a/lib/fb_graph2/edge/locations.rb b/lib/fb_graph2/edge/locations.rb new file mode 100644 index 0000000..68fd200 --- /dev/null +++ b/lib/fb_graph2/edge/locations.rb @@ -0,0 +1,14 @@ +module FbGraph2 + class Edge + module Locations + def locations(params = {}) + pages = self.edge :locations, params + pages.collect do |page| + Page.new(page[:id], page).authenticate self.access_token + end + end + + # TODO: add, delete and update locations + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/edge/milestones.rb b/lib/fb_graph2/edge/milestones.rb new file mode 100644 index 0000000..6bb40a6 --- /dev/null +++ b/lib/fb_graph2/edge/milestones.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module Milestones + def milestones(params = {}) + milestones = self.edge :milestones, params + milestones.collect do |milestone| + Milestone.new(milestone[:id], milestone).authenticate self.access_token + end + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/edge/offers.rb b/lib/fb_graph2/edge/offers.rb new file mode 100644 index 0000000..d3389d9 --- /dev/null +++ b/lib/fb_graph2/edge/offers.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module Offers + def offers(params = {}) + offers = self.edge :offers, params + offers.collect do |offer| + Offer.new(offer[:id], offer).authenticate self.access_token + end + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/edge/promotable_posts.rb b/lib/fb_graph2/edge/promotable_posts.rb new file mode 100644 index 0000000..f5222cb --- /dev/null +++ b/lib/fb_graph2/edge/promotable_posts.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module PromotablePosts + def promotable_posts(params = {}) + posts = self.edge :promotable_posts, params + posts.collect do |post| + Post.new(post[:id], post).authenticate self.access_token + end + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/milestone.rb b/lib/fb_graph2/milestone.rb new file mode 100644 index 0000000..2357805 --- /dev/null +++ b/lib/fb_graph2/milestone.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Milestone < Node + register_attributes( + raw: [:title, :description], + time: [:created_time, :updated_time, :start_time, :end_time], + page: [:from] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/node.rb b/lib/fb_graph2/node.rb index 5c349d6..781d736 100644 --- a/lib/fb_graph2/node.rb +++ b/lib/fb_graph2/node.rb @@ -75,7 +75,7 @@ module FbGraph2 File.join [ File.join(FbGraph2.root_url, id.to_s), options[:edge], - options[:edge_scope].respond_to?(:id) ? options[:edge_scope].id : options[:edge_scope] + Util.as_identifier(options[:edge_scope]) ].compact.collect(&:to_s) end diff --git a/lib/fb_graph2/offer.rb b/lib/fb_graph2/offer.rb new file mode 100644 index 0000000..424852c --- /dev/null +++ b/lib/fb_graph2/offer.rb @@ -0,0 +1,10 @@ +module FbGraph2 + class Offer < Node + register_attributes( + raw: [:claim_limit, :coupon_type, :image_url, :published, :redemption_code, :redemption_link, :terms, :title, :message], + time: [:created_time, :expiration_time, :reminder_time], + timestamp: [:scheduled_publish_time], + page: [:from] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 0ab1e1f..706996d 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -1,6 +1,22 @@ module FbGraph2 class Page < Node include Edge::Admins + include Edge::Albums + include Edge::Blocked + include Edge::Events + include Edge::Feed + include Edge::GlobalBrandChildren + include Edge::Links + include Edge::Locations + include Edge::Milestones + include Edge::Offers + include Edge::Picture + include Edge::Photos + include Edge::Posts + include Edge::PromotablePosts + include Edge::Statuses + include Edge::Tagged + include Edge::Videos register_attributes( raw: [ diff --git a/lib/fb_graph2/util.rb b/lib/fb_graph2/util.rb new file mode 100644 index 0000000..11eafd6 --- /dev/null +++ b/lib/fb_graph2/util.rb @@ -0,0 +1,13 @@ +module FbGraph2 + module Util + module_function + + def as_identifier(object) + if object.respond_to? :id + object.id + else + object + end + end + end +end \ No newline at end of file