From 02f066c357747765ca6e48bdf76dc1f0d12186d9 Mon Sep 17 00:00:00 2001 From: nov Date: Mon, 5 May 2014 20:30:11 +0900 Subject: [PATCH] "profile" object handling --- lib/fb_graph2/application.rb | 30 +++++++++++++++++++++++++++++ lib/fb_graph2/attribute_assigner.rb | 26 +++++++++++++++++++++++-- lib/fb_graph2/edge/feed.rb | 12 ++++++++++++ lib/fb_graph2/page.rb | 4 ---- lib/fb_graph2/post.rb | 26 +++++++++++++++++++++++++ lib/fb_graph2/user.rb | 1 + 6 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 lib/fb_graph2/application.rb create mode 100644 lib/fb_graph2/edge/feed.rb create mode 100644 lib/fb_graph2/post.rb diff --git a/lib/fb_graph2/application.rb b/lib/fb_graph2/application.rb new file mode 100644 index 0000000..0a61186 --- /dev/null +++ b/lib/fb_graph2/application.rb @@ -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 \ No newline at end of file diff --git a/lib/fb_graph2/attribute_assigner.rb b/lib/fb_graph2/attribute_assigner.rb index f698f0f..679fd04 100644 --- a/lib/fb_graph2/attribute_assigner.rb +++ b/lib/fb_graph2/attribute_assigner.rb @@ -28,21 +28,43 @@ module FbGraph2 Date.parse raw when :time Time.parse raw + when :timestamp + Time.at raw + when :application + Application.new raw[:id], raw when :page Page.new raw[:id], raw when :pages - raw.each do |_raw_| + Collection.new(raw).each do |_raw_| Page.new _raw_[:id], _raw_ end + when :profile + as_profile raw + when :profiles + Collection.new(raw).each do |_raw_| + as_profile _raw_ + end when :user User.new raw[:id], raw when :custom # NOTE: handle custom attributes in each class end - self.send :"#{key}=", attributes[key] + self.send :"#{key}=", value 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 \ No newline at end of file diff --git a/lib/fb_graph2/edge/feed.rb b/lib/fb_graph2/edge/feed.rb new file mode 100644 index 0000000..7ec81dc --- /dev/null +++ b/lib/fb_graph2/edge/feed.rb @@ -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 \ No newline at end of file diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 6fd450e..e39252d 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -24,9 +24,5 @@ module FbGraph2 assign attributes # TODO: handle custom attributes. end - - def self.me(access_token) - new(:me).authenticate access_token - end end end \ No newline at end of file diff --git a/lib/fb_graph2/post.rb b/lib/fb_graph2/post.rb new file mode 100644 index 0000000..2ad36df --- /dev/null +++ b/lib/fb_graph2/post.rb @@ -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 \ No newline at end of file diff --git a/lib/fb_graph2/user.rb b/lib/fb_graph2/user.rb index f527055..1913dea 100644 --- a/lib/fb_graph2/user.rb +++ b/lib/fb_graph2/user.rb @@ -4,6 +4,7 @@ module FbGraph2 include Edge::Accounts include Edge::Friends + include Edge::Feed register_attributes( raw: [