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:
parent
6b6fb17034
commit
db9aafa73b
13 changed files with 162 additions and 5 deletions
|
@ -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
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
9
lib/fb_graph2/message.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Message < Node
|
||||||
|
register_attributes(
|
||||||
|
raw: [:message],
|
||||||
|
time: [:created_time],
|
||||||
|
profile: [:from]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -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
9
lib/fb_graph2/order.rb
Normal 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
16
lib/fb_graph2/payment.rb
Normal 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
|
8
lib/fb_graph2/place_tag.rb
Normal file
8
lib/fb_graph2/place_tag.rb
Normal 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
10
lib/fb_graph2/request.rb
Normal 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
10
lib/fb_graph2/review.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Review < Node
|
||||||
|
register_attributes(
|
||||||
|
raw: [:message, :rating],
|
||||||
|
time: [:created_time],
|
||||||
|
app: [:to],
|
||||||
|
user: [:from]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
39
lib/fb_graph2/struct/app_link.rb
Normal file
39
lib/fb_graph2/struct/app_link.rb
Normal 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
10
lib/fb_graph2/thread.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module FbGraph2
|
||||||
|
class Thread < Node
|
||||||
|
register_attributes(
|
||||||
|
raw: [:unread, :unseen],
|
||||||
|
time: [:updated_time],
|
||||||
|
profiles: [:to],
|
||||||
|
messages: [:comments]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue