fb_graph2 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/fb_graph2.gemspec +23 -0
- data/lib/fb_graph2/application.rb +27 -0
- data/lib/fb_graph2/attribute_assigner.rb +72 -0
- data/lib/fb_graph2/collection.rb +20 -0
- data/lib/fb_graph2/edge/accounts.rb +12 -0
- data/lib/fb_graph2/edge/feed.rb +12 -0
- data/lib/fb_graph2/edge/friends.rb +12 -0
- data/lib/fb_graph2/edge.rb +18 -0
- data/lib/fb_graph2/node.rb +83 -0
- data/lib/fb_graph2/page.rb +25 -0
- data/lib/fb_graph2/post.rb +23 -0
- data/lib/fb_graph2/request_filter/authenticator.rb +17 -0
- data/lib/fb_graph2/request_filter/debugger.rb +23 -0
- data/lib/fb_graph2/user.rb +30 -0
- data/lib/fb_graph2.rb +55 -0
- data/spec/fb_graph2/node_spec.rb +16 -0
- data/spec/fb_graph2/user_spec.rb +8 -0
- data/spec/fb_graph2_spec.rb +35 -0
- data/spec/spec_helper.rb +8 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc282842ac8e4f9c5d5c23370f1d24c1081a314d
|
4
|
+
data.tar.gz: 9a7ad863eda44a83f1daf55d2b27a9fc2a44a4ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ac13ec30238246300656403271e17e34e79f493d958a8279cad910ab145983423693fad330c5b283d0cb837bd859d29327b381b2084df7d5776b4086deade6b
|
7
|
+
data.tar.gz: 44a5171f50873c25513a1ada57e250b60f1e4ac5f6b0d8d220ecb617f6b848bedb71ffb1a68f8ed4fda7ccf375bfb873318e5ca0e8f7429999c86d0347caf63c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 nov matake
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# FbGraph2
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fb_graph2'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fb_graph2
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/fb_graph2/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
namespace :coverage do
|
7
|
+
desc 'Open coverage report'
|
8
|
+
task :report do
|
9
|
+
require 'simplecov'
|
10
|
+
`open '#{File.join SimpleCov.coverage_path, 'index.html'}'`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task :spec do
|
15
|
+
Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/fb_graph2.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'fb_graph2'
|
3
|
+
gem.version = File.read('VERSION').delete("\n\r")
|
4
|
+
gem.authors = ['nov matake']
|
5
|
+
gem.email = ['nov@matake.jp']
|
6
|
+
gem.summary = %q{Facebook Graph API v2.0 Wrapper in Ruby}
|
7
|
+
gem.description = %q{Facebook Graph API v2.0 Wrapper in Ruby}
|
8
|
+
gem.homepage = ''
|
9
|
+
gem.license = 'MIT'
|
10
|
+
|
11
|
+
gem.files = `git ls-files -z`.split("\x0")
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
|
16
|
+
gem.add_runtime_dependency 'httpclient', '>= 2.3'
|
17
|
+
gem.add_runtime_dependency 'rack-oauth2', '>= 1.0'
|
18
|
+
gem.add_runtime_dependency 'multi_json'
|
19
|
+
gem.add_runtime_dependency 'activesupport', '>= 4.0'
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'simplecov'
|
22
|
+
gem.add_development_dependency 'rspec', '>= 2'
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Application < Node
|
3
|
+
register_attributes(
|
4
|
+
raw: [
|
5
|
+
:id, :android_key_hash, :app_domains, :auth_dialog_data_help_url, :auth_dialog_headline,
|
6
|
+
:auth_dialog_perms_explanation, :auth_referral_enabled, :auth_referral_extended_perms,
|
7
|
+
:auth_referral_friend_perms, :auth_referral_user_perms, :canvas_fluid_height, :canvas_fluid_width,
|
8
|
+
:canvas_url, :category, :company, :contact_email, :creator_uid, :daily_active_users, :daily_active_users_rank,
|
9
|
+
:deauth_callback_url, :description, :hosting_url, :icon_url, :ios_bundle_id, :iphone_app_store_id,
|
10
|
+
:link, :logo_url, :mobile_web_url, :monthly_active_users, :monthly_active_users_rank, :name,
|
11
|
+
:namespace, :page_tab_default_name, :page_tab_url, :privacy_policy_url, :secure_canvas_url,
|
12
|
+
:secure_page_tab_url, :server_ip_whitelist, :social_discovery, :subcategory, :terms_of_service_url,
|
13
|
+
:user_support_email, :user_support_url, :website_url, :weekly_active_users
|
14
|
+
],
|
15
|
+
timestamp: [:created_time],
|
16
|
+
custom: [
|
17
|
+
:auth_referral_default_activity_privacy, :auth_referral_response_type, :context, :migrations,
|
18
|
+
:object_store_urls, :restrictions
|
19
|
+
]
|
20
|
+
)
|
21
|
+
|
22
|
+
def initialize(id, attributes = {})
|
23
|
+
super
|
24
|
+
# TODO: handle custom attributes.
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
module AttributeAssigner
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
extend ClassMethods
|
7
|
+
attr_accessor :raw_attributes
|
8
|
+
cattr_accessor :registered_attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def register_attributes(attributes)
|
13
|
+
self.registered_attributes = attributes
|
14
|
+
send :attr_accessor, *attributes.values.flatten
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def assign(attributes)
|
19
|
+
self.raw_attributes = attributes
|
20
|
+
self.class.registered_attributes.each do |type, keys|
|
21
|
+
keys.each do |key|
|
22
|
+
raw = attributes[key]
|
23
|
+
if raw.present?
|
24
|
+
value = case type
|
25
|
+
when :raw
|
26
|
+
raw
|
27
|
+
when :date
|
28
|
+
Date.parse raw
|
29
|
+
when :time
|
30
|
+
Time.parse raw
|
31
|
+
when :timestamp
|
32
|
+
Time.at raw
|
33
|
+
when :application
|
34
|
+
Application.new raw[:id], raw
|
35
|
+
when :page
|
36
|
+
Page.new raw[:id], raw
|
37
|
+
when :pages
|
38
|
+
Collection.new(raw).collect do |_raw_|
|
39
|
+
Page.new _raw_[:id], _raw_
|
40
|
+
end
|
41
|
+
when :profile
|
42
|
+
as_profile raw
|
43
|
+
when :profiles
|
44
|
+
Collection.new(raw).collect do |_raw_|
|
45
|
+
as_profile _raw_
|
46
|
+
end
|
47
|
+
when :user
|
48
|
+
User.new raw[:id], raw
|
49
|
+
when :custom
|
50
|
+
# NOTE: handle custom attributes in each class
|
51
|
+
end
|
52
|
+
self.send :"#{key}=", value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def as_profile(raw)
|
61
|
+
klass = if raw.include?(:namespace)
|
62
|
+
Application
|
63
|
+
elsif raw.include?(:category)
|
64
|
+
Page
|
65
|
+
else
|
66
|
+
# TODO: needs to handle Event and Group here.
|
67
|
+
User
|
68
|
+
end
|
69
|
+
klass.new raw[:id], raw
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Collection < Array
|
3
|
+
attr_reader :previous, :next, :total_count, :unread_count, :updated_time, :cursors
|
4
|
+
|
5
|
+
def initialize(collection = nil)
|
6
|
+
collection = case collection
|
7
|
+
when Hash
|
8
|
+
collection
|
9
|
+
when Array
|
10
|
+
{
|
11
|
+
data: collection,
|
12
|
+
count: collection.size
|
13
|
+
}
|
14
|
+
else
|
15
|
+
raise ArgumentError.new("Invalid collection")
|
16
|
+
end
|
17
|
+
replace Array(collection[:data])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge < Collection
|
3
|
+
attr_accessor :owner, :edge, :params, :options, :collection
|
4
|
+
|
5
|
+
def initialize(owner, edge, params = {}, options = {})
|
6
|
+
self.owner = owner
|
7
|
+
self.edge = edge
|
8
|
+
self.params = params
|
9
|
+
self.options = options
|
10
|
+
self.collection = options.delete(:collection) || Collection.new
|
11
|
+
replace collection
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir[File.join(__dir__, 'edge/*.rb')].each do |file|
|
17
|
+
require file
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Node
|
3
|
+
attr_accessor :id, :access_token, :raw_attributes
|
4
|
+
|
5
|
+
def self.inherited(klass)
|
6
|
+
klass.include AttributeAssigner
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(id, attributes = {})
|
10
|
+
self.id = id
|
11
|
+
assign attributes if respond_to?(:assign)
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate(access_token)
|
15
|
+
self.access_token = access_token
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch(params = {})
|
20
|
+
attributes = get params
|
21
|
+
self.class.new(attributes[:id], attributes).authenticate access_token
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fetch(identifier, params = {})
|
25
|
+
new(identifier).fetch params
|
26
|
+
end
|
27
|
+
|
28
|
+
def edge(edge, params = {}, options = {})
|
29
|
+
Edge.new(
|
30
|
+
self,
|
31
|
+
edge,
|
32
|
+
params,
|
33
|
+
options.merge(
|
34
|
+
collection: edge_for(edge, params, options)
|
35
|
+
)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def http_client
|
42
|
+
FbGraph2.http_client(access_token)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get(params = {}, options = {})
|
46
|
+
handle_response do
|
47
|
+
http_client.get build_endpoint(options), build_params(params)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def edge_for(edge, params = {}, options = {})
|
54
|
+
collection = get params, options.merge(:edge => edge)
|
55
|
+
Collection.new collection
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_endpoint(options = {})
|
59
|
+
File.join [
|
60
|
+
File.join(FbGraph2.root_url, id.to_s),
|
61
|
+
options[:edge],
|
62
|
+
options[:edge_scope]
|
63
|
+
].compact.collect(&:to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_params(params = {})
|
67
|
+
params.present? ? params : nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def handle_response
|
71
|
+
response = yield
|
72
|
+
_response_ = MultiJson.load(response.body).with_indifferent_access
|
73
|
+
case response.status
|
74
|
+
when 200...300
|
75
|
+
_response_
|
76
|
+
else
|
77
|
+
raise response.body
|
78
|
+
end
|
79
|
+
rescue MultiJson::DecodeError
|
80
|
+
raise Exception.new(response.status, "Unparsable Response: #{response.body}")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Page < Node
|
3
|
+
register_attributes(
|
4
|
+
raw: [
|
5
|
+
:about, :attire, :band_members, :booking_agent, :can_post, :category, :checkins, :company_overview,
|
6
|
+
:current_location, :description, :directed_by, :founded, :general_info, :general_manager, :hometown,
|
7
|
+
:is_permanently_closed, :is_published, :is_unclaimed, :likes, :link, :mission, :name, :phone, :press_contact,
|
8
|
+
:products, :talking_about_count, :username, :website, :were_here_count,
|
9
|
+
# only within /:user_id/accounts context
|
10
|
+
:perms
|
11
|
+
],
|
12
|
+
date: [:birthday],
|
13
|
+
page: [:best_page],
|
14
|
+
custom: [
|
15
|
+
:category_list, :cover, :context, :hours, :location, :parking, :price_range, :restaurant_services,
|
16
|
+
:restaurant_specialties
|
17
|
+
]
|
18
|
+
)
|
19
|
+
|
20
|
+
def initialize(id, attributes = {})
|
21
|
+
super
|
22
|
+
# TODO: handle custom attributes.
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Post < Node
|
3
|
+
register_attributes(
|
4
|
+
raw: [
|
5
|
+
:caption, :description, :icon, :is_hidden, :link, :message, :name, :object_id, :picture,
|
6
|
+
:source, :story
|
7
|
+
],
|
8
|
+
time: [:created_time, :updated_time],
|
9
|
+
application: [:application],
|
10
|
+
page: [:place],
|
11
|
+
profile: [:from],
|
12
|
+
profiles: [:to, :with_tags],
|
13
|
+
custom: [
|
14
|
+
:actions, :message_tags, :privacy, :properties, :shares, :status_type, :type
|
15
|
+
]
|
16
|
+
)
|
17
|
+
|
18
|
+
def initialize(id, attributes = {})
|
19
|
+
super
|
20
|
+
# TODO: handle custom attributes.
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
module RequestFilter
|
3
|
+
class Authenticator < Rack::OAuth2::AccessToken::Authenticator
|
4
|
+
def initialize(access_token)
|
5
|
+
_access_token_ = case access_token
|
6
|
+
when Rack::OAuth2::AccessToken
|
7
|
+
access_token
|
8
|
+
else
|
9
|
+
Rack::OAuth2::AccessToken::Bearer.new(
|
10
|
+
access_token: access_token
|
11
|
+
)
|
12
|
+
end
|
13
|
+
super _access_token_
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
module RequestFilter
|
3
|
+
class Debugger
|
4
|
+
def filter_request(request)
|
5
|
+
started = "======= [FbGraph2] API REQUEST STARTED ======="
|
6
|
+
log started, request.dump
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter_response(request, response)
|
10
|
+
finished = "======= [FbGraph2] API REQUEST FINISHED ======="
|
11
|
+
log '-' * 50, response.dump, finished
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def log(*outputs)
|
17
|
+
outputs.each do |output|
|
18
|
+
FbGraph2.logger.info output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class User < Node
|
3
|
+
include Edge::Accounts
|
4
|
+
include Edge::Friends
|
5
|
+
include Edge::Feed
|
6
|
+
|
7
|
+
register_attributes(
|
8
|
+
raw: [
|
9
|
+
:about, :bio, :email, :first_name, :gender, :installed, :is_verified, :link, :locale,
|
10
|
+
:middle_name, :name, :name_format, :political, :quotes, :relationship_status, :religion,
|
11
|
+
:timezone, :third_party_id, :verified, :website
|
12
|
+
],
|
13
|
+
time: [:updated_time], # NOTE: undocumented attribute
|
14
|
+
date: [:birthday],
|
15
|
+
page: [:hometown, :location],
|
16
|
+
pages: [:favorite_athletes, :favorite_teams, :inspirational_people, :languages],
|
17
|
+
user: [:significant_other],
|
18
|
+
custom: [:age_range, :context, :cover, :currency, :education, :work]
|
19
|
+
)
|
20
|
+
|
21
|
+
def initialize(id, attributes = {})
|
22
|
+
super
|
23
|
+
# TODO: handle custom attributes.
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.me(access_token)
|
27
|
+
new(:me).authenticate access_token
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/fb_graph2.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'rack/oauth2'
|
3
|
+
|
4
|
+
module FbGraph2
|
5
|
+
cattr_accessor :api_version, :gem_version, :logger, :debugging, :_http_config_
|
6
|
+
|
7
|
+
self.api_version = 'v2.0'
|
8
|
+
self.gem_version = File.read(File.join(__dir__, '../VERSION')).delete("\n\r")
|
9
|
+
self.logger = Logger.new(STDOUT)
|
10
|
+
self.logger.progname = 'FbGraph2'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def root_url
|
14
|
+
File.join('https://graph.facebook.com', api_version)
|
15
|
+
end
|
16
|
+
|
17
|
+
def debugging?
|
18
|
+
!!self.debugging
|
19
|
+
end
|
20
|
+
def debug!
|
21
|
+
Rack::OAuth2.debug!
|
22
|
+
self.debugging = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def http_client(access_token = nil)
|
26
|
+
_http_client_ = HTTPClient.new(
|
27
|
+
agent_name: "FbGraph2 (#{gem_version})"
|
28
|
+
)
|
29
|
+
_http_client_.request_filter.delete_if do |filter|
|
30
|
+
filter.is_a? HTTPClient::WWWAuth
|
31
|
+
end
|
32
|
+
_http_client_.request_filter << RequestFilter::Authenticator.new(access_token) if access_token.present?
|
33
|
+
_http_client_.request_filter << RequestFilter::Debugger.new if self.debugging?
|
34
|
+
_http_config_.try(:call, _http_client_)
|
35
|
+
_http_client_
|
36
|
+
end
|
37
|
+
def http_config(&block)
|
38
|
+
Rack::OAuth2.http_config &block unless Rack::OAuth2.http_config
|
39
|
+
self._http_config_ ||= block
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'fb_graph2/attribute_assigner'
|
45
|
+
require 'fb_graph2/node'
|
46
|
+
require 'fb_graph2/collection'
|
47
|
+
require 'fb_graph2/edge'
|
48
|
+
[
|
49
|
+
'.',
|
50
|
+
'request_filter'
|
51
|
+
].each do |dir|
|
52
|
+
Dir[File.join(__dir__, 'fb_graph2', dir, '*.rb')].each do |file|
|
53
|
+
require file
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FbGraph2::Node do
|
4
|
+
describe '.new' do
|
5
|
+
it 'should support access_token option' do
|
6
|
+
FbGraph2::Node.new(
|
7
|
+
'matake', :access_token => 'access_token'
|
8
|
+
).access_token.should == 'access_token'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should store raw attributes' do
|
12
|
+
attributes = {:key => :value}
|
13
|
+
FbGraph2::Node.new(12345, attributes).raw_attributes.should == attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FbGraph2 do
|
4
|
+
subject { FbGraph2 }
|
5
|
+
after { FbGraph2.debugging = false }
|
6
|
+
|
7
|
+
its(:logger) { should be_a Logger }
|
8
|
+
its(:debugging?) { should be_false }
|
9
|
+
|
10
|
+
describe '.debug!' do
|
11
|
+
before { FbGraph2.debug! }
|
12
|
+
its(:debugging?) { should be_true }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.http_client' do
|
16
|
+
context 'with http_config' do
|
17
|
+
before do
|
18
|
+
FbGraph2.http_config do |config|
|
19
|
+
config.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
20
|
+
config.connect_timeout = 30
|
21
|
+
config.send_timeout = 40
|
22
|
+
config.receive_timeout = 60
|
23
|
+
end
|
24
|
+
end
|
25
|
+
it 'should configure Rack::OAuth2 and FbGraph2 http_client' do
|
26
|
+
[Rack::OAuth2, FbGraph2].each do |klass|
|
27
|
+
klass.http_client.ssl_config.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
28
|
+
klass.http_client.connect_timeout.should == 30
|
29
|
+
klass.http_client.send_timeout.should == 40
|
30
|
+
klass.http_client.receive_timeout.should == 60
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fb_graph2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nov matake
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2'
|
111
|
+
description: Facebook Graph API v2.0 Wrapper in Ruby
|
112
|
+
email:
|
113
|
+
- nov@matake.jp
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- VERSION
|
124
|
+
- fb_graph2.gemspec
|
125
|
+
- lib/fb_graph2.rb
|
126
|
+
- lib/fb_graph2/application.rb
|
127
|
+
- lib/fb_graph2/attribute_assigner.rb
|
128
|
+
- lib/fb_graph2/collection.rb
|
129
|
+
- lib/fb_graph2/edge.rb
|
130
|
+
- lib/fb_graph2/edge/accounts.rb
|
131
|
+
- lib/fb_graph2/edge/feed.rb
|
132
|
+
- lib/fb_graph2/edge/friends.rb
|
133
|
+
- lib/fb_graph2/node.rb
|
134
|
+
- lib/fb_graph2/page.rb
|
135
|
+
- lib/fb_graph2/post.rb
|
136
|
+
- lib/fb_graph2/request_filter/authenticator.rb
|
137
|
+
- lib/fb_graph2/request_filter/debugger.rb
|
138
|
+
- lib/fb_graph2/user.rb
|
139
|
+
- spec/fb_graph2/node_spec.rb
|
140
|
+
- spec/fb_graph2/user_spec.rb
|
141
|
+
- spec/fb_graph2_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
homepage: ''
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.2.2
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Facebook Graph API v2.0 Wrapper in Ruby
|
167
|
+
test_files: []
|