koala 0.9.0 → 1.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.
Files changed (66) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +47 -7
  3. data/Gemfile +3 -0
  4. data/LICENSE +1 -1
  5. data/Manifest +10 -15
  6. data/Rakefile +13 -13
  7. data/koala.gemspec +36 -16
  8. data/lib/koala/graph_api.rb +188 -123
  9. data/lib/koala/http_services.rb +93 -18
  10. data/lib/koala/rest_api.rb +73 -6
  11. data/lib/koala/test_users.rb +85 -0
  12. data/lib/koala/uploadable_io.rb +115 -0
  13. data/lib/koala.rb +114 -116
  14. data/readme.md +32 -18
  15. data/spec/cases/api_base_spec.rb +101 -0
  16. data/spec/cases/graph_and_rest_api_spec.rb +31 -0
  17. data/spec/cases/graph_api_spec.rb +25 -0
  18. data/spec/cases/http_services/http_service_spec.rb +54 -0
  19. data/spec/cases/http_services/net_http_service_spec.rb +350 -0
  20. data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
  21. data/spec/cases/oauth_spec.rb +409 -0
  22. data/spec/cases/realtime_updates_spec.rb +184 -0
  23. data/spec/cases/rest_api_spec.rb +25 -0
  24. data/spec/cases/test_users_spec.rb +221 -0
  25. data/spec/cases/uploadable_io_spec.rb +151 -0
  26. data/spec/fixtures/beach.jpg +0 -0
  27. data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +18 -14
  28. data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +314 -241
  29. data/spec/spec_helper.rb +18 -0
  30. data/spec/support/graph_api_shared_examples.rb +424 -0
  31. data/spec/support/live_testing_data_helper.rb +40 -0
  32. data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -80
  33. data/spec/support/rest_api_shared_examples.rb +161 -0
  34. data/spec/support/setup_mocks_or_live.rb +52 -0
  35. data/spec/support/uploadable_io_shared_examples.rb +76 -0
  36. metadata +140 -55
  37. data/examples/oauth_playground/Capfile +0 -2
  38. data/examples/oauth_playground/LICENSE +0 -22
  39. data/examples/oauth_playground/Rakefile +0 -4
  40. data/examples/oauth_playground/config/deploy.rb +0 -39
  41. data/examples/oauth_playground/config/facebook.yml +0 -13
  42. data/examples/oauth_playground/config.ru +0 -27
  43. data/examples/oauth_playground/lib/load_facebook.rb +0 -3
  44. data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
  45. data/examples/oauth_playground/readme.md +0 -8
  46. data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
  47. data/examples/oauth_playground/spec/spec_helper.rb +0 -36
  48. data/examples/oauth_playground/tmp/restart.txt +0 -0
  49. data/examples/oauth_playground/views/index.erb +0 -206
  50. data/examples/oauth_playground/views/layout.erb +0 -39
  51. data/init.rb +0 -2
  52. data/spec/koala/api_base_tests.rb +0 -95
  53. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
  54. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
  55. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
  56. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
  57. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  58. data/spec/koala/live_testing_data_helper.rb +0 -15
  59. data/spec/koala/net_http_service_tests.rb +0 -181
  60. data/spec/koala/oauth/oauth_tests.rb +0 -440
  61. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  62. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
  63. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
  64. data/spec/koala_spec.rb +0 -18
  65. data/spec/koala_spec_helper.rb +0 -31
  66. 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
- before :each do
88
- @api = Koala::Facebook::RestAPI.new
89
- end
90
-
91
- describe "Koala RestAPI without an access token" do
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
- it_should_behave_like "live testing examples"
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
@@ -1,31 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'spec/test/unit'
4
-
5
- # load the libraries
6
- require 'koala'
7
-
8
- # load testing data libraries
9
- require 'koala/live_testing_data_helper'
10
-
11
- # API tests
12
- require 'koala/api_base_tests'
13
-
14
- require 'koala/graph_api/graph_collection_tests'
15
- require 'koala/graph_api/graph_api_no_access_token_tests'
16
- require 'koala/graph_api/graph_api_with_access_token_tests'
17
-
18
- require 'koala/rest_api/rest_api_no_access_token_tests'
19
- require 'koala/rest_api/rest_api_with_access_token_tests'
20
-
21
- require 'koala/graph_and_rest_api/graph_and_rest_api_no_token_tests'
22
- require 'koala/graph_and_rest_api/graph_and_rest_api_with_token_tests'
23
-
24
- # OAuth tests
25
- require 'koala/oauth/oauth_tests'
26
-
27
- # Subscriptions tests
28
- require 'koala/realtime_updates/realtime_updates_tests'
29
-
30
- # Services tests
31
- require 'koala/net_http_service_tests'
@@ -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 "Cookie tests will fail until you store valid data for the cookie hash, app_id, and app secret in facebook_data.yml"
19
- end