From bb73e5190a48613d6732c8366906908fe2960b9e Mon Sep 17 00:00:00 2001 From: nov Date: Wed, 28 May 2014 15:45:12 +0900 Subject: [PATCH] reduce "custom" attributes --- lib/fb_graph2/attribute_assigner.rb | 24 ++++++++++++++++++------ lib/fb_graph2/comment.rb | 4 +++- lib/fb_graph2/event.rb | 9 +++------ lib/fb_graph2/group.rb | 8 ++------ lib/fb_graph2/page.rb | 3 ++- lib/fb_graph2/photo.rb | 9 +++++++-- lib/fb_graph2/post.rb | 3 ++- lib/fb_graph2/struct/action.rb | 9 +++++++++ lib/fb_graph2/struct/image_source.rb | 9 +++++++++ lib/fb_graph2/struct/score.rb | 2 +- lib/fb_graph2/user.rb | 3 ++- 11 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 lib/fb_graph2/struct/action.rb create mode 100644 lib/fb_graph2/struct/image_source.rb diff --git a/lib/fb_graph2/attribute_assigner.rb b/lib/fb_graph2/attribute_assigner.rb index 7762372..e58d913 100644 --- a/lib/fb_graph2/attribute_assigner.rb +++ b/lib/fb_graph2/attribute_assigner.rb @@ -30,28 +30,40 @@ module FbGraph2 Time.parse raw when :timestamp Time.at raw + when :actions + Collection.new(raw).collect do |_raw_| + Struct::Action.new _raw_ + end + when :album + Album.new raw[:id], raw when :application Application.new raw[:id], raw + when :comment + Comment.new raw[:id], raw + when :group + Group.new raw[:id], raw + when :image_sources + Collection.new(raw).collect do |_raw_| + Struct::ImageSource.new _raw_ + end when :page Page.new raw[:id], raw when :pages Collection.new(raw).collect do |_raw_| Page.new _raw_[:id], _raw_ end + when :photo + Photo.new raw[:id], raw + when :picture + Struct::Picture.new raw[:data] when :profile as_profile raw when :profiles Collection.new(raw).collect do |_raw_| as_profile _raw_ end - when :application - Application.new raw[:id], raw when :user User.new raw[:id], raw - when :picture - Struct::Picture.new raw[:data] - when :album - Album.new raw[:id], raw else # NOTE: handle these attributes in each class next diff --git a/lib/fb_graph2/comment.rb b/lib/fb_graph2/comment.rb index d011952..cf81bcc 100644 --- a/lib/fb_graph2/comment.rb +++ b/lib/fb_graph2/comment.rb @@ -4,7 +4,9 @@ module FbGraph2 raw: [:can_comment, :can_remove, :comment_count, :like_count, :message, :user_likes], time: [:created_time], user: [:from], - custom: [:attachment, :message_tags, :parent] + comment: [:parent], + profiles: [:message_tags], + custom: [:attachment] ) def initialize(id, attributes = {}) diff --git a/lib/fb_graph2/event.rb b/lib/fb_graph2/event.rb index 0bdf082..16f89e8 100644 --- a/lib/fb_graph2/event.rb +++ b/lib/fb_graph2/event.rb @@ -4,12 +4,9 @@ module FbGraph2 raw: [:description, :is_date_only, :location, :name, :privacy, :ticket_uri, :timezone], time: [:end_time, :start_time, :updated_time], page: [:venue], - custom: [:cover, :owner, :parent_group] + profile: [:owner], + group: [:parent_group], + photo: [:cover] ) - - def initialize(id, attributes = {}) - super - # TODO: handle custom attributes. - end end end \ No newline at end of file diff --git a/lib/fb_graph2/group.rb b/lib/fb_graph2/group.rb index 160978c..a72c655 100644 --- a/lib/fb_graph2/group.rb +++ b/lib/fb_graph2/group.rb @@ -7,12 +7,8 @@ module FbGraph2 :administrator, :bookmark_order, :unread ], time: [:updated_time], - custom: [:cover, :owner, :parent] + profile: [:owner, :parent], + photo: [:cover] ) - - def initialize(id, attributes = {}) - super - # TODO: handle custom attributes. - end end end \ No newline at end of file diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 21448ee..d698fdf 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -12,8 +12,9 @@ module FbGraph2 time: [:created_time], date: [:birthday], page: [:best_page], + photo: [:cover], custom: [ - :category_list, :cover, :context, :hours, :location, :parking, :price_range, :restaurant_services, + :category_list, :context, :hours, :location, :parking, :price_range, :restaurant_services, :restaurant_specialties ] ) diff --git a/lib/fb_graph2/photo.rb b/lib/fb_graph2/photo.rb index abaf13d..6c7d425 100644 --- a/lib/fb_graph2/photo.rb +++ b/lib/fb_graph2/photo.rb @@ -1,12 +1,17 @@ module FbGraph2 class Photo < Node register_attributes( - raw: [:backdated_time_granularity, :height, :icon, :link, :name, :page_story_id, :picture, :position, :source, :width], + raw: [ + :backdated_time_granularity, :height, :icon, :link, :name, :page_story_id, :picture, :position, :source, :width, + # NOTE: as cover photo + :offset_y, :offset_x + ], time: [:backdated_time, :created_time, :updated_time], page: [:place], profile: [:from], album: [:album], - custom: [:images, :name_tags] + image_sources: [:images], + custom: [:name_tags] ) end end \ No newline at end of file diff --git a/lib/fb_graph2/post.rb b/lib/fb_graph2/post.rb index 09b25e2..5fcc60f 100644 --- a/lib/fb_graph2/post.rb +++ b/lib/fb_graph2/post.rb @@ -12,8 +12,9 @@ module FbGraph2 page: [:place], profile: [:from], profiles: [:to, :with_tags], + actions: [:actions], custom: [ - :actions, :message_tags, :privacy, :properties, :shares, :status_type, :type + :message_tags, :privacy, :properties, :shares, :status_type, :type ] ) diff --git a/lib/fb_graph2/struct/action.rb b/lib/fb_graph2/struct/action.rb new file mode 100644 index 0000000..c1c5aa9 --- /dev/null +++ b/lib/fb_graph2/struct/action.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Struct + class Action < Struct + register_attributes( + raw: [:name, :link] + ) + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/struct/image_source.rb b/lib/fb_graph2/struct/image_source.rb new file mode 100644 index 0000000..7c9df8e --- /dev/null +++ b/lib/fb_graph2/struct/image_source.rb @@ -0,0 +1,9 @@ +module FbGraph2 + class Struct + class ImageSource < Struct + register_attributes( + raw: [:height, :source, :width] + ) + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/struct/score.rb b/lib/fb_graph2/struct/score.rb index 41ef8f2..c03dcb7 100644 --- a/lib/fb_graph2/struct/score.rb +++ b/lib/fb_graph2/struct/score.rb @@ -1,6 +1,6 @@ module FbGraph2 class Struct - class Poke < Struct + class Score < Struct register_attributes( raw: [:score], user: [:user], diff --git a/lib/fb_graph2/user.rb b/lib/fb_graph2/user.rb index f8630e2..d848a20 100644 --- a/lib/fb_graph2/user.rb +++ b/lib/fb_graph2/user.rb @@ -43,7 +43,8 @@ module FbGraph2 page: [:hometown, :location], pages: [:favorite_athletes, :favorite_teams, :inspirational_people, :languages], user: [:significant_other], - custom: [:age_range, :context, :cover, :currency, :education, :work] + photo: [:cover], + custom: [:age_range, :context, :currency, :education, :work] ) def initialize(id, attributes = {})