koala 1.0.0.beta → 1.1.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.
- data/.autotest +12 -0
- data/.gitignore +5 -0
- data/.travis.yml +8 -0
- data/CHANGELOG +42 -4
- data/Gemfile +7 -0
- data/LICENSE +1 -1
- data/Manifest +5 -2
- data/Rakefile +13 -14
- data/autotest/discover.rb +1 -0
- data/koala.gemspec +35 -20
- data/lib/koala/batch_operation.rb +74 -0
- data/lib/koala/graph_api.rb +196 -143
- data/lib/koala/graph_batch_api.rb +87 -0
- data/lib/koala/graph_collection.rb +54 -0
- data/lib/koala/http_services/net_http_service.rb +92 -0
- data/lib/koala/http_services/typhoeus_service.rb +37 -0
- data/lib/koala/http_services.rb +15 -124
- data/lib/koala/oauth.rb +181 -0
- data/lib/koala/realtime_updates.rb +5 -14
- data/lib/koala/rest_api.rb +13 -8
- data/lib/koala/test_users.rb +21 -8
- data/lib/koala/uploadable_io.rb +175 -0
- data/lib/koala.rb +48 -240
- data/readme.md +60 -28
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_batch_spec.rb +609 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +129 -0
- data/spec/cases/http_services/net_http_service_spec.rb +532 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +152 -0
- data/spec/cases/koala_spec.rb +55 -0
- data/spec/cases/oauth_spec.rb +409 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +47 -34
- data/spec/cases/uploadable_io_spec.rb +193 -0
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +12 -14
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +408 -306
- data/spec/spec_helper.rb +19 -0
- data/spec/support/graph_api_shared_examples.rb +495 -0
- data/spec/support/json_testing_fix.rb +18 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/support/mock_http_service.rb +96 -0
- data/spec/support/rest_api_shared_examples.rb +285 -0
- data/spec/support/setup_mocks_or_live.rb +51 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +110 -64
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -102
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -63
- data/spec/koala/graph_api/graph_api_tests.rb +0 -86
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -154
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/net_http_service_tests.rb +0 -430
- data/spec/koala/oauth/oauth_tests.rb +0 -409
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
- data/spec/koala/rest_api/rest_api_tests.rb +0 -118
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
- data/spec/koala/typhoeus_service_tests.rb +0 -156
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -70
- data/spec/koala_spec_without_mocks.rb +0 -19
- data/spec/mock_http_service.rb +0 -96
- /data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
data/.autotest
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
|
+
v1.1
|
|
2
|
+
New methods:
|
|
3
|
+
-- Added Batch API support (thanks, seejohnrun and spiegela!)
|
|
4
|
+
-- includes file uploads, error handling, and FQL
|
|
5
|
+
-- Added GraphAPI#put_video
|
|
6
|
+
-- Added GraphAPI#get_comments_for_urls (thanks, amrnt!)
|
|
7
|
+
-- Added RestAPI#fql_multiquery, which simplifies the results (thanks, amrnt!)
|
|
8
|
+
-- HTTP services support global proxy and timeout settings (thanks, itchy!)
|
|
9
|
+
-- Net::HTTP supports global ca_path, ca_file, and verify_mode settings (thanks, spiegela!)
|
|
10
|
+
Updated methods:
|
|
11
|
+
-- RealtimeUpdates now uses a GraphAPI object instead of its own API
|
|
12
|
+
-- RestAPI#rest_call now has an optional last argument for method, for calls requiring POST, DELETE, etc. (thanks, sshilo!)
|
|
13
|
+
-- Filename can now be specified when uploading (e.g. for Ads API) (thanks, sshilo!)
|
|
14
|
+
-- get_objects([]) returns [] instead of a Facebook error in non-batch mode (thanks, aselder!)
|
|
15
|
+
Internal improvements:
|
|
16
|
+
-- Koala is now more compatible with other Rubies (JRuby, Rubinius, etc.)
|
|
17
|
+
-- HTTP services are more modular and can be changed on the fly (thanks, chadk!)
|
|
18
|
+
-- Includes support for uploading StringIOs and other non-files via Net::HTTP even when using TyphoeusService
|
|
19
|
+
-- Koala now uses multi_json to improve compatibility with Rubinius and other Ruby versions
|
|
20
|
+
-- Koala now uses the modern Typhoeus API (thanks, aselder!)
|
|
21
|
+
-- Koala now uses the current modern Net::HTTP interface (thanks, romanbsd!)
|
|
22
|
+
-- Fixed bugs and typos (thanks, waynn, mokevnin, and tikh!)
|
|
23
|
+
|
|
1
24
|
v1.0
|
|
2
25
|
New methods:
|
|
3
|
-
-- Photo and file upload now supported through #put_picture
|
|
4
|
-
-- Added
|
|
5
|
-
|
|
26
|
+
-- Photo and file upload now supported through #put_picture
|
|
27
|
+
-- Added UploadableIO class to manage file uploads
|
|
28
|
+
-- Added a delete_like method (thanks to waseem)
|
|
29
|
+
-- Added put_connection and delete_connection convenience methods
|
|
30
|
+
Updated methods:
|
|
31
|
+
-- Search can now search places, checkins, etc. (thanks, rickyc!)
|
|
32
|
+
-- You can now pass :beta => true in the http options to use Facebook's beta tier
|
|
33
|
+
-- TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks, pulsd and kbighorse!)
|
|
34
|
+
-- All methods now accept an http_options hash as their optional last parameter (thanks, spiegela!)
|
|
35
|
+
-- url_for_oauth_code can now take a :display option (thanks, netbe!)
|
|
36
|
+
-- Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
|
|
37
|
+
-- Test users now supports using test accounts across multiple apps
|
|
38
|
+
Internal improvements:
|
|
6
39
|
-- For public requests, Koala now uses http by default (instead of https) to improve speed
|
|
7
40
|
-- This can be overridden through Koala.always_use_ssl= or by passing :use_ssl => true in the options hash for an api call
|
|
8
41
|
-- Read-only REST API requests now go through the faster api-read server
|
|
9
42
|
-- Replaced parse_signed_request with a version from Facebook that also supports the new signed params proposal
|
|
10
43
|
-- Note: invalid requests will now raise exceptions rather than return nil, in keeping with other SDKs
|
|
11
|
-
--
|
|
44
|
+
-- Delete methods will now raise an error if there's no access token (like put_object and delete_like)
|
|
45
|
+
-- Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
|
|
46
|
+
-- APIError is now < StandardError, not Exception
|
|
47
|
+
-- Added KoalaError for non-API errors
|
|
48
|
+
-- Net::HTTP's SSL verification is no longer disabled by default
|
|
12
49
|
Test improvements:
|
|
50
|
+
-- Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
|
|
13
51
|
-- Expanded HTTP service tests (added Typhoeus test suite and additional Net::HTTP test cases)
|
|
14
52
|
-- Live tests now verify that the access token has the necessary permissions before starting
|
|
15
53
|
-- Replaced the 50-person network test, which often took 15+ minutes to run live, with a 5-person test
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/Manifest
CHANGED
|
@@ -10,6 +10,7 @@ lib/koala/http_services.rb
|
|
|
10
10
|
lib/koala/realtime_updates.rb
|
|
11
11
|
lib/koala/rest_api.rb
|
|
12
12
|
lib/koala/test_users.rb
|
|
13
|
+
lib/koala/uploadable_io.rb
|
|
13
14
|
readme.md
|
|
14
15
|
spec/facebook_data.yml
|
|
15
16
|
spec/koala/api_base_tests.rb
|
|
@@ -20,15 +21,17 @@ spec/koala/graph_api/graph_api_no_access_token_tests.rb
|
|
|
20
21
|
spec/koala/graph_api/graph_api_tests.rb
|
|
21
22
|
spec/koala/graph_api/graph_api_with_access_token_tests.rb
|
|
22
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
|
|
23
27
|
spec/koala/live_testing_data_helper.rb
|
|
24
|
-
spec/koala/net_http_service_tests.rb
|
|
25
28
|
spec/koala/oauth/oauth_tests.rb
|
|
26
29
|
spec/koala/realtime_updates/realtime_updates_tests.rb
|
|
27
30
|
spec/koala/rest_api/rest_api_no_access_token_tests.rb
|
|
28
31
|
spec/koala/rest_api/rest_api_tests.rb
|
|
29
32
|
spec/koala/rest_api/rest_api_with_access_token_tests.rb
|
|
30
33
|
spec/koala/test_users/test_users_tests.rb
|
|
31
|
-
spec/koala/
|
|
34
|
+
spec/koala/uploadable_io/uploadable_io_tests.rb
|
|
32
35
|
spec/koala_spec.rb
|
|
33
36
|
spec/koala_spec_helper.rb
|
|
34
37
|
spec/koala_spec_without_mocks.rb
|
data/Rakefile
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
# Rakefile
|
|
2
|
-
require 'rubygems'
|
|
3
1
|
require 'rake'
|
|
4
|
-
require 'echoe'
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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']
|
|
17
16
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/koala.gemspec
CHANGED
|
@@ -1,35 +1,50 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
|
-
s.name
|
|
5
|
-
s.version = "1.
|
|
4
|
+
s.name = %q{koala}
|
|
5
|
+
s.version = "1.1.0"
|
|
6
|
+
s.date = %q{2011-07-18}
|
|
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}
|
|
6
11
|
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
12
|
s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
|
|
9
|
-
s.
|
|
10
|
-
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
|
|
14
|
-
s.
|
|
15
|
-
s.rdoc_options
|
|
16
|
-
|
|
17
|
-
s.
|
|
18
|
-
|
|
19
|
-
s.
|
|
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=
|
|
20
26
|
|
|
21
27
|
if s.respond_to? :specification_version then
|
|
22
28
|
s.specification_version = 3
|
|
23
29
|
|
|
24
30
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
25
|
-
s.add_runtime_dependency(%q<
|
|
26
|
-
s.add_runtime_dependency(%q<multipart-post>,
|
|
31
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
|
|
32
|
+
s.add_runtime_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
33
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
|
34
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
|
35
|
+
s.add_development_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
27
36
|
else
|
|
28
|
-
s.add_dependency(%q<
|
|
29
|
-
s.add_dependency(%q<multipart-post>,
|
|
37
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
|
38
|
+
s.add_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
39
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
|
40
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
|
41
|
+
s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
30
42
|
end
|
|
31
43
|
else
|
|
32
|
-
s.add_dependency(%q<
|
|
33
|
-
s.add_dependency(%q<multipart-post>,
|
|
44
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
|
45
|
+
s.add_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
46
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
|
47
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
|
48
|
+
s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
34
49
|
end
|
|
35
50
|
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Koala
|
|
2
|
+
module Facebook
|
|
3
|
+
class BatchOperation
|
|
4
|
+
attr_reader :access_token, :http_options, :post_processing, :files, :batch_api, :identifier
|
|
5
|
+
|
|
6
|
+
@identifier = 0
|
|
7
|
+
|
|
8
|
+
def self.next_identifier
|
|
9
|
+
@identifier += 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
@identifier = self.class.next_identifier
|
|
14
|
+
@args = (options[:args] || {}).dup # because we modify it below
|
|
15
|
+
@access_token = options[:access_token]
|
|
16
|
+
@http_options = (options[:http_options] || {}).dup # dup because we modify it below
|
|
17
|
+
@batch_args = @http_options.delete(:batch_args) || {}
|
|
18
|
+
@url = options[:url]
|
|
19
|
+
@method = options[:method].to_sym
|
|
20
|
+
@post_processing = options[:post_processing]
|
|
21
|
+
|
|
22
|
+
process_binary_args
|
|
23
|
+
|
|
24
|
+
raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_batch_params(main_access_token)
|
|
28
|
+
# set up the arguments
|
|
29
|
+
args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token))
|
|
30
|
+
|
|
31
|
+
response = {
|
|
32
|
+
:method => @method.to_s,
|
|
33
|
+
:relative_url => @url,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# handle batch-level arguments, such as name, depends_on, and attached_files
|
|
37
|
+
@batch_args[:attached_files] = @files.keys.join(",") if @files
|
|
38
|
+
response.merge!(@batch_args) if @batch_args
|
|
39
|
+
|
|
40
|
+
# for get and delete, we append args to the URL string
|
|
41
|
+
# otherwise, they go in the body
|
|
42
|
+
if args_string.length > 0
|
|
43
|
+
if args_in_url?
|
|
44
|
+
response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0
|
|
45
|
+
else
|
|
46
|
+
response[:body] = args_string if args_string.length > 0
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
response
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
def process_binary_args
|
|
56
|
+
# collect binary files
|
|
57
|
+
@args.each_pair do |key, value|
|
|
58
|
+
if UploadableIO.binary_content?(value)
|
|
59
|
+
@files ||= {}
|
|
60
|
+
# we use a class-level counter to ensure unique file identifiers across multiple batch operations
|
|
61
|
+
# (this is thread safe, since we just care about uniqueness)
|
|
62
|
+
# so remove the file from the original hash and add it to the file store
|
|
63
|
+
id = "op#{identifier}_file#{@files.keys.length}"
|
|
64
|
+
@files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def args_in_url?
|
|
70
|
+
@method == :get || @method == :delete
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|