koala 0.9.1 → 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.
Files changed (51) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +44 -7
  3. data/Gemfile +3 -0
  4. data/Manifest +10 -1
  5. data/Rakefile +13 -14
  6. data/koala.gemspec +36 -19
  7. data/lib/koala/graph_api.rb +188 -123
  8. data/lib/koala/http_services.rb +93 -18
  9. data/lib/koala/rest_api.rb +73 -6
  10. data/lib/koala/test_users.rb +85 -0
  11. data/lib/koala/uploadable_io.rb +115 -0
  12. data/lib/koala.rb +96 -82
  13. data/readme.md +21 -14
  14. data/spec/cases/api_base_spec.rb +101 -0
  15. data/spec/cases/graph_and_rest_api_spec.rb +31 -0
  16. data/spec/cases/graph_api_spec.rb +25 -0
  17. data/spec/cases/http_services/http_service_spec.rb +54 -0
  18. data/spec/cases/http_services/net_http_service_spec.rb +350 -0
  19. data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
  20. data/spec/cases/oauth_spec.rb +374 -0
  21. data/spec/cases/realtime_updates_spec.rb +184 -0
  22. data/spec/cases/rest_api_spec.rb +25 -0
  23. data/spec/cases/test_users_spec.rb +221 -0
  24. data/spec/cases/uploadable_io_spec.rb +151 -0
  25. data/spec/fixtures/beach.jpg +0 -0
  26. data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +18 -14
  27. data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +312 -241
  28. data/spec/spec_helper.rb +18 -0
  29. data/spec/support/graph_api_shared_examples.rb +424 -0
  30. data/spec/support/live_testing_data_helper.rb +40 -0
  31. data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -80
  32. data/spec/support/rest_api_shared_examples.rb +161 -0
  33. data/spec/support/setup_mocks_or_live.rb +52 -0
  34. data/spec/support/uploadable_io_shared_examples.rb +76 -0
  35. metadata +134 -43
  36. data/init.rb +0 -2
  37. data/spec/koala/api_base_tests.rb +0 -96
  38. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
  39. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
  40. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
  41. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
  42. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  43. data/spec/koala/live_testing_data_helper.rb +0 -23
  44. data/spec/koala/net_http_service_tests.rb +0 -186
  45. data/spec/koala/oauth/oauth_tests.rb +0 -433
  46. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  47. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
  48. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
  49. data/spec/koala_spec.rb +0 -18
  50. data/spec/koala_spec_helper.rb +0 -45
  51. 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,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 7712010
5
+ prerelease: 6
5
6
  segments:
6
- - 0
7
- - 9
8
7
  - 1
9
- version: 0.9.1
8
+ - 0
9
+ - 0
10
+ - rc
11
+ version: 1.0.0.rc
10
12
  platform: ruby
11
13
  authors:
12
14
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -14,66 +16,133 @@ autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-10-13 00:00:00 -05:00
19
+ date: 2011-04-18 00:00:00 +02:00
18
20
  default_executable:
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
- name: json
22
- prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
- - - ">="
26
+ - - ~>
26
27
  - !ruby/object:Gem::Version
28
+ hash: 15
27
29
  segments:
30
+ - 1
28
31
  - 0
29
- version: "0"
30
- type: :runtime
32
+ version: "1.0"
33
+ prerelease: false
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
+ type: :runtime
36
+ name: json
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 1
46
+ - 0
47
+ version: "1.0"
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ type: :runtime
51
+ name: multipart-post
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 27
59
+ segments:
60
+ - 2
61
+ - 5
62
+ - 0
63
+ version: 2.5.0
64
+ prerelease: false
65
+ version_requirements: *id003
66
+ type: :development
67
+ name: rspec
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 49
75
+ segments:
76
+ - 0
77
+ - 8
78
+ - 7
79
+ version: 0.8.7
80
+ prerelease: false
81
+ version_requirements: *id004
82
+ type: :development
83
+ name: rake
84
+ - !ruby/object:Gem::Dependency
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 31
91
+ segments:
92
+ - 0
93
+ - 2
94
+ - 4
95
+ version: 0.2.4
96
+ prerelease: false
97
+ version_requirements: *id005
98
+ type: :development
99
+ name: typhoeus
100
+ 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
101
  email: alex@alexkoppel.com
34
102
  executables: []
35
103
 
36
104
  extensions: []
37
105
 
38
106
  extra_rdoc_files:
107
+ - readme.md
39
108
  - 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
109
  files:
110
+ - .gitignore
47
111
  - CHANGELOG
112
+ - Gemfile
48
113
  - LICENSE
49
114
  - Manifest
50
115
  - Rakefile
51
- - init.rb
52
116
  - koala.gemspec
53
117
  - lib/koala.rb
54
118
  - lib/koala/graph_api.rb
55
119
  - lib/koala/http_services.rb
56
120
  - lib/koala/realtime_updates.rb
57
121
  - lib/koala/rest_api.rb
122
+ - lib/koala/test_users.rb
123
+ - lib/koala/uploadable_io.rb
58
124
  - 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
125
+ - spec/cases/api_base_spec.rb
126
+ - spec/cases/graph_and_rest_api_spec.rb
127
+ - spec/cases/graph_api_spec.rb
128
+ - spec/cases/http_services/http_service_spec.rb
129
+ - spec/cases/http_services/net_http_service_spec.rb
130
+ - spec/cases/http_services/typhoeus_service_spec.rb
131
+ - spec/cases/oauth_spec.rb
132
+ - spec/cases/realtime_updates_spec.rb
133
+ - spec/cases/rest_api_spec.rb
134
+ - spec/cases/test_users_spec.rb
135
+ - spec/cases/uploadable_io_spec.rb
136
+ - spec/fixtures/beach.jpg
137
+ - spec/fixtures/facebook_data.yml
138
+ - spec/fixtures/mock_facebook_responses.yml
139
+ - spec/spec_helper.rb
140
+ - spec/support/graph_api_shared_examples.rb
141
+ - spec/support/live_testing_data_helper.rb
142
+ - spec/support/mock_http_service.rb
143
+ - spec/support/rest_api_shared_examples.rb
144
+ - spec/support/setup_mocks_or_live.rb
145
+ - spec/support/uploadable_io_shared_examples.rb
77
146
  has_rdoc: true
78
147
  homepage: http://github.com/arsduo/koala
79
148
  licenses: []
@@ -84,31 +153,53 @@ rdoc_options:
84
153
  - --inline-source
85
154
  - --title
86
155
  - Koala
87
- - --main
88
- - readme.md
89
156
  require_paths:
90
157
  - lib
91
158
  required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
92
160
  requirements:
93
161
  - - ">="
94
162
  - !ruby/object:Gem::Version
163
+ hash: 3
95
164
  segments:
96
165
  - 0
97
166
  version: "0"
98
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
99
169
  requirements:
100
170
  - - ">="
101
171
  - !ruby/object:Gem::Version
172
+ hash: 11
102
173
  segments:
103
174
  - 1
104
175
  - 2
105
176
  version: "1.2"
106
177
  requirements: []
107
178
 
108
- rubyforge_project: koala
109
- rubygems_version: 1.3.6
179
+ rubyforge_project:
180
+ rubygems_version: 1.4.2
110
181
  signing_key:
111
182
  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
-
183
+ summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
184
+ test_files:
185
+ - spec/cases/api_base_spec.rb
186
+ - spec/cases/graph_and_rest_api_spec.rb
187
+ - spec/cases/graph_api_spec.rb
188
+ - spec/cases/http_services/http_service_spec.rb
189
+ - spec/cases/http_services/net_http_service_spec.rb
190
+ - spec/cases/http_services/typhoeus_service_spec.rb
191
+ - spec/cases/oauth_spec.rb
192
+ - spec/cases/realtime_updates_spec.rb
193
+ - spec/cases/rest_api_spec.rb
194
+ - spec/cases/test_users_spec.rb
195
+ - spec/cases/uploadable_io_spec.rb
196
+ - spec/fixtures/beach.jpg
197
+ - spec/fixtures/facebook_data.yml
198
+ - spec/fixtures/mock_facebook_responses.yml
199
+ - spec/spec_helper.rb
200
+ - spec/support/graph_api_shared_examples.rb
201
+ - spec/support/live_testing_data_helper.rb
202
+ - spec/support/mock_http_service.rb
203
+ - spec/support/rest_api_shared_examples.rb
204
+ - spec/support/setup_mocks_or_live.rb
205
+ - 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