mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
more user edges
This commit is contained in:
parent
95f699fb7c
commit
1fd1825e03
14 changed files with 160 additions and 3 deletions
|
@ -19,8 +19,8 @@ module FbGraph2
|
||||||
self.raw_attributes = attributes
|
self.raw_attributes = attributes
|
||||||
Array(self.class.registered_attributes).each do |type, keys|
|
Array(self.class.registered_attributes).each do |type, keys|
|
||||||
keys.each do |key|
|
keys.each do |key|
|
||||||
|
if attributes.include? key
|
||||||
raw = attributes[key]
|
raw = attributes[key]
|
||||||
if raw.present?
|
|
||||||
value = case type
|
value = case type
|
||||||
when :raw
|
when :raw
|
||||||
raw
|
raw
|
||||||
|
@ -48,6 +48,10 @@ module FbGraph2
|
||||||
Application.new raw[:id], raw
|
Application.new raw[:id], raw
|
||||||
when :user
|
when :user
|
||||||
User.new raw[:id], raw
|
User.new raw[:id], raw
|
||||||
|
when :picture
|
||||||
|
Struct::Picture.new raw[:data]
|
||||||
|
when :album
|
||||||
|
Album.new raw[:id], raw
|
||||||
else
|
else
|
||||||
# NOTE: handle these attributes in each class
|
# NOTE: handle these attributes in each class
|
||||||
next
|
next
|
||||||
|
|
12
lib/fb_graph2/edge/invitable_friends.rb
Normal file
12
lib/fb_graph2/edge/invitable_friends.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module InvitableFriends
|
||||||
|
def invitable_friends(params = {})
|
||||||
|
invitable_friends = self.edge :invitable_friends, params
|
||||||
|
invitable_friends.collect do |invitable_friend|
|
||||||
|
Struct::InvitableFriend.new invitable_friend
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
lib/fb_graph2/edge/notifications.rb
Normal file
12
lib/fb_graph2/edge/notifications.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module Notifications
|
||||||
|
def notifications(params = {})
|
||||||
|
notifications = self.edge :notifications, params
|
||||||
|
notifications.collect do |notification|
|
||||||
|
Notification.new notification[:id], notification
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
lib/fb_graph2/edge/permissions.rb
Normal file
12
lib/fb_graph2/edge/permissions.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module Permissions
|
||||||
|
def permissions(params = {})
|
||||||
|
permissions = self.edge :permissions, params
|
||||||
|
permissions.collect do |permission|
|
||||||
|
Struct::Permission.new permission
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
18
lib/fb_graph2/edge/photos.rb
Normal file
18
lib/fb_graph2/edge/photos.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module Photos
|
||||||
|
def photos(*args)
|
||||||
|
params = args.extract_options!
|
||||||
|
photos = self.edge :photos, params, edge_scope: args.first
|
||||||
|
photos.collect do |photo|
|
||||||
|
Photo.new(photo[:id], photo).authenticate self.access_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def photo!(params = {})
|
||||||
|
photo = post params, edge: :photos
|
||||||
|
Photo.new(photo[:id], params.merge(photo)).authenticate self.access_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
lib/fb_graph2/edge/picture.rb
Normal file
12
lib/fb_graph2/edge/picture.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module Picture
|
||||||
|
def picture(*args)
|
||||||
|
params = args.extract_options!
|
||||||
|
params[:type] = args.first if args.first
|
||||||
|
picture = self.get params.merge(redirect: false), edge: :picture
|
||||||
|
Struct::Picture.new picture[:data]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -8,7 +8,7 @@ module FbGraph2
|
||||||
|
|
||||||
def initialize(id, attributes = {})
|
def initialize(id, attributes = {})
|
||||||
self.id = id
|
self.id = id
|
||||||
assign attributes if respond_to?(:assign)
|
assign attributes if respond_to? :assign
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate(access_token)
|
def authenticate(access_token)
|
||||||
|
@ -36,6 +36,10 @@ module FbGraph2
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy(params = {}, options = {})
|
||||||
|
delete params, options
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def http_client
|
def http_client
|
||||||
|
@ -54,6 +58,12 @@ module FbGraph2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(params = {}, options = {})
|
||||||
|
handle_response do
|
||||||
|
http_client.delete build_endpoint(params), build_params(params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def edge_for(edge, params = {}, options = {})
|
def edge_for(edge, params = {}, options = {})
|
||||||
|
|
17
lib/fb_graph2/notification.rb
Normal file
17
lib/fb_graph2/notification.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Notification < Node
|
||||||
|
register_attributes(
|
||||||
|
raw: [:title, :link, :unread],
|
||||||
|
time: [:created_time, :updated_time],
|
||||||
|
profile: [:from],
|
||||||
|
user: [:to],
|
||||||
|
application: [:application],
|
||||||
|
custom: [:object]
|
||||||
|
)
|
||||||
|
|
||||||
|
def initialize(id, attributes = {})
|
||||||
|
super
|
||||||
|
# TODO: handle custom attributes.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
lib/fb_graph2/photo.rb
Normal file
12
lib/fb_graph2/photo.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Photo < Node
|
||||||
|
register_attributes(
|
||||||
|
raw: [:backdated_time_granularity, :height, :icon, :link, :name, :page_story_id, :picture, :position, :source, :width],
|
||||||
|
time: [:backdated_time, :created_time, :updated_time],
|
||||||
|
page: [:place],
|
||||||
|
profile: [:from],
|
||||||
|
album: [:album],
|
||||||
|
custom: [:images, :name_tags]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
15
lib/fb_graph2/struct.rb
Normal file
15
lib/fb_graph2/struct.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Struct
|
||||||
|
def self.inherited(klass)
|
||||||
|
klass.include AttributeAssigner
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(attributes = {})
|
||||||
|
assign attributes if respond_to? :assign
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir[File.join(__dir__, 'struct/*.rb')].each do |file|
|
||||||
|
require file
|
||||||
|
end
|
10
lib/fb_graph2/struct/invitable_friend.rb
Normal file
10
lib/fb_graph2/struct/invitable_friend.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Struct
|
||||||
|
class InvitableFriend < Struct
|
||||||
|
register_attributes(
|
||||||
|
raw: [:id, :name],
|
||||||
|
picture: [:picture]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
9
lib/fb_graph2/struct/permission.rb
Normal file
9
lib/fb_graph2/struct/permission.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Struct
|
||||||
|
class Permission < Struct
|
||||||
|
register_attributes(
|
||||||
|
raw: [:permission, :status]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
9
lib/fb_graph2/struct/picture.rb
Normal file
9
lib/fb_graph2/struct/picture.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Struct
|
||||||
|
class Picture < Struct
|
||||||
|
register_attributes(
|
||||||
|
raw: [:url, :is_silhouette, :height, :width]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,10 +13,15 @@ module FbGraph2
|
||||||
include Edge::Games
|
include Edge::Games
|
||||||
include Edge::Home
|
include Edge::Home
|
||||||
include Edge::Interests
|
include Edge::Interests
|
||||||
|
include Edge::InvitableFriends
|
||||||
include Edge::Likes
|
include Edge::Likes
|
||||||
include Edge::Links
|
include Edge::Links
|
||||||
include Edge::Movies
|
include Edge::Movies
|
||||||
include Edge::Music
|
include Edge::Music
|
||||||
|
include Edge::Notifications
|
||||||
|
include Edge::Permissions
|
||||||
|
include Edge::Picture
|
||||||
|
include Edge::Photos
|
||||||
include Edge::Posts
|
include Edge::Posts
|
||||||
include Edge::Statuses
|
include Edge::Statuses
|
||||||
include Edge::Tagged
|
include Edge::Tagged
|
||||||
|
|
Loading…
Reference in a new issue