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

register basic User attribute

This commit is contained in:
nov 2014-05-04 02:31:44 +09:00
parent 0383c1ef66
commit e8d0d50de2
2 changed files with 36 additions and 1 deletions

View file

@ -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 = {})

View file

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