koala 1.1.0 → 1.2.0beta1

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 (50) hide show
  1. data/.travis.yml +2 -1
  2. data/CHANGELOG +26 -0
  3. data/Gemfile +6 -2
  4. data/Rakefile +0 -1
  5. data/koala.gemspec +8 -8
  6. data/lib/koala.rb +42 -45
  7. data/lib/koala/batch_operation.rb +15 -15
  8. data/lib/koala/graph_api.rb +81 -58
  9. data/lib/koala/graph_batch_api.rb +10 -10
  10. data/lib/koala/graph_collection.rb +6 -6
  11. data/lib/koala/http_service.rb +177 -0
  12. data/lib/koala/oauth.rb +2 -2
  13. data/lib/koala/realtime_updates.rb +20 -17
  14. data/lib/koala/rest_api.rb +1 -1
  15. data/lib/koala/test_users.rb +33 -16
  16. data/lib/koala/uploadable_io.rb +47 -42
  17. data/lib/koala/utils.rb +11 -0
  18. data/readme.md +38 -38
  19. data/spec/cases/api_base_spec.rb +2 -2
  20. data/spec/cases/error_spec.rb +32 -0
  21. data/spec/cases/graph_and_rest_api_spec.rb +20 -3
  22. data/spec/cases/graph_api_batch_spec.rb +88 -97
  23. data/spec/cases/graph_api_spec.rb +21 -4
  24. data/spec/cases/http_service_spec.rb +446 -0
  25. data/spec/cases/koala_spec.rb +33 -38
  26. data/spec/cases/oauth_spec.rb +219 -200
  27. data/spec/cases/realtime_updates_spec.rb +45 -31
  28. data/spec/cases/rest_api_spec.rb +23 -7
  29. data/spec/cases/test_users_spec.rb +112 -52
  30. data/spec/cases/uploadable_io_spec.rb +49 -36
  31. data/spec/cases/utils_spec.rb +10 -0
  32. data/spec/fixtures/facebook_data.yml +23 -22
  33. data/spec/fixtures/mock_facebook_responses.yml +126 -96
  34. data/spec/spec_helper.rb +29 -5
  35. data/spec/support/graph_api_shared_examples.rb +59 -52
  36. data/spec/support/json_testing_fix.rb +35 -11
  37. data/spec/support/koala_test.rb +163 -0
  38. data/spec/support/mock_http_service.rb +6 -4
  39. data/spec/support/ordered_hash.rb +205 -0
  40. data/spec/support/rest_api_shared_examples.rb +37 -37
  41. data/spec/support/uploadable_io_shared_examples.rb +2 -8
  42. metadata +78 -79
  43. data/lib/koala/http_services.rb +0 -46
  44. data/lib/koala/http_services/net_http_service.rb +0 -92
  45. data/lib/koala/http_services/typhoeus_service.rb +0 -37
  46. data/spec/cases/http_services/http_service_spec.rb +0 -129
  47. data/spec/cases/http_services/net_http_service_spec.rb +0 -532
  48. data/spec/cases/http_services/typhoeus_service_spec.rb +0 -152
  49. data/spec/support/live_testing_data_helper.rb +0 -40
  50. data/spec/support/setup_mocks_or_live.rb +0 -51
@@ -1,152 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- Deer = Koala::TyphoeusService
5
-
6
- describe "TyphoeusService" do
7
-
8
- describe "TyphoeusService module holder class Deer" do
9
- before :each do
10
- # reset global settings
11
- Deer.always_use_ssl = Deer.proxy = Deer.timeout = nil
12
- end
13
-
14
- it "should define a make_request static module method" do
15
- Deer.respond_to?(:make_request).should be_true
16
- end
17
-
18
- it "should include the Koala::HTTPService module defining common features" do
19
- Deer.included_modules.include?(Koala::HTTPService).should be_true
20
- end
21
-
22
- describe "when making a request" do
23
- before(:each) do
24
- # Setup stubs for make_request to execute without exceptions
25
- @mock_body = stub('Typhoeus response body')
26
- @mock_headers_hash = stub({:value => "headers hash"})
27
- @mock_http_response = stub(Typhoeus::Response, :code => 1, :headers_hash => @mock_headers_hash, :body => @mock_body)
28
-
29
- # Typhoeus is an included module, so we stub methods on Deer itself
30
- Typhoeus::Request.stub(:post).and_return(@mock_http_response)
31
- Typhoeus::Request.stub(:get).and_return(@mock_http_response)
32
- end
33
-
34
- it "should use POST if verb is not GET" do
35
- Typhoeus::Request.should_receive(:post).and_return(@mock_http_response)
36
- Deer.make_request('anything', {}, 'anything')
37
- end
38
-
39
- it "should use GET if that verb is specified" do
40
- Typhoeus::Request.should_receive(:get).and_return(@mock_http_response)
41
- Deer.make_request('anything', {}, 'get')
42
- end
43
-
44
- describe "the connection" do
45
- it "should use SSL if the request has an access token" do
46
- Typhoeus::Request.should_receive(:post).with(/https\:/, anything)
47
-
48
- Deer.make_request('anything', {"access_token" => "123"}, 'anything')
49
- end
50
-
51
- it "should use SSL if always_use_ssl is true, even if there's no token" do
52
- Typhoeus::Request.should_receive(:post).with(/https\:/, anything)
53
-
54
- Deer.always_use_ssl = true
55
- Deer.make_request('anything', {}, 'anything')
56
- end
57
-
58
- it "should use SSL if the :use_ssl option is provided, even if there's no token" do
59
- Typhoeus::Request.should_receive(:post).with(/https\:/, anything)
60
-
61
- Deer.always_use_ssl = true
62
- Deer.make_request('anything', {}, 'anything', :use_ssl => true)
63
- end
64
-
65
- it "should not use SSL if always_use_ssl is false and there's no token" do
66
- Typhoeus::Request.should_receive(:post).with(/http\:/, anything)
67
-
68
- Deer.make_request('anything', {}, 'anything')
69
- end
70
-
71
- it "should use the graph server by default" do
72
- Typhoeus::Request.should_receive(:post).with(Regexp.new(Koala::Facebook::GRAPH_SERVER), anything)
73
-
74
- Deer.make_request('anything', {}, 'anything')
75
- end
76
-
77
- it "should use the REST server if the :rest_api option is true" do
78
- Typhoeus::Request.should_receive(:post).with(Regexp.new(Koala::Facebook::REST_SERVER), anything)
79
-
80
- Deer.make_request('anything', {}, 'anything', :rest_api => true)
81
- end
82
- end
83
-
84
- it "should pass the arguments to Typhoeus under the :params key" do
85
- args = {:a => 2}
86
- Typhoeus::Request.should_receive(:post).with(anything, hash_including(:params => args))
87
-
88
- Deer.make_request('anything', args, "post")
89
- end
90
-
91
- it "should add the method to the arguments if the method isn't get or post" do
92
- method = "telekenesis"
93
- Typhoeus::Request.should_receive(:post).with(anything, hash_including(:params => {:method => method}))
94
-
95
- Deer.make_request('anything', {}, method)
96
- end
97
-
98
- it "should pass :typhoeus_options to Typhoeus if provided" do
99
- t_options = {:a => :b}
100
- Typhoeus::Request.should_receive(:post).with(anything, hash_including(t_options))
101
-
102
- Deer.make_request("anything", {}, "post", :typhoeus_options => t_options)
103
- end
104
-
105
- it "should pass proxy and timeout :typhoeus_options to Typhoeus if set globally" do
106
- Deer.proxy = "http://defaultproxy"
107
- Deer.timeout = 20
108
-
109
- t_options = {:proxy => "http://defaultproxy", :timeout => 20}
110
- Typhoeus::Request.should_receive(:post).with(anything, hash_including(t_options))
111
-
112
- Deer.make_request("anything", {}, "post")
113
- end
114
-
115
- # for live tests, run the Graph API tests with Typhoues, which will run file uploads
116
- it "should pass any files directly on to Typhoues" do
117
- args = {:file => File.new(__FILE__, "r")}
118
- Typhoeus::Request.should_receive(:post).with(anything, hash_including(:params => args)).and_return(Typhoeus::Response.new)
119
- Deer.make_request("anything", args, :post)
120
- end
121
-
122
- it "should include the path in the request" do
123
- path = "/a/b/c/1"
124
- Typhoeus::Request.should_receive(:post).with(Regexp.new(path), anything)
125
-
126
- Deer.make_request(path, {}, "post")
127
- end
128
-
129
- describe "the returned value" do
130
- before(:each) do
131
- @response = Deer.make_request('anything', {}, 'anything')
132
- end
133
-
134
- it "should return a Koala::Response object" do
135
- @response.class.should == Koala::Response
136
- end
137
-
138
- it "should return a Koala::Response with the right status" do
139
- @response.status.should == @mock_http_response.code
140
- end
141
-
142
- it "should reutrn a Koala::Response with the right body" do
143
- @response.body.should == @mock_body
144
- end
145
-
146
- it "should return a Koala::Response with the Typhoeus headers as headers" do
147
- @response.headers.should == @mock_headers_hash
148
- end
149
- end # describe return value
150
- end
151
- end
152
- end
@@ -1,40 +0,0 @@
1
- module LiveTestingDataHelper
2
- # in RSpec 2, included example groups no longer share any hooks or state with outside examples
3
- # even if in the same block
4
- # so we have to use a module to provide setup and teardown hooks for live testing
5
-
6
- def self.included(base)
7
- base.class_eval do
8
- before :each do
9
- @token = $testing_data["oauth_token"]
10
- raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
11
- # track temporary objects created
12
- @temporary_object_ids = []
13
- end
14
-
15
- after :each do
16
- # clean up any temporary objects
17
- @temporary_object_ids << @temporary_object_id if @temporary_object_id
18
- count = @temporary_object_ids.length
19
- errors = []
20
-
21
- if count > 0
22
- @temporary_object_ids.each do |id|
23
- # get our API
24
- api = @api || (@test_users ? @test_users.graph_api : nil)
25
- raise "Unable to locate API when passed temporary object to delete!" unless api
26
-
27
- # delete the object
28
- result = (api.delete_object(id) rescue false)
29
- # if we errored out or Facebook returned false, track that
30
- errors << id unless result
31
- end
32
-
33
- unless errors.length == 0
34
- puts "cleaned up #{count - errors.length} objects, but errored out on the following:\n #{errors.join(", ")}"
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,51 +0,0 @@
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
- perms = api.fql_query("select read_stream, publish_stream, user_photos, user_videos, read_insights from permissions where uid = me()")[0]
8
- perms.each_pair do |perm, value|
9
- if value == (perm == "read_insights" ? 1 : 0) # live testing depends on insights calls failing
10
- puts "failed!\n" # put a new line after the print above
11
- raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions, and lack read_insights. You have: #{perms.inspect}"
12
- end
13
- end
14
- puts "done!"
15
- end
16
- end
17
-
18
-
19
- unless ENV['LIVE']
20
- # By default the Koala specs are run using stubs for HTTP requests
21
- #
22
- # Valid OAuth token and code are not necessary to run these
23
- # specs. Because of this, specs do not fail due to Facebook
24
- # imposed rate-limits or server timeouts.
25
- #
26
- # However as a result they are more brittle since
27
- # we are not testing the latest responses from the Facebook servers.
28
- # Therefore, to be certain all specs pass with the current
29
- # Facebook services, run koala_spec_without_mocks.rb.
30
- Koala.http_service = Koala::MockHTTPService
31
-
32
- $testing_data = Koala::MockHTTPService::TEST_DATA
33
- else
34
- # Runs Koala specs through the Facebook servers
35
- #
36
- # Note that you need a valid OAuth token and code for these
37
- # specs to run. See facebook_data.yml for more information.
38
-
39
- # load testing data (see note in readme.md)
40
- $testing_data = YAML.load_file(File.join(File.dirname(__FILE__), '../fixtures/facebook_data.yml'))
41
-
42
- unless $testing_data["oauth_token"]
43
- puts "Access token tests will fail until you store a valid token in facebook_data.yml"
44
- end
45
-
46
- unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
47
- 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"
48
- end
49
-
50
- KoalaTest.validate_user_info $testing_data["oauth_token"]
51
- end