koala 0.9.1 → 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 (52) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +42 -7
  3. data/Gemfile +3 -0
  4. data/LICENSE +1 -1
  5. data/Manifest +10 -1
  6. data/Rakefile +13 -14
  7. data/koala.gemspec +36 -19
  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 +131 -43
  37. data/init.rb +0 -2
  38. data/spec/koala/api_base_tests.rb +0 -96
  39. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
  40. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
  41. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
  42. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
  43. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  44. data/spec/koala/live_testing_data_helper.rb +0 -23
  45. data/spec/koala/net_http_service_tests.rb +0 -186
  46. data/spec/koala/oauth/oauth_tests.rb +0 -433
  47. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  48. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
  49. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
  50. data/spec/koala_spec.rb +0 -18
  51. data/spec/koala_spec_helper.rb +0 -45
  52. data/spec/koala_spec_without_mocks.rb +0 -19
@@ -0,0 +1,161 @@
1
+ shared_examples_for "Koala RestAPI" 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
+ hash_including(:rest_api => true)
22
+ )
23
+
24
+ @api.rest_call('anything')
25
+ end
26
+
27
+ it "should set the read_only option to true if the method is listed in the read-only list" do
28
+ method = Koala::Facebook::RestAPI::READ_ONLY_METHODS.first
29
+
30
+ @api.should_receive(:api).with(
31
+ anything,
32
+ anything,
33
+ anything,
34
+ hash_including(:read_only => true)
35
+ )
36
+
37
+ @api.rest_call(method)
38
+ end
39
+
40
+ it "should set the read_only option to false if the method is not inthe read-only list" do
41
+ method = "I'm not a read-only method"
42
+
43
+ @api.should_receive(:api).with(
44
+ anything,
45
+ anything,
46
+ anything,
47
+ hash_including(:read_only => false)
48
+ )
49
+
50
+ @api.rest_call(method)
51
+ end
52
+
53
+
54
+ it "should take an optional hash of arguments" do
55
+ args = {:arg1 => 'arg1'}
56
+
57
+ @api.should_receive(:api).with(
58
+ anything,
59
+ hash_including(args),
60
+ anything,
61
+ anything
62
+ )
63
+
64
+ @api.rest_call('anything', args)
65
+ end
66
+
67
+ it "should always ask for JSON" do
68
+ @api.should_receive(:api).with(
69
+ anything,
70
+ hash_including('format' => 'json'),
71
+ anything,
72
+ anything
73
+ )
74
+
75
+ @api.rest_call('anything')
76
+ end
77
+
78
+ it "should pass any options provided to the API" do
79
+ options = {:a => 2}
80
+
81
+ @api.should_receive(:api).with(
82
+ anything,
83
+ hash_including('format' => 'json'),
84
+ anything,
85
+ hash_including(options)
86
+ )
87
+
88
+ @api.rest_call('anything', {}, options)
89
+ end
90
+
91
+ it "should throw an APIError if the result hash has an error key" do
92
+ Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error_code" => "An error occurred!"}, {}))
93
+ lambda { @api.rest_call("koppel", {}) }.should raise_exception(Koala::Facebook::APIError)
94
+ end
95
+
96
+ describe "when making a FQL request" do
97
+ it "should call fql.query method" do
98
+ @api.should_receive(:rest_call).with(
99
+ "fql.query",
100
+ anything
101
+ ).and_return(Koala::Response.new(200, "2", {}))
102
+
103
+ @api.fql_query stub('query string')
104
+ end
105
+
106
+ it "should pass a query argument" do
107
+ query = stub('query string')
108
+
109
+ @api.should_receive(:rest_call).with(
110
+ anything,
111
+ hash_including("query" => query)
112
+ )
113
+
114
+ @api.fql_query(query)
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+
121
+ shared_examples_for "Koala RestAPI with an access token" do
122
+ # FQL
123
+ it "should be able to access public information via FQL" do
124
+ result = @api.fql_query('select first_name from user where uid = 216743')
125
+ result.size.should == 1
126
+ result.first['first_name'].should == 'Chris'
127
+ end
128
+
129
+ it "should be able to access protected information via FQL" do
130
+ # Tests agains the permissions fql table
131
+
132
+ # get the current user's ID
133
+ # we're sneakily using the Graph API, which should be okay since it has its own tests
134
+ g = Koala::Facebook::GraphAPI.new(@token)
135
+ id = g.get_object("me", :fields => "id")["id"]
136
+
137
+ # now send a query about your permissions
138
+ result = @api.fql_query("select read_stream from permissions where uid = #{id}")
139
+
140
+ result.size.should == 1
141
+ # we assume that you have read_stream permissions, so we can test against that
142
+ # (should we keep this?)
143
+ result.first["read_stream"].should == 1
144
+ end
145
+ end
146
+
147
+
148
+ shared_examples_for "Koala RestAPI without an access token" do
149
+ # FQL_QUERY
150
+ describe "when making a FQL request" do
151
+ it "should be able to access public information via FQL" do
152
+ @result = @api.fql_query("select first_name from user where uid = 216743")
153
+ @result.size.should == 1
154
+ @result.first["first_name"].should == "Chris"
155
+ end
156
+
157
+ it "should not be able to access protected information via FQL" do
158
+ lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,52 @@
1
+ # small helper method for live testing
2
+ module KoalaTest
3
+ def self.validate_user_info(token)
4
+ print "Validating permissions for live testing..."
5
+ # make sure we have the necessary permissions
6
+ api = Koala::Facebook::GraphAndRestAPI.new(token)
7
+ uid = api.get_object("me")["id"]
8
+ perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
9
+ perms.each_pair do |perm, value|
10
+ unless value == 1
11
+ puts "failed!\n" # put a new line after the print above
12
+ raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
13
+ end
14
+ end
15
+ puts "done!"
16
+ end
17
+ end
18
+
19
+
20
+ unless ENV['LIVE']
21
+ # By default the Koala specs are run using stubs for HTTP requests
22
+ #
23
+ # Valid OAuth token and code are not necessary to run these
24
+ # specs. Because of this, specs do not fail due to Facebook
25
+ # imposed rate-limits or server timeouts.
26
+ #
27
+ # However as a result they are more brittle since
28
+ # we are not testing the latest responses from the Facebook servers.
29
+ # Therefore, to be certain all specs pass with the current
30
+ # Facebook services, run koala_spec_without_mocks.rb.
31
+ Koala.http_service = Koala::MockHTTPService
32
+
33
+ $testing_data = Koala::MockHTTPService::TEST_DATA
34
+ else
35
+ # Runs Koala specs through the Facebook servers
36
+ #
37
+ # Note that you need a valid OAuth token and code for these
38
+ # specs to run. See facebook_data.yml for more information.
39
+
40
+ # load testing data (see note in readme.md)
41
+ $testing_data = YAML.load_file(File.join(File.dirname(__FILE__), '../fixtures/facebook_data.yml'))
42
+
43
+ unless $testing_data["oauth_token"]
44
+ puts "Access token tests will fail until you store a valid token in facebook_data.yml"
45
+ end
46
+
47
+ unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
48
+ 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"
49
+ end
50
+
51
+ KoalaTest.validate_user_info $testing_data["oauth_token"]
52
+ end
@@ -0,0 +1,76 @@
1
+ shared_examples_for "MIME::Types can't return results" do
2
+ {
3
+ "jpg" => "image/jpeg",
4
+ "jpeg" => "image/jpeg",
5
+ "png" => "image/png",
6
+ "gif" => "image/gif"
7
+ }.each_pair do |extension, mime_type|
8
+ it "should properly get content types for #{extension} using basic analysis" do
9
+ path = "filename.#{extension}"
10
+ if @koala_io_params[0].is_a?(File)
11
+ @koala_io_params[0].stub!(:path).and_return(path)
12
+ else
13
+ @koala_io_params[0] = path
14
+ end
15
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
16
+ end
17
+
18
+ it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
19
+ path = "file.name.#{extension}"
20
+ if @koala_io_params[0].is_a?(File)
21
+ @koala_io_params[0].stub!(:path).and_return(path)
22
+ else
23
+ @koala_io_params[0] = path
24
+ end
25
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
26
+ end
27
+ end
28
+
29
+ describe "if the MIME type can't be determined" do
30
+ before :each do
31
+ path = "badfile.badextension"
32
+ if @koala_io_params[0].is_a?(File)
33
+ @koala_io_params[0].stub!(:path).and_return(path)
34
+ else
35
+ @koala_io_params[0] = path
36
+ end
37
+ end
38
+
39
+ it "should throw an exception if the MIME type can't be determined and the HTTP service requires content type" do
40
+ Koala.stub!(:multipart_requires_content_type?).and_return(true)
41
+ lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
42
+ end
43
+
44
+ it "should just have @content_type == nil if the HTTP service doesn't require content type" do
45
+ Koala.stub!(:multipart_requires_content_type?).and_return(false)
46
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should be_nil
47
+ end
48
+ end
49
+ end
50
+
51
+ shared_examples_for "determining a mime type" do
52
+ describe "if MIME::Types is available" do
53
+ it "should return an UploadIO with MIME::Types-determined type if the type exists" do
54
+ type_result = ["type"]
55
+ Koala::MIME::Types.stub(:type_for).and_return(type_result)
56
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == type_result.first
57
+ end
58
+ end
59
+
60
+ describe "if MIME::Types is unavailable" do
61
+ before :each do
62
+ # fake that MIME::Types doesn't exist
63
+ Koala::MIME::Types.stub(:type_for).and_raise(NameError)
64
+ end
65
+ it_should_behave_like "MIME::Types can't return results"
66
+ end
67
+
68
+ describe "if MIME::Types can't find the result" do
69
+ before :each do
70
+ # fake that MIME::Types doesn't exist
71
+ Koala::MIME::Types.stub(:type_for).and_return([])
72
+ end
73
+
74
+ it_should_behave_like "MIME::Types can't return results"
75
+ end
76
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
- - 0
7
- - 9
8
7
  - 1
9
- version: 0.9.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -14,67 +15,132 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-13 00:00:00 -05:00
18
- default_executable:
18
+ date: 2011-05-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: json
22
21
  prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
24
  requirements:
25
- - - ">="
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
+ hash: 15
27
28
  segments:
29
+ - 1
28
30
  - 0
29
- version: "0"
31
+ version: "1.0"
30
32
  type: :runtime
33
+ name: json
31
34
  version_requirements: *id001
32
- description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, 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.
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 15
43
+ segments:
44
+ - 1
45
+ - 0
46
+ version: "1.0"
47
+ type: :runtime
48
+ name: multipart-post
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 27
58
+ segments:
59
+ - 2
60
+ - 5
61
+ - 0
62
+ version: 2.5.0
63
+ type: :development
64
+ name: rspec
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 49
74
+ segments:
75
+ - 0
76
+ - 8
77
+ - 7
78
+ version: 0.8.7
79
+ type: :development
80
+ name: rake
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 31
90
+ segments:
91
+ - 0
92
+ - 2
93
+ - 4
94
+ version: 0.2.4
95
+ type: :development
96
+ name: typhoeus
97
+ version_requirements: *id005
98
+ description: 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.
33
99
  email: alex@alexkoppel.com
34
100
  executables: []
35
101
 
36
102
  extensions: []
37
103
 
38
104
  extra_rdoc_files:
105
+ - readme.md
39
106
  - CHANGELOG
40
- - LICENSE
41
- - lib/koala.rb
42
- - lib/koala/graph_api.rb
43
- - lib/koala/http_services.rb
44
- - lib/koala/realtime_updates.rb
45
- - lib/koala/rest_api.rb
46
107
  files:
108
+ - .gitignore
47
109
  - CHANGELOG
110
+ - Gemfile
48
111
  - LICENSE
49
112
  - Manifest
50
113
  - Rakefile
51
- - init.rb
52
114
  - koala.gemspec
53
115
  - lib/koala.rb
54
116
  - lib/koala/graph_api.rb
55
117
  - lib/koala/http_services.rb
56
118
  - lib/koala/realtime_updates.rb
57
119
  - lib/koala/rest_api.rb
120
+ - lib/koala/test_users.rb
121
+ - lib/koala/uploadable_io.rb
58
122
  - readme.md
59
- - spec/facebook_data.yml
60
- - spec/koala/api_base_tests.rb
61
- - spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb
62
- - spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb
63
- - spec/koala/graph_api/graph_api_no_access_token_tests.rb
64
- - spec/koala/graph_api/graph_api_with_access_token_tests.rb
65
- - spec/koala/graph_api/graph_collection_tests.rb
66
- - spec/koala/live_testing_data_helper.rb
67
- - spec/koala/net_http_service_tests.rb
68
- - spec/koala/oauth/oauth_tests.rb
69
- - spec/koala/realtime_updates/realtime_updates_tests.rb
70
- - spec/koala/rest_api/rest_api_no_access_token_tests.rb
71
- - spec/koala/rest_api/rest_api_with_access_token_tests.rb
72
- - spec/koala_spec.rb
73
- - spec/koala_spec_helper.rb
74
- - spec/koala_spec_without_mocks.rb
75
- - spec/mock_facebook_responses.yml
76
- - spec/mock_http_service.rb
77
- has_rdoc: true
123
+ - spec/cases/api_base_spec.rb
124
+ - spec/cases/graph_and_rest_api_spec.rb
125
+ - spec/cases/graph_api_spec.rb
126
+ - spec/cases/http_services/http_service_spec.rb
127
+ - spec/cases/http_services/net_http_service_spec.rb
128
+ - spec/cases/http_services/typhoeus_service_spec.rb
129
+ - spec/cases/oauth_spec.rb
130
+ - spec/cases/realtime_updates_spec.rb
131
+ - spec/cases/rest_api_spec.rb
132
+ - spec/cases/test_users_spec.rb
133
+ - spec/cases/uploadable_io_spec.rb
134
+ - spec/fixtures/beach.jpg
135
+ - spec/fixtures/facebook_data.yml
136
+ - spec/fixtures/mock_facebook_responses.yml
137
+ - spec/spec_helper.rb
138
+ - spec/support/graph_api_shared_examples.rb
139
+ - spec/support/live_testing_data_helper.rb
140
+ - spec/support/mock_http_service.rb
141
+ - spec/support/rest_api_shared_examples.rb
142
+ - spec/support/setup_mocks_or_live.rb
143
+ - spec/support/uploadable_io_shared_examples.rb
78
144
  homepage: http://github.com/arsduo/koala
79
145
  licenses: []
80
146
 
@@ -84,31 +150,53 @@ rdoc_options:
84
150
  - --inline-source
85
151
  - --title
86
152
  - Koala
87
- - --main
88
- - readme.md
89
153
  require_paths:
90
154
  - lib
91
155
  required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
92
157
  requirements:
93
158
  - - ">="
94
159
  - !ruby/object:Gem::Version
160
+ hash: 3
95
161
  segments:
96
162
  - 0
97
163
  version: "0"
98
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
99
166
  requirements:
100
167
  - - ">="
101
168
  - !ruby/object:Gem::Version
169
+ hash: 11
102
170
  segments:
103
171
  - 1
104
172
  - 2
105
173
  version: "1.2"
106
174
  requirements: []
107
175
 
108
- rubyforge_project: koala
109
- rubygems_version: 1.3.6
176
+ rubyforge_project:
177
+ rubygems_version: 1.7.2
110
178
  signing_key:
111
179
  specification_version: 3
112
- summary: A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation.
113
- test_files: []
114
-
180
+ summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
181
+ test_files:
182
+ - spec/cases/api_base_spec.rb
183
+ - spec/cases/graph_and_rest_api_spec.rb
184
+ - spec/cases/graph_api_spec.rb
185
+ - spec/cases/http_services/http_service_spec.rb
186
+ - spec/cases/http_services/net_http_service_spec.rb
187
+ - spec/cases/http_services/typhoeus_service_spec.rb
188
+ - spec/cases/oauth_spec.rb
189
+ - spec/cases/realtime_updates_spec.rb
190
+ - spec/cases/rest_api_spec.rb
191
+ - spec/cases/test_users_spec.rb
192
+ - spec/cases/uploadable_io_spec.rb
193
+ - spec/fixtures/beach.jpg
194
+ - spec/fixtures/facebook_data.yml
195
+ - spec/fixtures/mock_facebook_responses.yml
196
+ - spec/spec_helper.rb
197
+ - spec/support/graph_api_shared_examples.rb
198
+ - spec/support/live_testing_data_helper.rb
199
+ - spec/support/mock_http_service.rb
200
+ - spec/support/rest_api_shared_examples.rb
201
+ - spec/support/setup_mocks_or_live.rb
202
+ - spec/support/uploadable_io_shared_examples.rb
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # init.rb
2
- require 'koala'
@@ -1,96 +0,0 @@
1
- class ApiBaseTests < Test::Unit::TestCase
2
-
3
- describe "Koala API base class" do
4
- before(:each) do
5
- @service = Koala::Facebook::API.new
6
- end
7
-
8
- it "should not include an access token if none was given" do
9
- Koala.should_receive(:make_request).with(
10
- anything,
11
- hash_not_including('access_token' => 1),
12
- anything,
13
- anything
14
- ).and_return(Koala::Response.new(200, "", ""))
15
-
16
- @service.api('anything')
17
- end
18
-
19
- it "should include an access token if given" do
20
- token = 'adfadf'
21
- service = Koala::Facebook::API.new token
22
-
23
- Koala.should_receive(:make_request).with(
24
- anything,
25
- hash_including('access_token' => token),
26
- anything,
27
- anything
28
- ).and_return(Koala::Response.new(200, "", ""))
29
-
30
- service.api('anything')
31
- end
32
-
33
- it "should get the attribute of a Koala::Response given by the http_component parameter" do
34
- http_component = :method_name
35
-
36
- response = mock('Mock KoalaResponse', :body => '', :status => 200)
37
- response.should_receive(http_component).and_return('')
38
-
39
- Koala.stub(:make_request).and_return(response)
40
-
41
- @service.api('anything', 'get', {}, :http_component => http_component)
42
- end
43
-
44
- it "should return the body of the request as JSON if no http_component is given" do
45
- response = stub('response', :body => 'body', :status => 200)
46
- Koala.stub(:make_request).and_return(response)
47
-
48
- json_body = mock('JSON body')
49
- JSON.stub(:parse).and_return([json_body])
50
-
51
- @service.api('anything').should == json_body
52
- end
53
-
54
- it "should execute a block with the response body if passed one" do
55
- body = '{}'
56
- Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
57
-
58
- yield_test = mock('Yield Tester')
59
- yield_test.should_receive(:pass)
60
-
61
- @service.api('anything') do |arg|
62
- yield_test.pass
63
- arg.should == JSON.parse(body)
64
- end
65
- end
66
-
67
- it "should raise an API error if the HTTP response code is greater than or equal to 500" do
68
- Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
69
-
70
- lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
71
- end
72
-
73
- it "should handle rogue true/false as responses" do
74
- Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
75
- @service.api('anything').should be_true
76
-
77
- Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
78
- @service.api('anything').should be_false
79
- end
80
-
81
- describe "with regard to leading slashes" do
82
- it "should add a leading / to the path if not present" do
83
- path = "anything"
84
- Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
85
- @service.api(path)
86
- end
87
-
88
- it "shouldn't change the path if a leading / is present" do
89
- path = "/anything"
90
- Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
91
- @service.api(path)
92
- end
93
- end
94
-
95
- end
96
- end
@@ -1,10 +0,0 @@
1
- class GraphAndRestAPINoTokenTests < Test::Unit::TestCase
2
- describe "Koala GraphAndRestAPI without an access token" do
3
- before(:each) do
4
- @api = Koala::Facebook::GraphAndRestAPI.new
5
- end
6
-
7
- it_should_behave_like "Koala RestAPI without an access token"
8
- it_should_behave_like "Koala GraphAPI without an access token"
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
2
- describe "Koala GraphAndRestAPI without an access token" do
3
- include LiveTestingDataHelper
4
- it_should_behave_like "Koala RestAPI with an access token"
5
- it_should_behave_like "Koala GraphAPI with an access token"
6
-
7
- before(:each) do
8
- @api = Koala::Facebook::GraphAndRestAPI.new(@token)
9
- end
10
- end
11
- end