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

fixed a bug with parsing message_tags

This commit is contained in:
Bryan Brunetti 2017-05-30 12:59:03 -04:00
parent 24f6fa5dca
commit 977a4196c2
290 changed files with 27 additions and 8033 deletions

View file

@ -1,24 +0,0 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.bundle
*.so
*.o
*.a
mkmf.log
wiki
samples

View file

@ -1,2 +0,0 @@
--color
--format=documentation

View file

@ -1,3 +0,0 @@
rvm:
- 2.0.0
- 2.1.2

View file

@ -1,4 +0,0 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in fb_graph2.gemspec
gemspec

View file

@ -1,22 +0,0 @@
Copyright (c) 2014 nov matake
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,29 +0,0 @@
# FbGraph2
Similar to [fb_graph gem](https://github.com/nov/fb_graph), but supports Graph API v2.0+.
## Installation
Add this line to your application's Gemfile:
gem 'fb_graph2'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fb_graph2
## Usage
See [fb_graph2 Wiki](https://github.com/nov/fb_graph2/wiki).
## Contributing
1. Fork it ( https://github.com/[my-github-username]/fb_graph2/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

View file

@ -1,18 +0,0 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
namespace :coverage do
desc 'Open coverage report'
task :report do
require 'simplecov'
`open '#{File.join SimpleCov.coverage_path, 'index.html'}'`
end
end
task :spec do
Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
end
task default: :spec

View file

@ -1 +0,0 @@
0.5.0

View file

@ -1,26 +0,0 @@
Gem::Specification.new do |gem|
gem.name = 'fb_graph2'
gem.version = File.read('VERSION').delete("\n\r")
gem.authors = ['nov matake']
gem.email = ['nov@matake.jp']
gem.summary = %q{Facebook Graph API v2.0 Wrapper in Ruby}
gem.description = %q{Facebook Graph API v2.0 Wrapper in Ruby}
gem.homepage = 'https://github.com/nov/fb_graph2'
gem.license = 'MIT'
gem.files = `git ls-files -z`.split("\x0")
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
gem.require_paths = ['lib']
gem.add_runtime_dependency 'httpclient', '>= 2.4'
gem.add_runtime_dependency 'rack-oauth2', '>= 1.0'
gem.add_runtime_dependency 'url_safe_base64'
gem.add_runtime_dependency 'multi_json'
gem.add_runtime_dependency 'activesupport', '>= 3.2'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'webmock'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'rspec-its'
end

View file

@ -1,56 +0,0 @@
require 'active_support'
require 'active_support/core_ext'
require 'rack/oauth2'
module FbGraph2
mattr_accessor :root_url, :api_version, :gem_version, :logger, :debugging, :_http_config_, :object_classes
self.root_url = 'https://graph.facebook.com'
self.api_version = 'v2.0'
self.gem_version = File.read(File.join(__dir__, '../VERSION')).delete("\n\r")
self.logger = Logger.new(STDOUT)
self.logger.progname = 'FbGraph2'
self.object_classes = Array.new
class << self
def debugging?
!!self.debugging
end
def debug!
Rack::OAuth2.debug!
self.debugging = true
end
def http_client(access_token = nil)
_http_client_ = HTTPClient.new(
agent_name: "FbGraph2 (#{gem_version})"
)
_http_client_.request_filter.delete_if do |filter|
filter.is_a? HTTPClient::WWWAuth
end
_http_client_.request_filter << RequestFilter::Authenticator.new(access_token) if access_token.present?
_http_client_.request_filter << RequestFilter::Debugger.new if self.debugging?
_http_config_.try(:call, _http_client_)
_http_client_
end
def http_config(&block)
Rack::OAuth2.http_config &block unless Rack::OAuth2.http_config
self._http_config_ ||= block
end
end
end
require 'fb_graph2/exception'
require 'fb_graph2/attribute_assigner'
require 'fb_graph2/node'
require 'fb_graph2/collection'
require 'fb_graph2/searchable'
require 'fb_graph2/edge'
[
'.',
'request_filter'
].each do |dir|
Dir[File.join(__dir__, 'fb_graph2', dir, '*.rb')].each do |file|
require file
end
end

View file

@ -1,21 +0,0 @@
module FbGraph2
class Achievement < Node
include Edge::Comments
include Edge::Likes::LikeeContext
register_attributes(
raw: [:type, :no_feed_story],
time: [:publish_time],
app: [:application],
user: [:from],
custom: [:data]
)
def initialize(id, attributes = {})
super
if attributes.include? :data
self.data = attributes[:data]
end
end
end
end

View file

@ -1,11 +0,0 @@
module FbGraph2
class AchievementType < Node
register_attributes(
raw: [:type, :title, :url, :description, :is_scraped],
time: [:updated_time, :created_time],
picture: [:image],
app: [:application],
custom: [:data, :context]
)
end
end

View file

@ -1,16 +0,0 @@
module FbGraph2
class Album < Node
include Edge::Comments
include Edge::Likes::LikeeContext
include Edge::Picture
include Edge::Photos
include Edge::SharedPosts
register_attributes(
raw: [:can_upload, :count, :cover_photo, :description, :link, :location, :name, :privacy, :type],
time: [:created_time, :updated_time],
user: [:from],
page: [:place]
)
end
end

View file

@ -1,45 +0,0 @@
module FbGraph2
class App < Node
include Edge::Achievements
include Edge::AppLinkHosts
include Edge::AppEventTypes
include Edge::Banned
include Edge::Groups
include Edge::Permissions
include Edge::Picture
include Edge::Roles::AppContext
include Edge::Scores
include Edge::StaticResources
include Edge::Subscriptions
include Edge::TestUsers
include Edge::Translations
register_attributes(
raw: [
:android_key_hash, :app_domains, :auth_dialog_data_help_url, :auth_dialog_headline,
:auth_dialog_perms_explanation, :auth_referral_enabled, :auth_referral_extended_perms,
:auth_referral_friend_perms, :auth_referral_user_perms, :canvas_fluid_height, :canvas_fluid_width,
:canvas_url, :category, :company, :contact_email, :creator_uid, :daily_active_users, :daily_active_users_rank,
:deauth_callback_url, :description, :hosting_url, :icon_url, :ios_bundle_id, :iphone_app_store_id,
:link, :logo_url, :mobile_web_url, :monthly_active_users, :monthly_active_users_rank, :name,
:namespace, :page_tab_default_name, :page_tab_url, :privacy_policy_url, :secure_canvas_url,
:secure_page_tab_url, :server_ip_whitelist, :social_discovery, :subcategory, :terms_of_service_url,
:user_support_email, :user_support_url, :website_url, :weekly_active_users
],
timestamp: [:created_time],
custom: [
:auth_referral_default_activity_privacy, :auth_referral_response_type, :context, :migrations,
:object_store_urls, :restrictions
]
)
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
end
def self.app(access_token)
new(:app).authenticate access_token
end
end
end

View file

@ -1,33 +0,0 @@
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
end
klass.new link
end
end
end
end

View file

@ -1,103 +0,0 @@
module FbGraph2
module AttributeAssigner
extend ActiveSupport::Concern
included do
extend ClassMethods
attr_accessor :raw_attributes
cattr_accessor :registered_attributes
end
module ClassMethods
def register_attributes(attributes)
self.registered_attributes = attributes
send :attr_accessor, *attributes.values.flatten
end
end
def assign(attributes)
Array(self.class.registered_attributes).each do |type, keys|
keys.each do |key|
if attributes.include? key
raw = attributes[key]
value = case type
when :raw
raw
when :int_flag
raw == 1
when :date
Date.strptime raw, '%m/%d/%Y' rescue raw
when :time
Time.parse raw rescue raw
when :timestamp
Time.at raw
when :actions
Collection.new(raw).collect! do |_raw_|
Struct::Action.new _raw_
end
when :album
Album.new raw[:id], raw
when :app
App.new raw[:id], raw
when :comment
Comment.new raw[:id], raw
when :group
Group.new raw[:id], raw
when :image_sources
Collection.new(raw).collect! do |_raw_|
Struct::ImageSource.new _raw_
end
when :messages
Collection.new(raw).collect! do |_raw_|
Message.new _raw_[:id], _raw_
end
when :page
Page.new raw[:id], raw
when :pages
Collection.new(raw).collect! do |_raw_|
Page.new _raw_[:id], _raw_
end
when :photo
Photo.new raw[:id], raw
when :picture
Struct::Picture.new raw[:data]
when :profile
as_profile raw
when :profiles
Collection.new(raw).collect! do |_raw_|
as_profile _raw_
end
when :user
User.new raw[:id], raw
when :users
Collection.new(raw).collect! do |_raw_|
User.new _raw_[:id], _raw_
end
else
# NOTE: handle these attributes in each class
next
end
self.send :"#{key}=", value
end
end
end
end
private
def as_profile(raw)
klass = if raw.include? :namespace
App
elsif raw.include? :category
Page
elsif raw.include? :start_time
Event
elsif raw.include? :owner
Group
else
User
end
klass.new raw[:id], raw
end
end
end

View file

@ -1,59 +0,0 @@
module FbGraph2
class Auth < Rack::OAuth2::Client
class Grant
class FbExchangeToken < Rack::OAuth2::Client::Grant
attr_required :fb_exchange_token
end
end
def initialize(client_id, client_secret, options = {})
super options.merge(
identifier: client_id,
secret: client_secret,
host: URI.parse(FbGraph2.root_url).host,
authorization_endpoint: '/oauth/authorize',
token_endpoint: '/oauth/access_token'
)
end
def fb_exchange_token=(access_token)
@grant = Grant::FbExchangeToken.new(
fb_exchange_token: access_token
)
end
def access_token!(options = {})
super options.merge(
client_auth_method: :body
)
rescue Rack::OAuth2::Client::Error => e
raise Exception.detect(e.status, e.response)
end
def debug_token!(input_token)
token_metadata = TokenMetadata.new
token_metadata.authenticate access_token!
token_metadata.fetch(
input_token: input_token.to_s
)
end
def from_cookie(cookie)
token = case cookie
when String
cookie
else
cookie["fbsr_#{identifier}"]
end
from_signed_request token
end
def from_signed_request(token)
SignedRequest.new(token).verify! self
end
end
end
Dir[File.join(__dir__, 'auth/*.rb')].each do |file|
require file
end

View file

@ -1,54 +0,0 @@
module FbGraph2
class Collection < Array
attr_accessor :before, :after, :next, :previous, :total_count, :summary
def initialize(collection = [])
collection = normalize collection
paginate collection[:paging]
summarize collection[:summary]
replace Array(collection[:data])
end
private
def normalize(collection)
case collection
when Hash
collection
when Array
{
data: collection,
count: collection.size
}
else
raise ArgumentError.new("Invalid collection")
end
end
def paginate(paging)
cursors = paging.try(:[], :cursors)
self.before = cursors.try(:[], :before)
self.after = cursors.try(:[], :after)
self.next = params_in paging.try(:[], :next)
self.previous = params_in paging.try(:[], :previous)
end
def summarize(summary)
self.summary = summary
self.total_count = summary.try(:[], :total_count)
if summary.try(:[], :updated_time)
self.summary[:updated_time] = Time.parse summary[:updated_time]
end
end
def params_in(url)
if url
Rack::Utils.parse_nested_query(
URI.parse(url).query
).inject({}) do |params, (key, value)|
params.merge! key => value
end.with_indifferent_access
end
end
end
end

View file

@ -1,20 +0,0 @@
module FbGraph2
class Comment < Node
include Edge::Comments
include Edge::Likes::LikeeContext
register_attributes(
raw: [:can_comment, :can_remove, :comment_count, :like_count, :message, :user_likes, :is_hidden, :can_hide],
time: [:created_time],
user: [:from],
comment: [:parent],
profiles: [:message_tags],
custom: [:attachment]
)
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
end
end
end

View file

@ -1,9 +0,0 @@
module FbGraph2
class Domain < Node
include Edge::Insights
register_attributes(
raw: [:name]
)
end
end

View file

@ -1,39 +0,0 @@
module FbGraph2
class Edge < Collection
attr_accessor :owner, :edge, :params, :options, :collection
delegate :summary, :total_count, to: :collection
def initialize(owner, edge, params = {}, options = {})
self.owner = owner
self.edge = edge
self.params = params
self.options = options
self.collection = options.delete(:collection) || Collection.new
replace collection
end
def next(_options_ = {})
if collection.next.present?
owner.send edge, options.merge(collection.next).merge(_options_)
elsif collection.after.present?
owner.send edge, options.merge(after: collection.after).merge(_options_)
else
self.class.new owner, edge
end
end
def previous(_options_ = {})
if self.collection.previous.present?
owner.send edge, options.merge(collection.previous).merge(_options_)
elsif collection.before.present?
owner.send edge, options.merge(before: collection.before).merge(_options_)
else
self.class.new owner, edge
end
end
end
end
Dir[File.join(__dir__, 'edge/*.rb')].each do |file|
require file
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Accounts
def accounts(params = {})
pages = self.edge :accounts, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate page[:access_token]
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Achievements
def achievements(params = {})
achievements = self.edge :achievements, params
achievements.collect! do |achievement|
Achievement.new(achievement[:id], achievement).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Activities
def activities(params = {})
pages = self.edge :activities, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Admins
def admins(params = {})
users = self.edge :admins, params
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
def admin?(user, params = {})
users = self.edge :admins, params, edge_scope: user
users.present?
end
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Albums
def albums(params = {})
albums = self.edge :albums, params
albums.collect! do |album|
Album.new(album[:id], album).authenticate self.access_token
end
end
def album!(params = {})
album = self.post params, edge: :albums
Album.new(album[:id], params.merge(album)).authenticate self.access_token
end
end
end
end

View file

@ -1,12 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,22 +0,0 @@
module FbGraph2
class Edge
module AppRequests
def app_requests(params = {})
requests = self.edge :apprequests, params
requests.collect! do |request|
Request.new(request[:id], request).authenticate self.access_token
end
end
alias_method :apprequests, :app_requests
def app_request!(params = {})
response = self.post params, edge: :apprequests
if request = response[:request]
response[:request] = Request.new(request[:id], request).authenticate self.access_token
end
response
end
alias_method :apprequest!, :app_request!
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Applications
def applications(params = {})
apps = self.edge :applications, params, edge_scope: :developer
apps.collect! do |app|
App.new(app[:id], app).authenticate self.access_token
end
end
end
end
end

View file

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

View file

@ -1,29 +0,0 @@
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
def banned?(user, params = {})
users = self.edge :banned, params, edge_scope: user
users.present?
end
def ban!(user, params = {})
self.post params.merge(
uid: Util.as_identifier(user)
), edge: :banned
end
def unban!(user, params = {})
self.delete params.merge(
uid: Util.as_identifier(user)
), edge: :banned
end
end
end
end

View file

@ -1,29 +0,0 @@
module FbGraph2
class Edge
module Blocked
def blocked(params = {})
users = self.edge :blocked, params
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
def blocked?(user, params = {})
users = self.edge :blocked, params, edge_scope: user
users.present?
end
def block!(user, params = {})
self.post params.merge(
user: Util.as_identifier(user)
), edge: :blocked
end
def unblock!(user, params = {})
self.delete params.merge(
user: Util.as_identifier(user)
), edge: :blocked
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Books
def books(params = {})
pages = self.edge :books, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,28 +0,0 @@
module FbGraph2
class Edge
module Comments
def assign(attributes)
super
if attributes.include? :comments
@_cached_comments = Collection.new attributes[:comments]
end
end
def comments(params = {})
comments = if @_cached_comments.present? && params.blank?
@_cached_comments
else
self.edge :comments, params
end
comments.collect! do |comment|
Comment.new(comment[:id], comment).authenticate self.access_token
end
end
def comment!(params = {})
comment = self.post params, edge: :comments
Comment.new(comment[:id], params.merge(comment)).authenticate self.access_token
end
end
end
end

View file

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

View file

@ -1,9 +0,0 @@
module FbGraph2
class Edge
module Dispute
def dispute!(params = {})
self.post params, edge: :dispute
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Docs
def docs(params = {})
docs = self.edge :docs, params
docs.collect! do |doc|
GroupDoc.new(doc[:id], doc).authenticate self.access_token
end
end
end
end
end

View file

@ -1,13 +0,0 @@
module FbGraph2
class Edge
module Events
def events(*args)
params = args.extract_options!
events = self.edge :events, params, edge_scope: args.first
events.collect! do |event|
Event.new(event[:id], event).authenticate self.access_token
end
end
end
end
end

View file

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

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Feed
def feed(params = {})
posts = self.edge :feed, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
def feed!(params = {})
post = self.post params, edge: :feed
Post.new(post[:id], params.merge(post)).authenticate self.access_token
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Files
def files(params = {})
files = self.edge :files, params
files.collect! do |file|
Struct::GroupFile.new file
end
end
end
end
end

View file

@ -1,13 +0,0 @@
module FbGraph2
class Edge
module FriendLists
def friend_lists(params = {})
friend_lists = self.edge :friendlists, params
friend_lists.collect! do |friend_list|
FriendList.new(friend_list[:id], friend_list).authenticate self.access_token
end
end
alias_method :friendlists, :friend_lists
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Friends
def friends(params = {})
users = self.edge :friends, params
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
def friend?(user, params = {})
users = self.edge :friends, params, edge_scope: user
users.present?
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Games
def games(params = {})
pages = self.edge :games, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module GlobalBrandChildren
def global_brand_children(params = {})
pages = self.edge :global_brand_children, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Groups
def groups(params = {})
groups = self.edge :groups, params
groups.collect! do |group|
Group.new(group[:id], group).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Home
def home(params = {})
posts = self.edge :home, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Inbox
def inbox(params = {})
threads = self.edge :inbox, params
threads.collect! do |thread|
Thread.new(thread[:id], thread).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Insights
def insights(params = {})
insights = self.edge :insights, params
insights.collect! do |insight|
Insight.new(insight[:id], insight).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Interests
def interests(params = {})
pages = self.edge :interests, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module InvitableFriends
def invitable_friends(params = {})
invitable_friends = self.edge :invitable_friends, params
invitable_friends.collect! do |friend|
Struct::Friend.new friend
end
end
end
end
end

View file

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

View file

@ -1,47 +0,0 @@
module FbGraph2
class Edge
module Likes
module LikerContext
def likes(params = {})
pages = self.edge :likes, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
def liked?(page, params = {})
pages = self.edge :likes, params, edge_scope: page
pages.present?
end
end
module LikeeContext
def assign(attributes)
super
if attributes.include? :likes
@_cached_likes = Collection.new attributes[:likes]
end
end
def likes(params = {})
users = if @_cached_likes.present? && params.blank?
@_cached_likes
else
self.edge :likes, params
end
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
def like!(params = {})
self.post params, edge: :likes
end
def unlike!(params = {})
self.delete params, edge: :likes
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Links
def links(params = {})
posts = self.edge :links, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,14 +0,0 @@
module FbGraph2
class Edge
module Locations
def locations(params = {})
pages = self.edge :locations, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
# TODO: add, delete and update locations
end
end
end

View file

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

View file

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

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Milestones
def milestones(params = {})
milestones = self.edge :milestones, params
milestones.collect! do |milestone|
Milestone.new(milestone[:id], milestone).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Movies
def movies(params = {})
pages = self.edge :movies, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Music
def music(params = {})
pages = self.edge :music, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

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

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Notifications
def notifications(params = {})
notifications = self.edge :notifications, params
notifications.collect! do |notification|
Notification.new notification[:id], notification
end
end
def notification!(params = {})
self.post params, edge: :notifications
end
alias_method :notify!, :notification!
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Offers
def offers(params = {})
offers = self.edge :offers, params
offers.collect! do |offer|
Offer.new(offer[:id], offer).authenticate self.access_token
end
end
def offer!(params = {})
offer = self.post params, edge: :offers
Offer.new(offer[:id], params.merge(offer)).authenticate self.access_token
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Outbox
def outbox(params = {})
threads = self.edge :outbox, params
threads.collect! do |thread|
Thread.new(thread[:id], thread).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module PaymentTransactions
def payment_transactions(params = {})
payments = self.edge :payment_transactions, params
payments.collect! do |payment|
Payment.new(payment[:id], payment).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Permissions
def permissions(params = {})
permissions = self.edge :permissions, params
permissions.collect! do |permission|
Struct::Permission.new permission
end
end
end
end
end

View file

@ -1,18 +0,0 @@
module FbGraph2
class Edge
module Photos
def photos(*args)
params = args.extract_options!
photos = self.edge :photos, params, edge_scope: args.first
photos.collect! do |photo|
Photo.new(photo[:id], photo).authenticate self.access_token
end
end
def photo!(params = {})
photo = self.post params, edge: :photos
Photo.new(photo[:id], params.merge(photo)).authenticate self.access_token
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Picture
def picture(*args)
params = args.extract_options!
params[:type] = args.first if args.first
picture = self.get params.merge(redirect: false), edge: :picture
Struct::Picture.new picture[:data]
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Pokes
def pokes(params = {})
pokes = self.edge :pokes, params
pokes.collect! do |poke|
Struct::Poke.new poke
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Posts
def posts(params = {})
posts = self.edge :posts, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module PromotablePosts
def promotable_posts(params = {})
posts = self.edge :promotable_posts, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,9 +0,0 @@
module FbGraph2
class Edge
module Refunds
def refund!(params = {})
self.post params, edge: :refund
end
end
end
end

View file

@ -1,41 +0,0 @@
module FbGraph2
class Edge
module Roles
module AppContext
def roles(params = {})
roles = self.edge :roles, params
roles.collect! do |role|
Struct::Role.new role
end
end
def role!(user, params = {})
self.post params.merge(
user: Util.as_identifier(user)
), edge: :roles
end
def unrole!(user, params = {})
self.post params.merge(
user: Util.as_identifier(user)
), edge: :roles
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
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Scores
def scores(params = {})
scores = self.edge :scores, params
scores.collect! do |score|
Struct::Score.new score
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Settings
def settings(params = {})
settings = self.edge :settings, params
settings.collect! do |setting|
Struct::Setting.new setting
end
end
end
end
end

View file

@ -1,13 +0,0 @@
module FbGraph2
class Edge
module SharedPosts
def shared_posts(params = {})
posts = self.edge :sharedposts, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
alias_method :sharedposts, :shared_posts
end
end
end

View file

@ -1,13 +0,0 @@
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

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Statuses
def statuses(params = {})
posts = self.edge :statuses, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
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

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module TaggableFriends
def taggable_friends(params = {})
taggable_friends = self.edge :taggable_friends, params
taggable_friends.collect! do |friend|
Struct::Friend.new friend
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Tagged
def tagged(params = {})
posts = self.edge :tagged, params
posts.collect! do |post|
Post.new(post[:id], post).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module TaggedPlaces
def tagged_places(params = {})
place_tags = self.edge :tagged_places, params
place_tags.collect! do |place_tag|
PlaceTag.new(place_tag[:id], place_tag).authenticate self.access_token
end
end
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Edge
module Tags
def tags(params = {})
users = self.edge :tags, params
users.collect! do |user|
User.new(user[:id], user).authenticate self.access_token
end
end
# NOTE: available both for create & update
def tag!(params = {})
self.post params, edge: :tags
end
end
end
end

View file

@ -1,12 +0,0 @@
module FbGraph2
class Edge
module Television
def television(params = {})
pages = self.edge :television, params
pages.collect! do |page|
Page.new(page[:id], page).authenticate self.access_token
end
end
end
end
end

View file

@ -1,12 +0,0 @@
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

@ -1,17 +0,0 @@
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

@ -1,18 +0,0 @@
module FbGraph2
class Edge
module Videos
def videos(*args)
params = args.extract_options!
videos = self.edge :videos, params, edge_scope: args.first
videos.collect! do |video|
Video.new(video[:id], video).authenticate self.access_token
end
end
def video!(params = {})
video = self.post params, edge: :videos
Video.new(video[:id], params.merge(video)).authenticate self.access_token
end
end
end
end

View file

@ -1,23 +0,0 @@
module FbGraph2
class Event < Node
include Edge::Attending
include Edge::Declined
include Edge::Feed
include Edge::Invited
include Edge::Maybe
include Edge::Noreply
include Edge::Picture
include Edge::Photos
include Edge::Videos
extend Searchable
register_attributes(
raw: [:description, :is_date_only, :location, :name, :privacy, :ticket_uri, :timezone],
time: [:end_time, :start_time, :updated_time],
page: [:venue],
profile: [:owner],
group: [:parent_group],
photo: [:cover]
)
end
end

View file

@ -1,81 +0,0 @@
module FbGraph2
class Exception < StandardError
attr_accessor :status, :type, :code
class << self
def detect(status, body = {}, headers = {})
error = body[:error]
message = error.try(:[], :message)
klass = detect_from_header(headers, error) || detect_from_status(status)
if klass
klass.new message, error
else
new status, message, error
end
end
def detect_from_status(status)
case status
when 400
BadRequest
when 401
Unauthorized
when 404
NotFound
when 500
InternalServerError
end
end
def detect_from_header(headers, error)
key, value = headers.detect do |name, value|
name.upcase == "WWW-Authenticate".upcase
end || return
matched, klass = ERROR_HEADER_MATCHERS.detect do |matcher, klass_name|
matcher =~ value
end || return
klass
end
end
def initialize(status, message, error = {})
super message
self.status = status
self.type = error[:type]
self.code = error[:code]
end
class BadRequest < Exception
def initialize(message, details = {})
super 400, message, details
end
end
class Unauthorized < Exception
def initialize(message, details = {})
super 401, message, details
end
end
class NotFound < Exception
def initialize(message, details = {})
super 404, message, details
end
end
class InternalServerError < Exception
def initialize(message, details = {})
super 500, message, details
end
end
class InvalidToken < Unauthorized; end
class InvalidRequest < BadRequest; end
ERROR_HEADER_MATCHERS = {
/not_found/ => NotFound,
/invalid_token/ => InvalidToken,
/invalid_request/ => InvalidRequest
}
end
end

View file

@ -1,7 +0,0 @@
module FbGraph2
class FriendList < Node
register_attributes(
raw: [:name, :list_type]
)
end
end

View file

@ -1,21 +0,0 @@
module FbGraph2
class Group < Node
include Edge::Docs
include Edge::Events
include Edge::Feed
include Edge::Files
include Edge::Members
extend Searchable
register_attributes(
raw: [
:description, :email, :icon, :link, :name, :privacy,
# NOTE: in groups edge context
:administrator, :bookmark_order, :unread
],
time: [:updated_time],
profile: [:owner, :parent],
photo: [:cover]
)
end
end

View file

@ -1,9 +0,0 @@
module FbGraph2
class GroupDoc < Node
register_attributes(
raw: [:subject, :message, :icon, :revision, :can_edit, :can_delete],
time: [:created_time, :updated_time],
profile: [:from]
)
end
end

View file

@ -1,13 +0,0 @@
module FbGraph2
class Insight < Node
register_attributes(
raw: [:name, :description, :title, :period],
custom: [:values]
)
def initialize(id, attributes = {})
super
self.values = attributes[:values].collect(&:with_indifferent_access)
end
end
end

View file

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

View file

@ -1,13 +0,0 @@
module FbGraph2
class Milestone < Node
include Edge::Comments
include Edge::Likes::LikeeContext
include Edge::Photos
register_attributes(
raw: [:title, :description],
time: [:created_time, :updated_time, :start_time, :end_time],
page: [:from]
)
end
end

View file

@ -1,125 +0,0 @@
module FbGraph2
class Node
attr_accessor :id, :access_token, :raw_attributes
alias_method :identifier, :id
def self.inherited(klass)
klass.send :include, AttributeAssigner
FbGraph2.object_classes << klass
end
def initialize(id, attributes = {})
self.id = id
self.raw_attributes = attributes
assign attributes if respond_to? :assign
authenticate attributes[:access_token] if attributes.include? :access_token
end
def authenticate(access_token)
self.access_token = access_token
self
end
def fetch(params = {}, options = {})
attributes = get params, options
self.class.new(attributes[:id], attributes).authenticate access_token
end
def edge(edge, params = {}, options = {})
Edge.new(
self,
edge,
params,
options.merge(
collection: edge_for(edge, params, options)
)
)
end
def edges
@edges ||= self.class.included_modules.select do |_module_|
_module_.name =~ /FbGraph2::Edge/
end.collect(&:instance_methods).flatten.sort
end
def update(params = {}, options = {})
post params, options
end
def destroy(params = {}, options = {})
delete params, options
end
protected
def http_client
FbGraph2.http_client(access_token)
end
def get(params = {}, options = {})
handle_response do
http_client.get build_endpoint(options), build_params(params)
end
end
def post(params = {}, options = {})
handle_response do
http_client.post build_endpoint(options), build_params(params)
end
end
def delete(params = {}, options = {})
handle_response do
http_client.delete build_endpoint(options), build_params(params)
end
end
private
def edge_for(edge, params = {}, options = {})
collection = get params, options.merge(edge: edge)
Collection.new collection
end
def build_endpoint(options = {})
File.join [
File.join(
FbGraph2.root_url,
options[:api_version] || FbGraph2.api_version,
id.to_s
),
options[:edge],
Util.as_identifier(options[:edge_scope])
].compact.collect(&:to_s)
end
def build_params(params = {})
if params.present?
if params.include? :fields
params[:fields] = Array(params[:fields]).join(',')
end
params
else
nil
end
end
def handle_response
response = yield
_response_ = MultiJson.load response.body
_response_ = _response_.with_indifferent_access if _response_.respond_to? :with_indifferent_access
case response.status
when 200...300
if _response_.respond_to?(:include?) && _response_.include?(:success)
_response_[:success]
else
_response_
end
else
raise Exception.detect(response.status, _response_, response.headers)
end
rescue MultiJson::DecodeError
raise Exception.new(response.status, "Unparsable Response: #{response.body}")
end
end
end

View file

@ -1,17 +0,0 @@
module FbGraph2
class Notification < Node
register_attributes(
raw: [:title, :link, :unread],
time: [:created_time, :updated_time],
profile: [:from],
user: [:to],
app: [:application],
custom: [:object]
)
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
end
end
end

View file

@ -1,9 +0,0 @@
module FbGraph2
class Offer < Node
register_attributes(
raw: [:claim_limit, :coupon_type, :image_url, :redemption_code, :redemption_link, :terms, :title, :message],
time: [:created_time, :expiration_time],
page: [:from]
)
end
end

View file

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

Some files were not shown because too many files have changed in this diff Show more