From e8d0d50de270fd9ac0fe562a6e68d32c4da94579 Mon Sep 17 00:00:00 2001 From: nov Date: Sun, 4 May 2014 02:31:44 +0900 Subject: [PATCH] register basic User attribute --- lib/fb_graph2/node.rb | 2 +- lib/fb_graph2/user.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/fb_graph2/node.rb b/lib/fb_graph2/node.rb index b6892f3..3e70c07 100644 --- a/lib/fb_graph2/node.rb +++ b/lib/fb_graph2/node.rb @@ -4,8 +4,8 @@ module FbGraph2 def initialize(id, attributes = {}) self.id = id - self.raw_attributes = attributes self.access_token = attributes[:access_token] + self.raw_attributes = attributes end def fetch(params = {}, options = {}) diff --git a/lib/fb_graph2/user.rb b/lib/fb_graph2/user.rb index 6b9a854..1ab5186 100644 --- a/lib/fb_graph2/user.rb +++ b/lib/fb_graph2/user.rb @@ -1,5 +1,40 @@ module FbGraph2 class User < Node + @@attributes = { + raw: [ + :about, :bio, :email, :first_name, :gender, :installed, :is_verified, :link, :locale, + :middle_name, :name, :name_format, :political, :quotes, :relationship_status, :religion, + :timezone, :third_party_id, :verified, :website + ], + time: [:updated_time], # NOTE: undocumented attribute + date: [:birthday], + custom: [ + :age_range, :context, :cover, :currency, :education, :favorite_athletes, :favorite_teams, + :hometown, :inspirational_people, :languages, :location, :significant_other, :work + ] + } + attr_accessor *@@attributes.values.flatten + + def initialize(id, attributes = {}) + super + @@attributes.each do |type, keys| + keys.each do |key| + raw = attributes[key] + if raw.present? + value = case type + when :raw + raw + when :date + Date.parse raw + when :time + Time.parse raw + end + self.send :"#{key}=", attributes[key] + end + end + end + end + def self.me(access_token) new(:me, access_token: access_token) end