diff --git a/lib/fb_graph2/attribute_assigner.rb b/lib/fb_graph2/attribute_assigner.rb index 904cbf3..f698f0f 100644 --- a/lib/fb_graph2/attribute_assigner.rb +++ b/lib/fb_graph2/attribute_assigner.rb @@ -8,6 +8,13 @@ module FbGraph2 cattr_accessor :registered_attributes end + module ClassMethods + def register_attributes(attributes) + self.registered_attributes = attributes + send :attr_accessor, *attributes.values.flatten + end + end + def assign(attributes) self.raw_attributes = attributes self.class.registered_attributes.each do |type, keys| @@ -37,12 +44,5 @@ module FbGraph2 end end end - - module ClassMethods - def register_attributes(attributes) - self.registered_attributes = attributes - send :attr_accessor, *attributes.values.flatten - end - end end end \ No newline at end of file diff --git a/lib/fb_graph2/edge/accounts.rb b/lib/fb_graph2/edge/accounts.rb new file mode 100644 index 0000000..941529c --- /dev/null +++ b/lib/fb_graph2/edge/accounts.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module Accounts + def accounts(params = {}) + pages = self.edge :accounts, params + pages.collect do |page| + Page.new(page[:id], page).authenticate page[:access_token] + end + end + end + end +end \ No newline at end of file diff --git a/lib/fb_graph2/node.rb b/lib/fb_graph2/node.rb index ba17483..1e6cd18 100644 --- a/lib/fb_graph2/node.rb +++ b/lib/fb_graph2/node.rb @@ -1,11 +1,9 @@ module FbGraph2 class Node - include AttributeAssigner attr_accessor :id, :access_token, :raw_attributes def initialize(id, attributes = {}) self.id = id - assign attributes end def authenticate(access_token) diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 55b85f0..6fd450e 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -1,11 +1,15 @@ module FbGraph2 class Page < Node + include AttributeAssigner + register_attributes( raw: [ :about, :attire, :band_members, :booking_agent, :can_post, :category, :checkins, :company_overview, :current_location, :description, :directed_by, :founded, :general_info, :general_manager, :hometown, :is_permanently_closed, :is_published, :is_unclaimed, :likes, :link, :mission, :name, :phone, :press_contact, - :products, :talking_about_count, :username, :website, :were_here_count + :products, :talking_about_count, :username, :website, :were_here_count, + # only within /:user_id/accounts context + :perms ], date: [:birthday], page: [:best_page], @@ -17,6 +21,7 @@ module FbGraph2 def initialize(id, attributes = {}) super + assign attributes # TODO: handle custom attributes. end diff --git a/lib/fb_graph2/user.rb b/lib/fb_graph2/user.rb index 73f9508..f527055 100644 --- a/lib/fb_graph2/user.rb +++ b/lib/fb_graph2/user.rb @@ -1,5 +1,8 @@ module FbGraph2 class User < Node + include AttributeAssigner + + include Edge::Accounts include Edge::Friends register_attributes( @@ -18,6 +21,7 @@ module FbGraph2 def initialize(id, attributes = {}) super + assign attributes # TODO: handle custom attributes. end diff --git a/spec/fb_graph2/user_spec.rb b/spec/fb_graph2/user_spec.rb index e69de29..a038805 100644 --- a/spec/fb_graph2/user_spec.rb +++ b/spec/fb_graph2/user_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe FbGraph2::User do + it do + p FbGraph2::User, FbGraph2::User.registered_attributes + p FbGraph2::Page, FbGraph2::Page.registered_attributes + end +end \ No newline at end of file