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

add remaining basic objects

This commit is contained in:
nov 2014-06-04 17:54:22 +09:00
parent 6b6fb17034
commit db9aafa73b
13 changed files with 162 additions and 5 deletions

View file

@ -0,0 +1,35 @@
module FbGraph2
class AppLinkHost < Node
register_attributes(
raw: [:name, :canonical_url],
custom: [:ios, :iphone, :ipad, :android, :windows_phone, :web]
)
def initialize(id, attributes = {})
super
[:ios, :iphone, :ipad, :android, :windows_phone].each do |link_attr|
if attributes.include? link_attr
self.send :"#{link_attr}=", collect_links(attributes, link_attr)
end
end
end
private
def collect_links(attributes, link_attr)
Collection.new(attributes[link_attr]).collect do |link|
klass = case link_attr
when :ios, :iphone, :ipad
Struct::AppLink::Native::IOS
when :android
Struct::AppLink::Native::Android
when :windows_phone
Struct::AppLink::Native::WindowsPhone
else
raise 'Unknown AppLink Type'
end
klass.new link
end
end
end
end

View file

@ -46,6 +46,10 @@ module FbGraph2
Collection.new(raw).collect do |_raw_| Collection.new(raw).collect do |_raw_|
Struct::ImageSource.new _raw_ Struct::ImageSource.new _raw_
end end
when :messages
Collection.new(raw).collect do |_raw_|
Message.new _raw_[:id], _raw_
end
when :page when :page
Page.new raw[:id], raw Page.new raw[:id], raw
when :pages when :pages
@ -77,12 +81,15 @@ module FbGraph2
private private
def as_profile(raw) def as_profile(raw)
klass = if raw.include?(:namespace) klass = if raw.include? :namespace
App App
elsif raw.include?(:category) elsif raw.include? :category
Page Page
elsif raw.include? :start_time
Event
elsif raw.include? :owner
Group
else else
# TODO: needs to handle Event and Group here.
User User
end end
klass.new raw[:id], raw klass.new raw[:id], raw

View file

@ -3,7 +3,7 @@ module FbGraph2
module Comments module Comments
def assign(attributes) def assign(attributes)
super super
if attributes.include?(:comments) if attributes.include? :comments
@_cached_comments = Collection.new attributes[:comments] @_cached_comments = Collection.new attributes[:comments]
end end
end end

View file

@ -18,7 +18,7 @@ module FbGraph2
module LikeeContext module LikeeContext
def assign(attributes) def assign(attributes)
super super
if attributes.include?(:likes) if attributes.include? :likes
@_cached_likes = Collection.new attributes[:likes] @_cached_likes = Collection.new attributes[:likes]
end end
end end

9
lib/fb_graph2/message.rb Normal file
View file

@ -0,0 +1,9 @@
module FbGraph2
class Message < Node
register_attributes(
raw: [:message],
time: [:created_time],
profile: [:from]
)
end
end

View file

@ -43,6 +43,10 @@ module FbGraph2
end.collect(&:instance_methods).sort end.collect(&:instance_methods).sort
end end
def update(params = {}, options = {})
post params, options
end
def destroy(params = {}, options = {}) def destroy(params = {}, options = {})
delete params, options delete params, options
end end

9
lib/fb_graph2/order.rb Normal file
View file

@ -0,0 +1,9 @@
module FbGraph2
class Order < Node
register_attributes(
raw: [:amount, :country, :from, :refund_reason_code, :status],
time: [:created_time, :updated_time],
app: [:application]
)
end
end

16
lib/fb_graph2/payment.rb Normal file
View file

@ -0,0 +1,16 @@
module FbGraph2
class Payment < Node
register_attributes(
raw: [:product, :quantity, :request_id, :country, :created_time, :payout_foreign_exchange_rate, :test],
time: [:created_time, :updated_time],
user: [:user],
app: [:application],
custom: [:actions, :items, :disputes]
)
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
end
end
end

View file

@ -0,0 +1,8 @@
module FbGraph2
class PlaceTag < Node
register_attributes(
time: [:created_time],
page: [:place]
)
end
end

10
lib/fb_graph2/request.rb Normal file
View file

@ -0,0 +1,10 @@
module FbGraph2
class Request < Node
register_attributes(
raw: [:message],
time: [:created_time],
app: [:application],
user: [:to, :from]
)
end
end

10
lib/fb_graph2/review.rb Normal file
View file

@ -0,0 +1,10 @@
module FbGraph2
class Review < Node
register_attributes(
raw: [:message, :rating],
time: [:created_time],
app: [:to],
user: [:from]
)
end
end

View file

@ -0,0 +1,39 @@
module FbGraph2
class Struct
class AppLink < Struct
register_attributes(
raw: [:url]
)
class Native < AppLink
register_attributes(
raw: [:app_name]
)
class IOS < Native
register_attributes(
raw: [:app_store_id]
)
end
class Android < Native
register_attributes(
raw: [:class, :package]
)
end
class WindowsPhone < Native
register_attributes(
raw: [:app_name]
)
end
end
class Web < AppLink
register_attributes(
raw: [:should_fallback]
)
end
end
end
end

10
lib/fb_graph2/thread.rb Normal file
View file

@ -0,0 +1,10 @@
module FbGraph2
class Thread < Node
register_attributes(
raw: [:unread, :unseen],
time: [:updated_time],
profiles: [:to],
messages: [:comments]
)
end
end