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

Graph API v2.2 - rename Page#admins to Page#roles

(actually not renaming for legacy version support)

close #18
This commit is contained in:
nov 2014-11-01 13:40:59 +09:00
parent e84e28a15f
commit 0c05153fe2
6 changed files with 103 additions and 5 deletions

View file

@ -7,7 +7,7 @@ module FbGraph2
include Edge::Groups
include Edge::Permissions
include Edge::Picture
include Edge::Roles
include Edge::Roles::AppContext
include Edge::Scores
include Edge::StaticResources
include Edge::Subscriptions

View file

@ -1,10 +1,27 @@
module FbGraph2
class Edge
module Roles
def roles(params = {})
roles = self.edge :roles, params
roles.collect! do |role|
Struct::Role.new role
module AppContext
def roles(params = {})
roles = self.edge :roles, params
roles.collect! do |role|
Struct::Role.new role
end
end
end
module PageContext
def roles(*args)
params = args.extract_options!
users = self.edge :roles, params, edge_scope: args.first
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
if args.first.present?
users.first
else
users
end
end
end
end

View file

@ -14,6 +14,7 @@ module FbGraph2
include Edge::Photos
include Edge::Posts
include Edge::PromotablePosts
include Edge::Roles::PageContext
include Edge::Settings
include Edge::Statuses
include Edge::Tagged

View file

@ -17,4 +17,51 @@ describe FbGraph2::Edge::Roles do
end
end
end
context 'included in Page' do
let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') }
describe '#roles' do
it 'should return an Array of FbGraph2::User' do
roles = mock_graph :get, 'page_id/roles', 'page/roles', access_token: 'page_token' do
page.roles
end
roles.should be_instance_of FbGraph2::Edge
roles.should_not be_blank
roles.each do |role|
role.should be_instance_of FbGraph2::User
end
end
context 'when blank' do
it 'should return a blank Array' do
roles = mock_graph :get, 'page_id/roles', 'blank_collection', access_token: 'page_token' do
page.roles
end
roles.should be_instance_of FbGraph2::Edge
roles.should be_blank
end
end
context 'when user context specified' do
let(:user) { FbGraph2::User.new('user_id') }
it 'should return a FbGraph2::User' do
role = mock_graph :get, 'page_id/roles/user_id', 'page/roles_single', access_token: 'page_token' do
page.roles user
end
role.should be_instance_of FbGraph2::User
end
context 'when blank' do
it 'should return nil' do
role = mock_graph :get, 'page_id/roles/user_id', 'blank_collection', access_token: 'page_token' do
page.roles user
end
role.should be_nil
end
end
end
end
end
end

View file

@ -0,0 +1,19 @@
{
"data": [{
"id": "10101078259835569",
"name": "Micah Wedemeyer",
"role": "Admin",
"perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"]
}, {
"id": "579612276",
"name": "Nov Matake",
"role": "Admin",
"perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"]
}],
"paging": {
"cursors": {
"before": "MTAxMDEwNzgyNTk4MzU1Njk=",
"after": "NTc5NjEyMjc2"
}
}
}

View file

@ -0,0 +1,14 @@
{
"data": [{
"id": "579612276",
"name": "Nov Matake",
"role": "Admin",
"perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"]
}],
"paging": {
"cursors": {
"before": "MTAxMDEwNzgyNTk4MzU1Njk=",
"after": "NTc5NjEyMjc2"
}
}
}