mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
FbGraph2::Util & page edges
This commit is contained in:
parent
49f5aeae8b
commit
70e50429f0
13 changed files with 139 additions and 5 deletions
|
@ -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
|
||||
|
|
24
lib/fb_graph2/edge/blocked.rb
Normal file
24
lib/fb_graph2/edge/blocked.rb
Normal file
|
@ -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
|
12
lib/fb_graph2/edge/global_brand_children.rb
Normal file
12
lib/fb_graph2/edge/global_brand_children.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
14
lib/fb_graph2/edge/locations.rb
Normal file
14
lib/fb_graph2/edge/locations.rb
Normal file
|
@ -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
|
12
lib/fb_graph2/edge/milestones.rb
Normal file
12
lib/fb_graph2/edge/milestones.rb
Normal file
|
@ -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
|
12
lib/fb_graph2/edge/offers.rb
Normal file
12
lib/fb_graph2/edge/offers.rb
Normal file
|
@ -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
|
12
lib/fb_graph2/edge/promotable_posts.rb
Normal file
12
lib/fb_graph2/edge/promotable_posts.rb
Normal file
|
@ -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
|
9
lib/fb_graph2/milestone.rb
Normal file
9
lib/fb_graph2/milestone.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
10
lib/fb_graph2/offer.rb
Normal file
10
lib/fb_graph2/offer.rb
Normal file
|
@ -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
|
|
@ -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: [
|
||||
|
|
13
lib/fb_graph2/util.rb
Normal file
13
lib/fb_graph2/util.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue