1
0
Fork 0
mirror of https://github.com/nov/fb_graph2 synced 2023-03-27 23:22:15 -04:00

started adding edges to the non-user objects

This commit is contained in:
nov 2014-05-28 15:16:12 +09:00
parent c5d529be13
commit f4d856ed3f
9 changed files with 86 additions and 10 deletions

View file

@ -1,5 +1,8 @@
module FbGraph2
class Achievement < Node
include Edge::Comments
include Edge::Likes::LikeeContext
register_attributes(
raw: [:type, :no_feed_story],
time: [:publish_time],

View file

@ -1,5 +1,11 @@
module FbGraph2
class Album < Node
include Edge::Comments
include Edge::Likes::LikeeContext
include Edge::Picture
include Edge::Photos
include Edge::SharedPosts
register_attributes(
raw: [:can_upload, :count, :cover_photo, :description, :link, :location, :name, :privacy, :type],
time: [:created_time, :updated_time],

15
lib/fb_graph2/comment.rb Normal file
View file

@ -0,0 +1,15 @@
module FbGraph2
class Comment < Node
register_attributes(
raw: [:can_comment, :can_remove, :comment_count, :like_count, :message, :user_likes],
time: [:created_time],
user: [:from],
custom: [:attachment, :message_tags, :parent]
)
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
end
end
end

View file

@ -0,0 +1,17 @@
module FbGraph2
class Edge
module Comments
def comments(params = {})
comments = self.edge :comments, params
comments.collect do |comment|
Comment.new(comment[:id], comment).authenticate self.access_token
end
end
def comment!(params = {})
comment = self.post params, edge: :comments
Comment.new(comment[:id], comment.merge(params)).authenticate self.access_token
end
end
end
end

View file

@ -1,16 +1,35 @@
module FbGraph2
class Edge
module Likes
def likes(params = {})
pages = self.edge :likes, params
pages.collect do |page|
Page.new(page[:id], page).authenticate self.access_token
module LikerContext
def likes(params = {})
pages = self.edge :likes, params
pages.collect do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
def liked?(page_id, params = {})
pages = self.edge :likes, params, edge_scope: page_id
pages.present?
end
end
def liked?(page_id, params = {})
pages = self.edge :likes, params, edge_scope: page_id
pages.present?
module LikeeContext
def likes(params = {})
users = self.edge :likes, params
users.collect do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
def like!(params = {})
self.post params, edge: :likes
end
def unlike!(params = {})
self.delete params, edge: :likes
end
end
end
end

View file

@ -0,0 +1,13 @@
module FbGraph2
class Edge
module SharedPosts
def shared_posts(params = {})
posts = self.edge :posts, params
posts.collect do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
alias_method :sharedposts, :shared_posts
end
end
end

View file

@ -60,7 +60,7 @@ module FbGraph2
def delete(params = {}, options = {})
handle_response do
http_client.delete build_endpoint(params), build_params(params)
http_client.delete build_endpoint(options), build_params(params)
end
end
@ -85,7 +85,8 @@ module FbGraph2
def handle_response
response = yield
_response_ = MultiJson.load(response.body).with_indifferent_access
_response_ = MultiJson.load response.body
_response_ = _response_.with_indifferent_access if _response_.respond_to? :with_indifferent_access
case response.status
when 200...300
_response_

View file

@ -1,5 +1,7 @@
module FbGraph2
class Post < Node
include Edge::Likes::LikeeContext
register_attributes(
raw: [
:caption, :description, :icon, :is_hidden, :link, :message, :name, :object_id, :picture,

View file

@ -14,7 +14,7 @@ module FbGraph2
include Edge::Home
include Edge::Interests
include Edge::InvitableFriends
include Edge::Likes
include Edge::Likes::LikerContext
include Edge::Links
include Edge::Movies
include Edge::Music