1
0
Fork 0
mirror of https://github.com/nov/fb_graph2 synced 2023-03-27 23:22:15 -04:00

handle post custom attributes

ref #9
This commit is contained in:
nov 2014-06-30 16:51:50 +09:00
parent 234234e42f
commit 1372dcc93b
4 changed files with 62 additions and 3 deletions

View file

@ -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

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Privacy < Struct
register_attributes(
raw: [:description, :value, :friends, :allow, :deny]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Property < Struct
register_attributes(
raw: [:name, :text, :href]
)
end
end
end

View file

@ -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