From db9aafa73ba6550281c79a5e08a6429f97caa94c Mon Sep 17 00:00:00 2001 From: nov Date: Wed, 4 Jun 2014 17:54:22 +0900 Subject: [PATCH] add remaining basic objects --- lib/fb_graph2/app_link_host.rb | 35 ++++++++++++++++++++++++++ lib/fb_graph2/attribute_assigner.rb | 13 +++++++--- lib/fb_graph2/edge/comments.rb | 2 +- lib/fb_graph2/edge/likes.rb | 2 +- lib/fb_graph2/message.rb | 9 +++++++ lib/fb_graph2/node.rb | 4 +++ lib/fb_graph2/order.rb | 9 +++++++ lib/fb_graph2/payment.rb | 16 ++++++++++++ lib/fb_graph2/place_tag.rb | 8 ++++++ lib/fb_graph2/request.rb | 10 ++++++++ lib/fb_graph2/review.rb | 10 ++++++++ lib/fb_graph2/struct/app_link.rb | 39 +++++++++++++++++++++++++++++ lib/fb_graph2/thread.rb | 10 ++++++++ 13 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 lib/fb_graph2/message.rb create mode 100644 lib/fb_graph2/order.rb create mode 100644 lib/fb_graph2/payment.rb create mode 100644 lib/fb_graph2/place_tag.rb create mode 100644 lib/fb_graph2/request.rb create mode 100644 lib/fb_graph2/review.rb create mode 100644 lib/fb_graph2/struct/app_link.rb create mode 100644 lib/fb_graph2/thread.rb diff --git a/lib/fb_graph2/app_link_host.rb b/lib/fb_graph2/app_link_host.rb index e69de29..286a922 100644 --- a/lib/fb_graph2/app_link_host.rb +++ b/lib/fb_graph2/app_link_host.rb @@ -0,0 +1,35 @@ +module FbGraph2 + class AppLinkHost < Node + register_attributes( + raw: [:name, :canonical_url], + custom: [:ios, :iphone, :ipad, :android, :windows_phone, :web] + ) + + def initialize(id, attributes = {}) + super + [:ios, :iphone, :ipad, :android, :windows_phone].each do |link_attr| + if attributes.include? link_attr + self.send :"#{link_attr}=", collect_links(attributes, link_attr) + end + end + end + + private + + def collect_links(attributes, link_attr) + Collection.new(attributes[link_attr]).collect do |link| + klass = case link_attr + when :ios, :iphone, :ipad + Struct::AppLink::Native::IOS + when :android + Struct::AppLink::Native::Android + when :windows_phone + Struct::AppLink::Native::WindowsPhone + else + raise 'Unknown AppLink Type' + end + klass.new link + end + 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 425b13b..3e71796 100644 --- a/lib/fb_graph2/attribute_assigner.rb +++ b/lib/fb_graph2/attribute_assigner.rb @@ -46,6 +46,10 @@ module FbGraph2 Collection.new(raw).collect do |_raw_| Struct::ImageSource.new _raw_ end + when :messages + Collection.new(raw).collect do |_raw_| + Message.new _raw_[:id], _raw_ + end when :page Page.new raw[:id], raw when :pages @@ -77,12 +81,15 @@ module FbGraph2 private def as_profile(raw) - klass = if raw.include?(:namespace) + klass = if raw.include? :namespace App - elsif raw.include?(:category) + elsif raw.include? :category Page + elsif raw.include? :start_time + Event + elsif raw.include? :owner + Group else - # TODO: needs to handle Event and Group here. User end klass.new raw[:id], raw diff --git a/lib/fb_graph2/edge/comments.rb b/lib/fb_graph2/edge/comments.rb index 45e1c24..1e06b5c 100644 --- a/lib/fb_graph2/edge/comments.rb +++ b/lib/fb_graph2/edge/comments.rb @@ -3,7 +3,7 @@ module FbGraph2 module Comments def assign(attributes) super - if attributes.include?(:comments) + if attributes.include? :comments @_cached_comments = Collection.new attributes[:comments] end end diff --git a/lib/fb_graph2/edge/likes.rb b/lib/fb_graph2/edge/likes.rb index 2575a7c..e61b3df 100644 --- a/lib/fb_graph2/edge/likes.rb +++ b/lib/fb_graph2/edge/likes.rb @@ -18,7 +18,7 @@ module FbGraph2 module LikeeContext def assign(attributes) super - if attributes.include?(:likes) + if attributes.include? :likes @_cached_likes = Collection.new attributes[:likes] end end diff --git a/lib/fb_graph2/message.rb b/lib/fb_graph2/message.rb new file mode 100644 index 0000000..5ca9c3c --- /dev/null +++ b/lib/fb_graph2/message.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Message < Node + register_attributes( + raw: [:message], + time: [:created_time], + profile: [:from] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/node.rb b/lib/fb_graph2/node.rb index 8fa38de..73f11cb 100644 --- a/lib/fb_graph2/node.rb +++ b/lib/fb_graph2/node.rb @@ -43,6 +43,10 @@ module FbGraph2 end.collect(&:instance_methods).sort end + def update(params = {}, options = {}) + post params, options + end + def destroy(params = {}, options = {}) delete params, options end diff --git a/lib/fb_graph2/order.rb b/lib/fb_graph2/order.rb new file mode 100644 index 0000000..b3695a6 --- /dev/null +++ b/lib/fb_graph2/order.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Order < Node + register_attributes( + raw: [:amount, :country, :from, :refund_reason_code, :status], + time: [:created_time, :updated_time], + app: [:application] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/payment.rb b/lib/fb_graph2/payment.rb new file mode 100644 index 0000000..9e6903b --- /dev/null +++ b/lib/fb_graph2/payment.rb @@ -0,0 +1,16 @@ +module FbGraph2 + class Payment < Node + register_attributes( + raw: [:product, :quantity, :request_id, :country, :created_time, :payout_foreign_exchange_rate, :test], + time: [:created_time, :updated_time], + user: [:user], + app: [:application], + custom: [:actions, :items, :disputes] + ) + + def initialize(id, attributes = {}) + super + # TODO: handle custom attributes. + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/place_tag.rb b/lib/fb_graph2/place_tag.rb new file mode 100644 index 0000000..b4ca6ce --- /dev/null +++ b/lib/fb_graph2/place_tag.rb @@ -0,0 +1,8 @@ +module FbGraph2 + class PlaceTag < Node + register_attributes( + time: [:created_time], + page: [:place] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/request.rb b/lib/fb_graph2/request.rb new file mode 100644 index 0000000..578be77 --- /dev/null +++ b/lib/fb_graph2/request.rb @@ -0,0 +1,10 @@ +module FbGraph2 + class Request < Node + register_attributes( + raw: [:message], + time: [:created_time], + app: [:application], + user: [:to, :from] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/review.rb b/lib/fb_graph2/review.rb new file mode 100644 index 0000000..f5b9fa5 --- /dev/null +++ b/lib/fb_graph2/review.rb @@ -0,0 +1,10 @@ +module FbGraph2 + class Review < Node + register_attributes( + raw: [:message, :rating], + time: [:created_time], + app: [:to], + user: [:from] + ) + end +end \ No newline at end of file diff --git a/lib/fb_graph2/struct/app_link.rb b/lib/fb_graph2/struct/app_link.rb new file mode 100644 index 0000000..7ebf2f8 --- /dev/null +++ b/lib/fb_graph2/struct/app_link.rb @@ -0,0 +1,39 @@ +module FbGraph2 + class Struct + class AppLink < Struct + register_attributes( + raw: [:url] + ) + + class Native < AppLink + register_attributes( + raw: [:app_name] + ) + + class IOS < Native + register_attributes( + raw: [:app_store_id] + ) + end + + class Android < Native + register_attributes( + raw: [:class, :package] + ) + end + + class WindowsPhone < Native + register_attributes( + raw: [:app_name] + ) + end + end + + class Web < AppLink + register_attributes( + raw: [:should_fallback] + ) + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/thread.rb b/lib/fb_graph2/thread.rb new file mode 100644 index 0000000..54f4763 --- /dev/null +++ b/lib/fb_graph2/thread.rb @@ -0,0 +1,10 @@ +module FbGraph2 + class Thread < Node + register_attributes( + raw: [:unread, :unseen], + time: [:updated_time], + profiles: [:to], + messages: [:comments] + ) + end +end \ No newline at end of file