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

app edges

This commit is contained in:
nov 2014-06-05 18:29:48 +09:00
parent 46458a0a23
commit 5e4a703956
21 changed files with 246 additions and 5 deletions

View file

@ -1,5 +1,18 @@
module FbGraph2
class App < Node
include Edge::Achievements
include Edge::AppLinkHosts
include Edge::AppEventTypes
include Edge::Banned
include Edge::Groups
include Edge::Picture
include Edge::Roles
include Edge::Scores
include Edge::StaticResources
include Edge::Subscriptions
include Edge::TestUsers
include Edge::Translations
register_attributes(
raw: [
:id, :android_key_hash, :app_domains, :auth_dialog_data_help_url, :auth_dialog_headline,

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module AppEventTypes
def app_event_types(params = {})
types = self.edge :app_event_types, params
types.collect do |type|
Struct::AppEventType.new type
end
end
end
end
end

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module AppLinkHosts
def app_link_hosts(params = {})
hosts = self.edge :app_link_hosts, params
hosts.collect do |host|
AppLinkHost.new(hosts[:id], hosts).authenticate self.access_token
end
end
end
end
end

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module Banned
def banned(params = {})
users = self.edge :banned, params
users.collect do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
end
end
end

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module Roles
def roles(params = {})
roles = self.edge :roles, params
roles.collect do |role|
Struct::Role.new role
end
end
end
end
end

View file

@ -0,0 +1,13 @@
module FbGraph2
class Edge
module StaticResources
def static_resources(params = {})
resources = self.edge :staticresources, params
resources.collect do |resource|
Struct::StaticResource.new resource
end
end
alias_method :staticresources, :static_resources
end
end
end

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module Subscriptions
def subscriptions(params = {})
subscriptions = self.edge :subscriptions, params
subscriptions.collect do |subscription|
Struct::Subscription.new subscription
end
end
end
end
end

View file

@ -0,0 +1,12 @@
module FbGraph2
class Edge
module TestUsers
def test_users(params = {})
users = self.edge :accounts, params, edge_scope: :'test-users'
users.collect do |user|
User.new(user[:id], user)
end
end
end
end
end

View file

@ -0,0 +1,17 @@
module FbGraph2
class Edge
module Translations
def translations(params = {})
translations = self.edge :translations, params
translations.collect do |translation|
Translation.new(translation[:id], translation).authenticate self.authenticate
end
end
def translation!(params = {})
self.post params, edge: :translations
end
alias_method :translate!, :translation!
end
end
end

View file

@ -10,6 +10,7 @@ module FbGraph2
def initialize(id, attributes = {})
self.id = id
assign attributes if respond_to? :assign
authenticate attributes[:access_token] if attributes.include? :access_token
end
def authenticate(access_token)

View file

@ -0,0 +1,25 @@
module FbGraph2
class Struct
class AppEventType < Struct
register_attributes(
raw: [:event_name, :display_name, :description],
custom: [:parameters]
)
class Parameter < Struct
register_attributes(
raw: [:parameter_name, :display_name, :description]
)
end
def initialize(attributes = {})
super
if attributes.include? :parameters
self.parameters = Collection.new(attributes[:parameters]).collect do |param|
Parameter.new param
end
end
end
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Role < Struct
register_attributes(
raw: [:app_id, :user, :role]
)
end
end
end

View file

@ -0,0 +1,17 @@
module FbGraph2
class Struct
class StaticResource < Struct
register_attributes(
raw: [:usage_stats, :prefetched_resources],
custom: [:https]
)
def initialize(attributes = {})
super
if attributes.include? :https
self.https = self.class.new attributes[:https]
end
end
end
end
end

View file

@ -0,0 +1,9 @@
module FbGraph2
class Struct
class Subscription < Struct
register_attributes(
raw: [:object, :callback_url, :fields, :active]
)
end
end
end

View file

@ -0,0 +1,7 @@
module FbGraph2
class Translation < Node
register_attributes(
raw: [:translation, :approval_status, :native_string, :description]
)
end
end

View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe FbGraph2::Edge::Subscriptions do
context 'included in App' do
describe '#subscriptions' do
let(:app) { FbGraph2::App.app('app_token') }
it 'should return an Array of FbGraph2::Struct::Subscription' do
subscriptions = mock_graph :get, 'app/subscriptions', 'app/subscriptions', access_token: 'app_token' do
app.subscriptions
end
subscriptions.should_not be_blank
subscriptions.each do |subscription|
subscription.should be_instance_of FbGraph2::Struct::Subscription
end
end
end
end
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe FbGraph2::Edge::TestUsers do
context 'included in App' do
describe '#test_users' do
let(:app) { FbGraph2::App.app('app_token') }
it 'should return an Array of FbGraph2::User with test_user token' do
users = mock_graph :get, 'app/accounts/test-users', 'app/test_users', access_token: 'app_token' do
app.test_users
end
users.should_not be_blank
users.each do |user|
user.should be_instance_of FbGraph2::User
user.access_token.should == 'test_user_token'
end
end
end
end
end

View file

@ -1,5 +0,0 @@
require 'spec_helper'
describe FbGraph2::Page do
it :TODO
end

View file

@ -8,6 +8,7 @@ describe FbGraph2 do
its(:logger) { should be_a Logger }
its(:api_version) { should == 'v2.0' }
its(:root_url) { should == 'https://graph.facebook.com/v2.0' }
its(:object_classes) { should contain_exactly *FbGraph2::Node.subclasses }
it { should_not be_debugging }
end

View file

@ -0,0 +1,8 @@
{
"data": [{
"object": "user",
"callback_url": "http://fbgraphsample.heroku.com/subscriptions/7",
"fields": ["email"],
"active": true
}]
}

View file

@ -0,0 +1,17 @@
{
"data": [{
"id": "100003934202581",
"login_url": "https://developers.facebook.com/checkpoint/test-user-login/100003934202581/",
"access_token": "test_user_token"
}, {
"id": "100003888272508",
"login_url": "https://developers.facebook.com/checkpoint/test-user-login/100003888272508/",
"access_token": "test_user_token"
}],
"paging": {
"cursors": {
"before": "MTAwMDAzOTM0MjAyNTgx",
"after": "MTAwMDAzODg4MjcyNTA4"
}
}
}