koala 0.10.0 → 1.0.0.rc
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/.gitignore +3 -0
- data/CHANGELOG +39 -7
- data/Gemfile +3 -0
- data/Manifest +8 -1
- data/Rakefile +13 -14
- data/koala.gemspec +36 -19
- data/lib/koala/graph_api.rb +188 -123
- data/lib/koala/http_services.rb +93 -18
- data/lib/koala/rest_api.rb +73 -6
- data/lib/koala/test_users.rb +21 -8
- data/lib/koala/uploadable_io.rb +115 -0
- data/lib/koala.rb +86 -86
- data/readme.md +18 -12
- 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_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +54 -0
- data/spec/cases/http_services/net_http_service_spec.rb +350 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
- data/spec/cases/oauth_spec.rb +374 -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} +78 -72
- data/spec/cases/uploadable_io_spec.rb +151 -0
- data/spec/fixtures/beach.jpg +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +13 -9
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +312 -289
- data/spec/spec_helper.rb +18 -0
- data/spec/support/graph_api_shared_examples.rb +424 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -81
- data/spec/support/rest_api_shared_examples.rb +161 -0
- data/spec/support/setup_mocks_or_live.rb +52 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +130 -43
- 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 -10
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/net_http_service_tests.rb +0 -186
- data/spec/koala/oauth/oauth_tests.rb +0 -438
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -48
- data/spec/koala_spec_without_mocks.rb +0 -19
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala RestAPI without an access token" do
|
|
2
|
-
# REST_CALL
|
|
3
|
-
describe "when making a rest request" do
|
|
4
|
-
it "should use the proper path" do
|
|
5
|
-
method = stub('methodName')
|
|
6
|
-
@api.should_receive(:api).with(
|
|
7
|
-
"method/#{method}",
|
|
8
|
-
anything,
|
|
9
|
-
anything,
|
|
10
|
-
anything
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
@api.rest_call(method)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should always use the rest api" do
|
|
17
|
-
@api.should_receive(:api).with(
|
|
18
|
-
anything,
|
|
19
|
-
anything,
|
|
20
|
-
anything,
|
|
21
|
-
:rest_api => true
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
@api.rest_call('anything')
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should take an optional hash of arguments" do
|
|
28
|
-
args = {:arg1 => 'arg1'}
|
|
29
|
-
|
|
30
|
-
@api.should_receive(:api).with(
|
|
31
|
-
anything,
|
|
32
|
-
hash_including(args),
|
|
33
|
-
anything,
|
|
34
|
-
anything
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
@api.rest_call('anything', args)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "should always ask for JSON" do
|
|
41
|
-
@api.should_receive(:api).with(
|
|
42
|
-
anything,
|
|
43
|
-
hash_including('format' => 'json'),
|
|
44
|
-
anything,
|
|
45
|
-
anything
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
@api.rest_call('anything')
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# FQL_QUERY
|
|
53
|
-
describe "when making a FQL request" do
|
|
54
|
-
it "should call fql.query method" do
|
|
55
|
-
@api.should_receive(:rest_call).with(
|
|
56
|
-
"fql.query",
|
|
57
|
-
anything
|
|
58
|
-
).and_return(Koala::Response.new(200, "2", {}))
|
|
59
|
-
|
|
60
|
-
@api.fql_query stub('query string')
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "should pass a query argument" do
|
|
64
|
-
query = stub('query string')
|
|
65
|
-
|
|
66
|
-
@api.should_receive(:rest_call).with(
|
|
67
|
-
anything,
|
|
68
|
-
hash_including("query" => query)
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
@api.fql_query(query)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should be able to access public information via FQL" do
|
|
75
|
-
@result = @api.fql_query("select first_name from user where uid = 216743")
|
|
76
|
-
@result.size.should == 1
|
|
77
|
-
@result.first["first_name"].should == "Chris"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "should not be able to access protected information via FQL" do
|
|
81
|
-
lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
class FacebookRestAPINoAccessTokenTest < Test::Unit::TestCase
|
|
87
|
-
describe "Koala RestAPI without an access token" do
|
|
88
|
-
before :each do
|
|
89
|
-
@api = Koala::Facebook::RestAPI.new
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it_should_behave_like "Koala RestAPI without an access token"
|
|
93
|
-
end
|
|
94
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala RestAPI with an access token" do
|
|
2
|
-
# FQL
|
|
3
|
-
it "should be able to access public information via FQL" do
|
|
4
|
-
result = @api.fql_query('select first_name from user where uid = 216743')
|
|
5
|
-
result.size.should == 1
|
|
6
|
-
result.first['first_name'].should == 'Chris'
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should be able to access protected information via FQL" do
|
|
10
|
-
# Tests agains the permissions fql table
|
|
11
|
-
|
|
12
|
-
# get the current user's ID
|
|
13
|
-
# we're sneakily using the Graph API, which should be okay since it has its own tests
|
|
14
|
-
g = Koala::Facebook::GraphAPI.new(@token)
|
|
15
|
-
id = g.get_object("me", :fields => "id")["id"]
|
|
16
|
-
|
|
17
|
-
# now send a query about your permissions
|
|
18
|
-
result = @api.fql_query("select read_stream from permissions where uid = #{id}")
|
|
19
|
-
|
|
20
|
-
result.size.should == 1
|
|
21
|
-
# we assume that you have read_stream permissions, so we can test against that
|
|
22
|
-
# (should we keep this?)
|
|
23
|
-
result.first["read_stream"].should == 1
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class FacebookRestAPIWithAccessTokenTests < Test::Unit::TestCase
|
|
28
|
-
describe "Koala RestAPI with an access token" do
|
|
29
|
-
include LiveTestingDataHelper
|
|
30
|
-
it_should_behave_like "Koala RestAPI with an access token"
|
|
31
|
-
|
|
32
|
-
before :each do
|
|
33
|
-
@api = Koala::Facebook::RestAPI.new(@token)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/spec/koala_spec.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'koala_spec_helper'
|
|
2
|
-
require 'mock_http_service'
|
|
3
|
-
|
|
4
|
-
# Runs Koala specs using stubs for HTTP requests
|
|
5
|
-
#
|
|
6
|
-
# Valid OAuth token and code are not necessary to run these
|
|
7
|
-
# specs. Because of this, specs do not fail due to Facebook
|
|
8
|
-
# imposed rate-limits or server timeouts.
|
|
9
|
-
#
|
|
10
|
-
# However as a result they are more brittle since
|
|
11
|
-
# we are not testing the latest responses from the Facebook servers.
|
|
12
|
-
# Therefore, to be certain all specs pass with the current
|
|
13
|
-
# Facebook services, run koala_spec_without_mocks.rb.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Koala.http_service = Koala::MockHTTPService
|
|
17
|
-
|
|
18
|
-
$testing_data = Koala::MockHTTPService::TEST_DATA
|
data/spec/koala_spec_helper.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
if defined?(RUBY_VERSION) && RUBY_VERSION =~ /1\.9/
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
require 'rspec'
|
|
4
|
-
|
|
5
|
-
Rspec.configure do |c|
|
|
6
|
-
c.mock_with :rspec
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
else
|
|
10
|
-
# Ruby 1.8.x
|
|
11
|
-
require 'test/unit'
|
|
12
|
-
require 'rubygems'
|
|
13
|
-
|
|
14
|
-
require 'spec/test/unit'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# load the libraries
|
|
18
|
-
require 'koala'
|
|
19
|
-
|
|
20
|
-
# load testing data libraries
|
|
21
|
-
require 'koala/live_testing_data_helper'
|
|
22
|
-
|
|
23
|
-
# API tests
|
|
24
|
-
require 'koala/api_base_tests'
|
|
25
|
-
|
|
26
|
-
require 'koala/graph_api/graph_collection_tests'
|
|
27
|
-
require 'koala/graph_api/graph_api_no_access_token_tests'
|
|
28
|
-
require 'koala/graph_api/graph_api_with_access_token_tests'
|
|
29
|
-
|
|
30
|
-
require 'koala/rest_api/rest_api_no_access_token_tests'
|
|
31
|
-
require 'koala/rest_api/rest_api_with_access_token_tests'
|
|
32
|
-
|
|
33
|
-
require 'koala/graph_and_rest_api/graph_and_rest_api_no_token_tests'
|
|
34
|
-
require 'koala/graph_and_rest_api/graph_and_rest_api_with_token_tests'
|
|
35
|
-
|
|
36
|
-
# OAuth tests
|
|
37
|
-
require 'koala/oauth/oauth_tests'
|
|
38
|
-
|
|
39
|
-
# Subscriptions tests
|
|
40
|
-
require 'koala/realtime_updates/realtime_updates_tests'
|
|
41
|
-
|
|
42
|
-
# Services tests
|
|
43
|
-
require 'koala/net_http_service_tests'
|
|
44
|
-
|
|
45
|
-
# Test users tests
|
|
46
|
-
require 'koala/test_users/test_users_tests'
|
|
47
|
-
|
|
48
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'koala_spec_helper'
|
|
2
|
-
|
|
3
|
-
# Runs Koala specs through the Facebook servers
|
|
4
|
-
#
|
|
5
|
-
# Note that you need a valid OAuth token and code for these
|
|
6
|
-
# specs to run. See facebook_data.yml for more information.
|
|
7
|
-
|
|
8
|
-
# load testing data (see note in readme.md)
|
|
9
|
-
# I'm seeing a bug with spec and gets where the facebook_test_suite.rb file gets read in when gets is called
|
|
10
|
-
# until that's solved, we'll need to store/update tokens in the access_token file
|
|
11
|
-
$testing_data = YAML.load_file(File.join(File.dirname(__FILE__), 'facebook_data.yml')) rescue {}
|
|
12
|
-
|
|
13
|
-
unless $testing_data["oauth_token"]
|
|
14
|
-
puts "Access token tests will fail until you store a valid token in facebook_data.yml"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
|
|
18
|
-
puts "OAuth code tests will fail until you store valid data for the user's OAuth code and the app secret in facebook_data.yml"
|
|
19
|
-
end
|