tyler_koala 1.2.0beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +12 -0
- data/.gitignore +5 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +185 -0
- data/Gemfile +11 -0
- data/LICENSE +22 -0
- data/Manifest +39 -0
- data/Rakefile +16 -0
- data/autotest/discover.rb +1 -0
- data/koala.gemspec +50 -0
- data/lib/koala.rb +119 -0
- data/lib/koala/batch_operation.rb +74 -0
- data/lib/koala/graph_api.rb +281 -0
- data/lib/koala/graph_batch_api.rb +87 -0
- data/lib/koala/graph_collection.rb +54 -0
- data/lib/koala/http_service.rb +161 -0
- data/lib/koala/oauth.rb +181 -0
- data/lib/koala/realtime_updates.rb +89 -0
- data/lib/koala/rest_api.rb +95 -0
- data/lib/koala/test_users.rb +102 -0
- data/lib/koala/uploadable_io.rb +180 -0
- data/lib/koala/utils.rb +7 -0
- data/readme.md +160 -0
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/error_spec.rb +30 -0
- data/spec/cases/graph_and_rest_api_spec.rb +48 -0
- data/spec/cases/graph_api_batch_spec.rb +600 -0
- data/spec/cases/graph_api_spec.rb +42 -0
- data/spec/cases/http_service_spec.rb +420 -0
- data/spec/cases/koala_spec.rb +21 -0
- data/spec/cases/oauth_spec.rb +428 -0
- data/spec/cases/realtime_updates_spec.rb +198 -0
- data/spec/cases/rest_api_spec.rb +41 -0
- data/spec/cases/test_users_spec.rb +281 -0
- data/spec/cases/uploadable_io_spec.rb +206 -0
- data/spec/cases/utils_spec.rb +8 -0
- data/spec/fixtures/beach.jpg +0 -0
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +61 -0
- data/spec/fixtures/mock_facebook_responses.yml +439 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/graph_api_shared_examples.rb +502 -0
- data/spec/support/json_testing_fix.rb +42 -0
- data/spec/support/koala_test.rb +163 -0
- data/spec/support/mock_http_service.rb +98 -0
- data/spec/support/ordered_hash.rb +205 -0
- data/spec/support/rest_api_shared_examples.rb +285 -0
- data/spec/support/uploadable_io_shared_examples.rb +70 -0
- metadata +221 -0
data/.autotest
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
v1.2
|
2
|
+
New methods:
|
3
|
+
-- API is now the main API class, contains both Graph and REST methods
|
4
|
+
-- Old classes are aliased with deprecation warnings (non-breaking change)
|
5
|
+
-- TestUsers#update lets you update the name or password of an existing test user
|
6
|
+
-- GraphAPI.get_page_access_token lets you easily fetch the access token for a page you manage (thanks, marcgg!)
|
7
|
+
Updated methods:
|
8
|
+
-- put_picture now accepts URLs to images (thanks, marcgg!)
|
9
|
+
Internal improvements:
|
10
|
+
-- Koala now uses Faraday to make requests, replacing the HTTPServices (see wiki)
|
11
|
+
-- Koala::HTTPService.faraday_options allows specification of default Faraday connection options
|
12
|
+
-- Koala::HTTPService.faraday_middleware allows custom middleware configurations
|
13
|
+
-- RealTimeUpdates and TestUsers are no longer subclasses of API, but have their own .api objects
|
14
|
+
-- The old .graph_api accessor is aliases to .api with a deprecation warning
|
15
|
+
Testing improvements:
|
16
|
+
-- Live test suites now run against test users by default
|
17
|
+
-- Test suite can be repeatedly run live without having to update facebook_data.yml
|
18
|
+
-- OAuth code and session key tests cannot be run against test users
|
19
|
+
-- Faraday adapter for live tests can be specified with ADAPTER=[your adapter] in the shell command
|
20
|
+
-- Tests now pass against all rubies on Travis CI
|
21
|
+
-- Expanded test coverage
|
22
|
+
-- Fixed bug with YAML parsing in Ruby 1.9
|
23
|
+
|
24
|
+
v1.1
|
25
|
+
New methods:
|
26
|
+
-- Added Batch API support (thanks, seejohnrun and spiegela!)
|
27
|
+
-- includes file uploads, error handling, and FQL
|
28
|
+
-- Added GraphAPI#put_video
|
29
|
+
-- Added GraphAPI#get_comments_for_urls (thanks, amrnt!)
|
30
|
+
-- Added RestAPI#fql_multiquery, which simplifies the results (thanks, amrnt!)
|
31
|
+
-- HTTP services support global proxy and timeout settings (thanks, itchy!)
|
32
|
+
-- Net::HTTP supports global ca_path, ca_file, and verify_mode settings (thanks, spiegela!)
|
33
|
+
Updated methods:
|
34
|
+
-- RealtimeUpdates now uses a GraphAPI object instead of its own API
|
35
|
+
-- RestAPI#rest_call now has an optional last argument for method, for calls requiring POST, DELETE, etc. (thanks, sshilo!)
|
36
|
+
-- Filename can now be specified when uploading (e.g. for Ads API) (thanks, sshilo!)
|
37
|
+
-- get_objects([]) returns [] instead of a Facebook error in non-batch mode (thanks, aselder!)
|
38
|
+
Internal improvements:
|
39
|
+
-- Koala is now more compatible with other Rubies (JRuby, Rubinius, etc.)
|
40
|
+
-- HTTP services are more modular and can be changed on the fly (thanks, chadk!)
|
41
|
+
-- Includes support for uploading StringIOs and other non-files via Net::HTTP even when using TyphoeusService
|
42
|
+
-- Koala now uses multi_json to improve compatibility with Rubinius and other Ruby versions
|
43
|
+
-- Koala now uses the modern Typhoeus API (thanks, aselder!)
|
44
|
+
-- Koala now uses the current modern Net::HTTP interface (thanks, romanbsd!)
|
45
|
+
-- Fixed bugs and typos (thanks, waynn, mokevnin, and tikh!)
|
46
|
+
|
47
|
+
v1.0
|
48
|
+
New methods:
|
49
|
+
-- Photo and file upload now supported through #put_picture
|
50
|
+
-- Added UploadableIO class to manage file uploads
|
51
|
+
-- Added a delete_like method (thanks to waseem)
|
52
|
+
-- Added put_connection and delete_connection convenience methods
|
53
|
+
Updated methods:
|
54
|
+
-- Search can now search places, checkins, etc. (thanks, rickyc!)
|
55
|
+
-- You can now pass :beta => true in the http options to use Facebook's beta tier
|
56
|
+
-- TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks, pulsd and kbighorse!)
|
57
|
+
-- All methods now accept an http_options hash as their optional last parameter (thanks, spiegela!)
|
58
|
+
-- url_for_oauth_code can now take a :display option (thanks, netbe!)
|
59
|
+
-- Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
|
60
|
+
-- Test users now supports using test accounts across multiple apps
|
61
|
+
Internal improvements:
|
62
|
+
-- For public requests, Koala now uses http by default (instead of https) to improve speed
|
63
|
+
-- This can be overridden through Koala.always_use_ssl= or by passing :use_ssl => true in the options hash for an api call
|
64
|
+
-- Read-only REST API requests now go through the faster api-read server
|
65
|
+
-- Replaced parse_signed_request with a version from Facebook that also supports the new signed params proposal
|
66
|
+
-- Note: invalid requests will now raise exceptions rather than return nil, in keeping with other SDKs
|
67
|
+
-- Delete methods will now raise an error if there's no access token (like put_object and delete_like)
|
68
|
+
-- Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
|
69
|
+
-- APIError is now < StandardError, not Exception
|
70
|
+
-- Added KoalaError for non-API errors
|
71
|
+
-- Net::HTTP's SSL verification is no longer disabled by default
|
72
|
+
Test improvements:
|
73
|
+
-- Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
|
74
|
+
-- Expanded HTTP service tests (added Typhoeus test suite and additional Net::HTTP test cases)
|
75
|
+
-- Live tests now verify that the access token has the necessary permissions before starting
|
76
|
+
-- Replaced the 50-person network test, which often took 15+ minutes to run live, with a 5-person test
|
77
|
+
|
78
|
+
v0.10.0
|
79
|
+
-- Added test user module
|
80
|
+
-- Fixed bug when raising APIError after Facebook fails to exchange session keys
|
81
|
+
-- Made access_token accessible via the readonly access_token property on all our API classes
|
82
|
+
|
83
|
+
v0.9.1
|
84
|
+
-- Tests are now compatible with Ruby 1.9.2
|
85
|
+
-- Added JSON to runtime dependencies
|
86
|
+
-- Removed examples directory (referenced from github instead)
|
87
|
+
|
88
|
+
v0.9.0
|
89
|
+
-- Added parse_signed_request to handle Facebook's new authentication scheme
|
90
|
+
-- note: creates dependency on OpenSSL (OpenSSL::HMAC) for decryption
|
91
|
+
-- Added GraphCollection class to provide paging support for GraphAPI get_connections and search methods (thanks to jagthedrummer)
|
92
|
+
-- Added get_page method to easily fetch pages of results from GraphCollections
|
93
|
+
-- Exchanging sessions for tokens now works properly when provided invalid/expired session keys
|
94
|
+
-- You can now include a :typhoeus_options key in TyphoeusService#make_request's options hash to control the Typhoeus call (for example, to set :disable_ssl_peer_verification => true)
|
95
|
+
-- All paths provided to HTTP services start with leading / to improve compatibility with stubbing libraries
|
96
|
+
-- If Facebook returns nil for search or get_connections requests, Koala now returns nil rather than throwing an exception
|
97
|
+
|
98
|
+
v0.8.0
|
99
|
+
-- Breaking interface changes
|
100
|
+
-- Removed string overloading for the methods, per 0.7.3, which caused Marshaling issues
|
101
|
+
-- Removed ability to provide a string as the second argument to url_for_access_token, per 0.5.0
|
102
|
+
|
103
|
+
v0.7.4
|
104
|
+
-- Fixed bug with get_user_from_cookies
|
105
|
+
|
106
|
+
v0.7.3
|
107
|
+
-- Added support for picture sizes -- thanks thhermansen for the patch!
|
108
|
+
-- Adjusted the return values for several methods (get_access_token, get_app_access_token, get_token_from_session_key, get_tokens_from_session_keys, get_user_from_cookies)
|
109
|
+
-- These methods now return strings, rather than hashes, which makes more sense
|
110
|
+
-- The strings are overloaded with an [] method for backwards compatibility (Ruby is truly amazing)
|
111
|
+
-- Using those methods triggers a deprecation warning
|
112
|
+
-- This will be removed by 1.0
|
113
|
+
-- There are new info methods (get_access_token_info, get_app_access_token_info, get_token_info_from_session_keys, and get_user_info_from_cookies) that natively return hashes, for when you want the expiration date
|
114
|
+
-- Responses with HTTP status 500+ now properly throw errors under Net::HTTP
|
115
|
+
-- Updated changelog
|
116
|
+
-- Added license
|
117
|
+
|
118
|
+
v0.7.2
|
119
|
+
-- Added support for exchanging session keys for OAuth access tokens (get_token_from_session_key for single keys, get_tokens_from_session_keys for multiple)
|
120
|
+
-- Moved Koala files into a koala/ subdirectory to minimize risk of name collisions
|
121
|
+
-- Added OAuth Playground git submodule as an example
|
122
|
+
-- Updated tests, readme, and changelog
|
123
|
+
|
124
|
+
v0.7.1
|
125
|
+
-- Updated RealtimeUpdates#list_subscriptions and GraphAPI#get_connections to now return an
|
126
|
+
array of results directly (rather than a hash with one key)
|
127
|
+
-- Fixed a bug with Net::HTTP-based HTTP service in which the headers hash was improperly formatted
|
128
|
+
-- Updated readme
|
129
|
+
|
130
|
+
v0.7.0
|
131
|
+
-- Added RealtimeUpdates class, which can be used to manage subscriptions for user updates (see http://developers.facebook.com/docs/api/realtime)
|
132
|
+
-- Added picture method to graph API, which fetches an object's picture from the redirect headers.
|
133
|
+
-- Added _greatly_ improved testing with result mocking, which is now the default set of tests
|
134
|
+
-- Renamed live testing spec to koala_spec_without_mocks.rb
|
135
|
+
-- Added Koala::Response class, which encapsulates HTTP results since Facebook sometimes sends data in the status or headers
|
136
|
+
-- Much internal refactoring
|
137
|
+
-- Updated readme, changelog, etc.
|
138
|
+
|
139
|
+
|
140
|
+
v0.6.0
|
141
|
+
-- Added support for the old REST API thanks to cbaclig's great work
|
142
|
+
-- Updated tests to conform to RSpec standards
|
143
|
+
-- Updated changelog, readme, etc.
|
144
|
+
|
145
|
+
v0.5.1
|
146
|
+
-- Documentation is now on the wiki, updated readme accordingly.
|
147
|
+
|
148
|
+
v0.5.0
|
149
|
+
-- Added several new OAuth methods for making and parsing access token requests
|
150
|
+
-- Added test suite for the OAuth class
|
151
|
+
-- Made second argument to url_for_access_token a hash (strings still work but trigger a deprecation warning)
|
152
|
+
-- Added fields to facebook_data.yml
|
153
|
+
-- Updated readme
|
154
|
+
|
155
|
+
v0.4.1
|
156
|
+
-- Encapsulated GraphAPI and OAuth classes in the Koala::Facebook module for clarity (and to avoid claiming the global Facebook class)
|
157
|
+
-- Moved make_request method to Koala class from GraphAPI instance (for use by future OAuth class functionality)
|
158
|
+
-- Renamed request method to api for consistancy with Javascript library
|
159
|
+
-- Updated tests and readme
|
160
|
+
|
161
|
+
v0.4.0
|
162
|
+
-- Adopted the Koala name
|
163
|
+
-- Updated readme and tests
|
164
|
+
-- Fixed cookie verification bug for non-expiring OAuth tokens
|
165
|
+
|
166
|
+
v0.3.1
|
167
|
+
-- Bug fixes.
|
168
|
+
|
169
|
+
v0.3
|
170
|
+
-- Renamed Graph API class from Facebook::GraphAPI to FacebookGraph::API
|
171
|
+
-- Created FacebookGraph::OAuth class for tokens and OAuth URLs
|
172
|
+
-- Updated method for including HTTP service (think we've got it this time)
|
173
|
+
-- Updated tests
|
174
|
+
-- Added CHANGELOG and gemspec
|
175
|
+
|
176
|
+
v0.2
|
177
|
+
-- Gemified the project
|
178
|
+
-- Split out HTTP services into their own file, and adjusted inclusion method
|
179
|
+
|
180
|
+
v0.1
|
181
|
+
-- Added modular support for Typhoeus
|
182
|
+
-- Added tests
|
183
|
+
|
184
|
+
v0.0
|
185
|
+
-- Hi from F8! Basic read/write from the graph is working
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010-2011 Alex Koppel
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
LICENSE
|
3
|
+
Manifest
|
4
|
+
Rakefile
|
5
|
+
init.rb
|
6
|
+
koala.gemspec
|
7
|
+
lib/koala.rb
|
8
|
+
lib/koala/graph_api.rb
|
9
|
+
lib/koala/http_services.rb
|
10
|
+
lib/koala/realtime_updates.rb
|
11
|
+
lib/koala/rest_api.rb
|
12
|
+
lib/koala/test_users.rb
|
13
|
+
lib/koala/uploadable_io.rb
|
14
|
+
readme.md
|
15
|
+
spec/facebook_data.yml
|
16
|
+
spec/koala/api_base_tests.rb
|
17
|
+
spec/koala/assets/beach.jpg
|
18
|
+
spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb
|
19
|
+
spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb
|
20
|
+
spec/koala/graph_api/graph_api_no_access_token_tests.rb
|
21
|
+
spec/koala/graph_api/graph_api_tests.rb
|
22
|
+
spec/koala/graph_api/graph_api_with_access_token_tests.rb
|
23
|
+
spec/koala/graph_api/graph_collection_tests.rb
|
24
|
+
spec/koala/http_services/http_service_tests.rb
|
25
|
+
spec/koala/http_services/net_http_service_tests.rb
|
26
|
+
spec/koala/http_services/typhoeus_service_tests.rb
|
27
|
+
spec/koala/live_testing_data_helper.rb
|
28
|
+
spec/koala/oauth/oauth_tests.rb
|
29
|
+
spec/koala/realtime_updates/realtime_updates_tests.rb
|
30
|
+
spec/koala/rest_api/rest_api_no_access_token_tests.rb
|
31
|
+
spec/koala/rest_api/rest_api_tests.rb
|
32
|
+
spec/koala/rest_api/rest_api_with_access_token_tests.rb
|
33
|
+
spec/koala/test_users/test_users_tests.rb
|
34
|
+
spec/koala/uploadable_io/uploadable_io_tests.rb
|
35
|
+
spec/koala_spec.rb
|
36
|
+
spec/koala_spec_helper.rb
|
37
|
+
spec/koala_spec_without_mocks.rb
|
38
|
+
spec/mock_facebook_responses.yml
|
39
|
+
spec/mock_http_service.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
rescue LoadError
|
7
|
+
puts 'although not required, bundler is recommened for running the tests'
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
task :default => :spec
|
12
|
+
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new do |t|
|
15
|
+
t.rspec_opts = ["--color", '--format doc']
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/koala.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tyler_koala}
|
5
|
+
s.version = "1.2.0beta"
|
6
|
+
s.date = %q{2011-07-16}
|
7
|
+
|
8
|
+
s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.}
|
9
|
+
s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
|
10
|
+
s.homepage = %q{http://github.com/arsduo/koala}
|
11
|
+
|
12
|
+
s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
|
13
|
+
s.email = %q{alex@alexkoppel.com}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
|
18
|
+
s.extra_rdoc_files = ["readme.md", "CHANGELOG"]
|
19
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala"]
|
20
|
+
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.rubygems_version = %q{1.4.2}
|
24
|
+
|
25
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
26
|
+
|
27
|
+
if s.respond_to? :specification_version then
|
28
|
+
s.specification_version = 3
|
29
|
+
|
30
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
31
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
|
32
|
+
s.add_runtime_dependency(%q<faraday>, ["~> 0.7.4"])
|
33
|
+
s.add_runtime_dependency(%q<faraday-stack>, ["~> 0.1.3"])
|
34
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
35
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
38
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
39
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
40
|
+
s.add_dependency(%q<faraday>, ["~> 0.7.4"])
|
41
|
+
s.add_dependency(%q<faraday-stack>, ["~> 0.1.3"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
45
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
46
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
47
|
+
s.add_dependency(%q<faraday>, ["~> 0.7.4"])
|
48
|
+
s.add_dependency(%q<faraday-stack>, ["~> 0.1.3"])
|
49
|
+
end
|
50
|
+
end
|
data/lib/koala.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
require 'multi_json'
|
5
|
+
|
6
|
+
# OpenSSL and Base64 are required to support signed_request
|
7
|
+
require 'openssl'
|
8
|
+
require 'base64'
|
9
|
+
|
10
|
+
# include koala modules
|
11
|
+
require 'koala/http_service'
|
12
|
+
require 'koala/oauth'
|
13
|
+
require 'koala/graph_api'
|
14
|
+
require 'koala/graph_batch_api'
|
15
|
+
require 'koala/batch_operation'
|
16
|
+
require 'koala/graph_collection'
|
17
|
+
require 'koala/rest_api'
|
18
|
+
require 'koala/realtime_updates'
|
19
|
+
require 'koala/test_users'
|
20
|
+
require 'koala/utils'
|
21
|
+
|
22
|
+
# add KoalaIO class
|
23
|
+
require 'koala/uploadable_io'
|
24
|
+
|
25
|
+
module Koala
|
26
|
+
|
27
|
+
module Facebook
|
28
|
+
# Ruby client library for the Facebook Platform.
|
29
|
+
# Copyright 2010-2011 Alex Koppel
|
30
|
+
# Contributors: Alex Koppel, Chris Baclig, Rafi Jacoby, and the team at Context Optional
|
31
|
+
# http://github.com/arsduo/koala
|
32
|
+
|
33
|
+
# APIs
|
34
|
+
class API
|
35
|
+
# initialize with an access token
|
36
|
+
def initialize(access_token = nil)
|
37
|
+
@access_token = access_token
|
38
|
+
end
|
39
|
+
attr_reader :access_token
|
40
|
+
|
41
|
+
include GraphAPIMethods
|
42
|
+
include RestAPIMethods
|
43
|
+
|
44
|
+
def api(path, args = {}, verb = "get", options = {}, &error_checking_block)
|
45
|
+
# Fetches the given path in the Graph API.
|
46
|
+
args["access_token"] = @access_token || @app_access_token if @access_token || @app_access_token
|
47
|
+
|
48
|
+
# add a leading /
|
49
|
+
path = "/#{path}" unless path =~ /^\//
|
50
|
+
|
51
|
+
# make the request via the provided service
|
52
|
+
result = Koala.make_request(path, args, verb, options)
|
53
|
+
|
54
|
+
# Check for any 500 errors before parsing the body
|
55
|
+
# since we're not guaranteed that the body is valid JSON
|
56
|
+
# in the case of a server error
|
57
|
+
raise APIError.new({"type" => "HTTP #{result.status.to_s}", "message" => "Response body: #{result.body}"}) if result.status >= 500
|
58
|
+
|
59
|
+
# parse the body as JSON and run it through the error checker (if provided)
|
60
|
+
# Note: Facebook sometimes sends results like "true" and "false", which aren't strictly objects
|
61
|
+
# and cause MultiJson.decode to fail -- so we account for that by wrapping the result in []
|
62
|
+
body = MultiJson.decode("[#{result.body.to_s}]")[0]
|
63
|
+
yield body if error_checking_block
|
64
|
+
|
65
|
+
# if we want a component other than the body (e.g. redirect header for images), return that
|
66
|
+
options[:http_component] ? result.send(options[:http_component]) : body
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# special enhanced APIs
|
71
|
+
class GraphBatchAPI < API
|
72
|
+
include GraphBatchAPIMethods
|
73
|
+
end
|
74
|
+
|
75
|
+
class RealtimeUpdates
|
76
|
+
include RealtimeUpdateMethods
|
77
|
+
end
|
78
|
+
|
79
|
+
class TestUsers
|
80
|
+
include TestUserMethods
|
81
|
+
end
|
82
|
+
|
83
|
+
# legacy support for old APIs
|
84
|
+
class OldAPI < API;
|
85
|
+
def initialize(*args)
|
86
|
+
Koala::Utils.deprecate("#{self.class.name} is deprecated and will be removed in a future version; please use the API class instead.")
|
87
|
+
super
|
88
|
+
end
|
89
|
+
end
|
90
|
+
class GraphAPI < OldAPI; end
|
91
|
+
class RestAPI < OldAPI; end
|
92
|
+
class GraphAndRestAPI < OldAPI; end
|
93
|
+
|
94
|
+
# Errors
|
95
|
+
|
96
|
+
class APIError < StandardError
|
97
|
+
attr_accessor :fb_error_type
|
98
|
+
def initialize(details = {})
|
99
|
+
self.fb_error_type = details["type"]
|
100
|
+
super("#{fb_error_type}: #{details["message"]}")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class KoalaError < StandardError; end
|
106
|
+
|
107
|
+
|
108
|
+
# finally, the few things defined on the Koala module itself
|
109
|
+
class << self
|
110
|
+
attr_accessor :http_service
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.make_request(path, args, verb, options = {})
|
114
|
+
http_service.make_request(path, args, verb, options)
|
115
|
+
end
|
116
|
+
|
117
|
+
# we use Faraday as our main service, with mock as the other main one
|
118
|
+
self.http_service = HTTPService
|
119
|
+
end
|