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

page custom attributes done

This commit is contained in:
nov 2014-06-11 16:27:04 +09:00
parent 32904ec333
commit 968cab225d
9 changed files with 82 additions and 22 deletions

View file

@ -24,6 +24,8 @@ module FbGraph2
value = case type
when :raw
raw
when :int_flag
raw == 1
when :date
Date.strptime raw, '%m/%d/%Y' rescue raw
when :time

View file

@ -21,9 +21,9 @@ module FbGraph2
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,
:current_location, :description, :directed_by, :founded, :general_info, :general_manager, :hometown, :hours,
:is_permanently_closed, :is_published, :is_unclaimed, :likes, :link, :mission, :name, :phone, :press_contact,
:products, :talking_about_count, :username, :website, :were_here_count,
:price_range, :products, :talking_about_count, :username, :website, :were_here_count,
# NOTE: only within /:user_id/accounts context
:perms
],
@ -40,8 +40,9 @@ module FbGraph2
:with
],
custom: [
:category_list, :context, :hours, :location, :parking, :price_range, :restaurant_services,
:restaurant_specialties
:category_list, :context, :location, :parking, :restaurant_services, :restaurant_specialties,
# NOTE: undocumented
:payment_options
]
)
@ -52,7 +53,24 @@ module FbGraph2
PageCategory.new page_category[:id], page_category
end
end
# TODO: handle other custom attributes.
if attributes.include? :context
self.context = Struct::Context::PageContext.new attributes[:context]
end
if attributes.include? :location
self.location = Struct::Location.new attributes[:location]
end
if attributes.include? :parking
self.parking = Struct::Parking.new attributes[:parking]
end
if attributes.include? :restaurant_services
self.restaurant_services = Struct::RestaurantServices.new attributes[:restaurant_services]
end
if attributes.include? :restaurant_specialties
self.restaurant_specialties = Struct::RestaurantSpecialties.new attributes[:restaurant_specialties]
end
if attributes.include? :payment_options
self.payment_options = Struct::PaymentOptions.new attributes[:payment_options]
end
end
end
end

View file

@ -1,21 +1,17 @@
module FbGraph2
class Struct
class Context < Struct
module Context
class UserContext < Struct
register_attributes(
custom: [:mutual_friends, :mutual_likes]
users: [:mutual_friends],
pages: [:mutual_likes]
)
end
def initialize(attributes = {})
if attributes.include? :mutual_friends
self.mutual_friends = Collection.new(attributes[:mutual_friends]).collect do |user|
User.new user[:id], user
end
end
if attributes.include? :mutual_likes
self.mutual_likes = Collection.new(attributes[:mutual_likes]).collect do |page|
Page.new page[:id], page
end
end
class PageContext < Struct
register_attributes(
users: [:friends_who_like, :friends_tagged_at, :music_listen_friends, :video_watch_friends]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Location < Struct
register_attributes(
raw: [:country, :city, :longitude, :zip, :state, :street, :located_in, :latitude]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Parking < Struct
register_attributes(
int_flag: [:street, :lot, :valet]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class PaymentOptions < Struct
register_attributes(
int_flag: [:amex, :cash_only, :discover, :mastercard, :visa]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class RestaurantServices < Struct
register_attributes(
int_flag: [:kids, :delivery, :walkins, :catering, :reserve, :groups, :waiter, :outdoor, :takeout]
)
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class RestaurantSpecialties < Struct
register_attributes(
int_flag: [:coffee, :drinks, :breakfast, :dinner, :lunch]
)
end
end
end

View file

@ -69,12 +69,11 @@ module FbGraph2
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
if attributes.include? :age_range
self.age_range = Struct::AgeRange.new attributes[:age_range]
end
if attributes.include? :context
self.context = Struct::Context.new attributes[:context]
self.context = Struct::Context::UserContext.new attributes[:context]
end
if attributes.include? :currency
self.currency = Struct::Currency.new attributes[:currency]