mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
"profile" object handling
This commit is contained in:
parent
3caf010134
commit
02f066c357
6 changed files with 93 additions and 6 deletions
30
lib/fb_graph2/application.rb
Normal file
30
lib/fb_graph2/application.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Application < Node
|
||||||
|
include AttributeAssigner
|
||||||
|
|
||||||
|
register_attributes(
|
||||||
|
raw: [
|
||||||
|
:id, :android_key_hash, :app_domains, :auth_dialog_data_help_url, :auth_dialog_headline,
|
||||||
|
:auth_dialog_perms_explanation, :auth_referral_enabled, :auth_referral_extended_perms,
|
||||||
|
:auth_referral_friend_perms, :auth_referral_user_perms, :canvas_fluid_height, :canvas_fluid_width,
|
||||||
|
:canvas_url, :category, :company, :contact_email, :creator_uid, :daily_active_users, :daily_active_users_rank,
|
||||||
|
:deauth_callback_url, :description, :hosting_url, :icon_url, :ios_bundle_id, :iphone_app_store_id,
|
||||||
|
:link, :logo_url, :mobile_web_url, :monthly_active_users, :monthly_active_users_rank, :name,
|
||||||
|
:namespace, :page_tab_default_name, :page_tab_url, :privacy_policy_url, :secure_canvas_url,
|
||||||
|
:secure_page_tab_url, :server_ip_whitelist, :social_discovery, :subcategory, :terms_of_service_url,
|
||||||
|
:user_support_email, :user_support_url, :website_url, :weekly_active_users
|
||||||
|
],
|
||||||
|
timestamp: [:created_time],
|
||||||
|
custom: [
|
||||||
|
:auth_referral_default_activity_privacy, :auth_referral_response_type, :context, :migrations,
|
||||||
|
:object_store_urls, :restrictions
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def initialize(id, attributes = {})
|
||||||
|
super
|
||||||
|
assign attributes
|
||||||
|
# TODO: handle custom attributes.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -28,21 +28,43 @@ module FbGraph2
|
||||||
Date.parse raw
|
Date.parse raw
|
||||||
when :time
|
when :time
|
||||||
Time.parse raw
|
Time.parse raw
|
||||||
|
when :timestamp
|
||||||
|
Time.at raw
|
||||||
|
when :application
|
||||||
|
Application.new raw[:id], raw
|
||||||
when :page
|
when :page
|
||||||
Page.new raw[:id], raw
|
Page.new raw[:id], raw
|
||||||
when :pages
|
when :pages
|
||||||
raw.each do |_raw_|
|
Collection.new(raw).each do |_raw_|
|
||||||
Page.new _raw_[:id], _raw_
|
Page.new _raw_[:id], _raw_
|
||||||
end
|
end
|
||||||
|
when :profile
|
||||||
|
as_profile raw
|
||||||
|
when :profiles
|
||||||
|
Collection.new(raw).each do |_raw_|
|
||||||
|
as_profile _raw_
|
||||||
|
end
|
||||||
when :user
|
when :user
|
||||||
User.new raw[:id], raw
|
User.new raw[:id], raw
|
||||||
when :custom
|
when :custom
|
||||||
# NOTE: handle custom attributes in each class
|
# NOTE: handle custom attributes in each class
|
||||||
end
|
end
|
||||||
self.send :"#{key}=", attributes[key]
|
self.send :"#{key}=", value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_profile(raw)
|
||||||
|
klass = if raw.include?(:namespace)
|
||||||
|
Application
|
||||||
|
elsif raw.include?(:category)
|
||||||
|
Page
|
||||||
|
else
|
||||||
|
# TODO: needs to handle Event and Group here.
|
||||||
|
User
|
||||||
|
end
|
||||||
|
klass.new raw[:id], raw
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
12
lib/fb_graph2/edge/feed.rb
Normal file
12
lib/fb_graph2/edge/feed.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Edge
|
||||||
|
module Feed
|
||||||
|
def feed(params = {})
|
||||||
|
posts = self.edge :feed, params
|
||||||
|
posts.collect do |post|
|
||||||
|
Post.new(post[:id], post).authenticate self.access_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,9 +24,5 @@ module FbGraph2
|
||||||
assign attributes
|
assign attributes
|
||||||
# TODO: handle custom attributes.
|
# TODO: handle custom attributes.
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.me(access_token)
|
|
||||||
new(:me).authenticate access_token
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
26
lib/fb_graph2/post.rb
Normal file
26
lib/fb_graph2/post.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Post < Node
|
||||||
|
include AttributeAssigner
|
||||||
|
|
||||||
|
register_attributes(
|
||||||
|
raw: [
|
||||||
|
:caption, :description, :icon, :is_hidden, :link, :message, :name, :object_id, :picture,
|
||||||
|
:source, :story
|
||||||
|
],
|
||||||
|
time: [:created_time, :updated_time],
|
||||||
|
application: [:application],
|
||||||
|
page: [:place],
|
||||||
|
profile: [:from],
|
||||||
|
profiles: [:to, :with_tags],
|
||||||
|
custom: [
|
||||||
|
:actions, :message_tags, :privacy, :properties, :shares, :status_type, :type
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def initialize(id, attributes = {})
|
||||||
|
super
|
||||||
|
assign attributes
|
||||||
|
# TODO: handle custom attributes.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,6 +4,7 @@ module FbGraph2
|
||||||
|
|
||||||
include Edge::Accounts
|
include Edge::Accounts
|
||||||
include Edge::Friends
|
include Edge::Friends
|
||||||
|
include Edge::Feed
|
||||||
|
|
||||||
register_attributes(
|
register_attributes(
|
||||||
raw: [
|
raw: [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue