From 1372dcc93bdb0e1ad80095a3694741549a2921aa Mon Sep 17 00:00:00 2001 From: nov Date: Mon, 30 Jun 2014 16:51:50 +0900 Subject: [PATCH] handle post custom attributes ref #9 --- lib/fb_graph2/post.rb | 21 ++++++++++++++++++--- lib/fb_graph2/struct/privacy.rb | 9 +++++++++ lib/fb_graph2/struct/property.rb | 9 +++++++++ lib/fb_graph2/tagged_profile.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 lib/fb_graph2/struct/privacy.rb create mode 100644 lib/fb_graph2/struct/property.rb create mode 100644 lib/fb_graph2/tagged_profile.rb diff --git a/lib/fb_graph2/post.rb b/lib/fb_graph2/post.rb index 235d547..57e9820 100644 --- a/lib/fb_graph2/post.rb +++ b/lib/fb_graph2/post.rb @@ -7,7 +7,7 @@ module FbGraph2 register_attributes( raw: [ :caption, :description, :icon, :is_hidden, :link, :message, :name, :object_id, :picture, - :source, :story + :source, :status_type, :story, :type ], time: [:created_time, :updated_time], app: [:application], @@ -16,13 +16,28 @@ module FbGraph2 profiles: [:to, :with_tags], actions: [:actions], custom: [ - :message_tags, :privacy, :properties, :shares, :status_type, :type + :message_tags, :privacy, :properties ] ) def initialize(id, attributes = {}) super - # TODO: handle custom attributes. + if attributes.include? :message_tags + self.message_tags = attributes[:message_tags].inject({}) do |message_tags, (key, values)| + _message_tags_ = values.collect do |value| + TaggedProfile.new value[:id], value + end + message_tags.merge! key => _message_tags_ + end + end + if attributes.include? :privacy + self.privacy = Struct::Privacy.new attributes[:privacy] + end + if attributes.include? :properties + self.properties = attributes[:properties].collect do |property| + Struct::Property.new property + end + end end end end \ No newline at end of file diff --git a/lib/fb_graph2/struct/privacy.rb b/lib/fb_graph2/struct/privacy.rb new file mode 100644 index 0000000..4d81b21 --- /dev/null +++ b/lib/fb_graph2/struct/privacy.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Struct + class Privacy < Struct + register_attributes( + raw: [:description, :value, :friends, :allow, :deny] + ) + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/struct/property.rb b/lib/fb_graph2/struct/property.rb new file mode 100644 index 0000000..202218e --- /dev/null +++ b/lib/fb_graph2/struct/property.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Struct + class Property < Struct + register_attributes( + raw: [:name, :text, :href] + ) + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/tagged_profile.rb b/lib/fb_graph2/tagged_profile.rb new file mode 100644 index 0000000..ab52328 --- /dev/null +++ b/lib/fb_graph2/tagged_profile.rb @@ -0,0 +1,26 @@ +module FbGraph2 + class TaggedProfile < Node + register_attributes( + raw: [:id, :name, :type, :offset, :length], + custom: [:object] + ) + + def initialize(id, attributes = {}) + super + self.object = klass.new self.id + end + + def klass + klass = case self.type + when 'user' + User + when 'page' + Page + when 'group' + Group + when 'event' + Event + end + end + end +end \ No newline at end of file