koala 2.5.0 → 3.0.0.beta1

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -2
  3. data/Gemfile +1 -1
  4. data/changelog.md +26 -0
  5. data/lib/koala/api/batch_operation.rb +3 -6
  6. data/lib/koala/api/graph_api.rb +6 -45
  7. data/lib/koala/api/graph_batch_api.rb +1 -2
  8. data/lib/koala/api/graph_collection.rb +1 -5
  9. data/lib/koala/api/graph_error_checker.rb +1 -1
  10. data/lib/koala/api.rb +3 -7
  11. data/lib/koala/errors.rb +1 -1
  12. data/lib/koala/http_service/multipart_request.rb +6 -10
  13. data/lib/koala/http_service/request.rb +139 -0
  14. data/lib/koala/http_service/response.rb +0 -4
  15. data/lib/koala/http_service/uploadable_io.rb +0 -4
  16. data/lib/koala/http_service.rb +16 -68
  17. data/lib/koala/oauth.rb +3 -3
  18. data/lib/koala/version.rb +1 -1
  19. data/lib/koala.rb +2 -1
  20. data/readme.md +5 -26
  21. data/spec/cases/api_spec.rb +1 -7
  22. data/spec/cases/graph_api_batch_spec.rb +12 -22
  23. data/spec/cases/graph_api_spec.rb +0 -19
  24. data/spec/cases/graph_collection_spec.rb +18 -18
  25. data/spec/cases/graph_error_checker_spec.rb +6 -1
  26. data/spec/cases/http_service/request_spec.rb +240 -0
  27. data/spec/cases/http_service_spec.rb +102 -296
  28. data/spec/cases/koala_spec.rb +6 -1
  29. data/spec/cases/oauth_spec.rb +1 -1
  30. data/spec/cases/test_users_spec.rb +4 -1
  31. data/spec/cases/uploadable_io_spec.rb +31 -31
  32. data/spec/fixtures/mock_facebook_responses.yml +0 -37
  33. data/spec/spec_helper.rb +2 -2
  34. data/spec/support/graph_api_shared_examples.rb +6 -142
  35. data/spec/support/koala_test.rb +6 -6
  36. data/spec/support/mock_http_service.rb +6 -6
  37. data/spec/support/uploadable_io_shared_examples.rb +4 -4
  38. metadata +7 -7
  39. data/lib/koala/api/rest_api.rb +0 -135
  40. data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -1,135 +0,0 @@
1
- module Koala
2
- module Facebook
3
- # Methods used to interact with Facebook's legacy REST API.
4
- # Where possible, you should use the newer, faster Graph API to interact with Facebook;
5
- # in the future, the REST API will be deprecated.
6
- # For now, though, there are a few methods that can't be done through the Graph API.
7
- #
8
- # When using the REST API, Koala will use Facebook's faster read-only servers
9
- # whenever the call allows.
10
- #
11
- # See https://github.com/arsduo/koala/wiki/REST-API for a general introduction to Koala
12
- # and the Rest API.
13
- module RestAPIMethods
14
- # Set a Facebook application's properties.
15
- #
16
- # @param properties a hash of properties you want to update with their new values.
17
- # @param (see #rest_call)
18
- # @param options (see #rest_call)
19
- #
20
- # @return true if successful, false if not. (This call currently doesn't give useful feedback on failure.)
21
- def set_app_properties(properties, args = {}, options = {})
22
- raise AuthenticationError.new(nil, nil, "setAppProperties requires an access token") unless @access_token
23
- rest_call("admin.setAppProperties", args.merge(:properties => JSON.dump(properties)), options, "post")
24
- end
25
-
26
- # Make a call to the REST API.
27
- #
28
- # @note The order of the last two arguments is non-standard (for historical reasons). Sorry.
29
- #
30
- # @param fb_method the API call you want to make
31
- # @param args (see Koala::Facebook::GraphAPIMethods#graph_call)
32
- # @param options (see Koala::Facebook::GraphAPIMethods#graph_call)
33
- # @param verb (see Koala::Facebook::GraphAPIMethods#graph_call)
34
- #
35
- # @raise [Koala::Facebook::APIError] if Facebook returns an error
36
- #
37
- # @return the result from Facebook
38
- def rest_call(fb_method, args = {}, options = {}, verb = "get")
39
- Koala::Utils.deprecate("The REST API is now deprecated; please use the equivalent Graph API methods instead. See http://developers.facebook.com/blog/post/616/.")
40
-
41
- options = options.merge!(:rest_api => true, :read_only => READ_ONLY_METHODS.include?(fb_method.to_s))
42
-
43
- api("method/#{fb_method}", args.merge('format' => 'json'), verb, options) do |response|
44
- # check for REST API-specific errors
45
- if response.status >= 400
46
- begin
47
- response_hash = JSON.load(response.body)
48
- rescue JSON::ParserError
49
- response_hash = {}
50
- end
51
-
52
- error_info = {
53
- 'code' => response_hash['error_code'],
54
- 'error_subcode' => response_hash['error_subcode'],
55
- 'message' => response_hash['error_msg']
56
- }
57
-
58
- if response.status >= 500
59
- raise ServerError.new(response.status, response.body, error_info)
60
- else
61
- raise ClientError.new(response.status, response.body, error_info)
62
- end
63
- end
64
- end
65
- end
66
-
67
- # @private
68
- # read-only methods for which we can use API-read
69
- # taken directly from the FB PHP library (https://github.com/facebook/php-sdk/blob/master/src/facebook.php)
70
- READ_ONLY_METHODS = [
71
- 'admin.getallocation',
72
- 'admin.getappproperties',
73
- 'admin.getbannedusers',
74
- 'admin.getlivestreamvialink',
75
- 'admin.getmetrics',
76
- 'admin.getrestrictioninfo',
77
- 'application.getpublicinfo',
78
- 'auth.getapppublickey',
79
- 'auth.getsession',
80
- 'auth.getsignedpublicsessiondata',
81
- 'comments.get',
82
- 'connect.getunconnectedfriendscount',
83
- 'dashboard.getactivity',
84
- 'dashboard.getcount',
85
- 'dashboard.getglobalnews',
86
- 'dashboard.getnews',
87
- 'dashboard.multigetcount',
88
- 'dashboard.multigetnews',
89
- 'data.getcookies',
90
- 'events.get',
91
- 'events.getmembers',
92
- 'fbml.getcustomtags',
93
- 'feed.getappfriendstories',
94
- 'feed.getregisteredtemplatebundlebyid',
95
- 'feed.getregisteredtemplatebundles',
96
- 'fql.multiquery',
97
- 'fql.query',
98
- 'friends.arefriends',
99
- 'friends.get',
100
- 'friends.getappusers',
101
- 'friends.getlists',
102
- 'friends.getmutualfriends',
103
- 'gifts.get',
104
- 'groups.get',
105
- 'groups.getmembers',
106
- 'intl.gettranslations',
107
- 'links.get',
108
- 'notes.get',
109
- 'notifications.get',
110
- 'pages.getinfo',
111
- 'pages.isadmin',
112
- 'pages.isappadded',
113
- 'pages.isfan',
114
- 'permissions.checkavailableapiaccess',
115
- 'permissions.checkgrantedapiaccess',
116
- 'photos.get',
117
- 'photos.getalbums',
118
- 'photos.gettags',
119
- 'profile.getinfo',
120
- 'profile.getinfooptions',
121
- 'stream.get',
122
- 'stream.getcomments',
123
- 'stream.getfilters',
124
- 'users.getinfo',
125
- 'users.getloggedinuser',
126
- 'users.getstandardinfo',
127
- 'users.hasapppermission',
128
- 'users.isappuser',
129
- 'users.isverified',
130
- 'video.getuploadlimits'
131
- ]
132
- end
133
-
134
- end # module Facebook
135
- end # module Koala
@@ -1,168 +0,0 @@
1
- shared_examples_for "Koala RestAPI" do
2
- # REST_CALL
3
- describe "when making a rest request" do
4
- it "uses the proper path" do
5
- method = double('methodName')
6
- expect(@api).to receive(:api).with(
7
- "method/#{method}",
8
- anything,
9
- anything,
10
- anything
11
- )
12
-
13
- @api.rest_call(method)
14
- end
15
-
16
- it "always uses the rest api" do
17
- expect(@api).to 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 "sets the read_only option to true if the method is listed in the read-only list" do
28
- method = Koala::Facebook::API::READ_ONLY_METHODS.first
29
-
30
- expect(@api).to 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 "sets 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
- expect(@api).to 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 "takes an optional hash of arguments" do
55
- args = {:arg1 => 'arg1'}
56
-
57
- expect(@api).to 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 "always asks for JSON" do
68
- expect(@api).to 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 "passes any options provided to the API" do
79
- options = {:a => 2}
80
-
81
- expect(@api).to 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 "uses get by default" do
92
- expect(@api).to receive(:api).with(
93
- anything,
94
- anything,
95
- "get",
96
- anything
97
- )
98
-
99
- @api.rest_call('anything')
100
- end
101
-
102
- it "allows you to specify other http methods as the last argument" do
103
- method = 'bar'
104
- expect(@api).to receive(:api).with(
105
- anything,
106
- anything,
107
- method,
108
- anything
109
- )
110
-
111
- @api.rest_call('anything', {}, {}, method)
112
- end
113
-
114
- it "throws an APIError if the status code >= 400" do
115
- allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, '{"error_code": "An error occurred!"}', {}))
116
- expect { @api.rest_call(KoalaTest.user1, {}) }.to raise_exception(Koala::Facebook::APIError)
117
- end
118
- end
119
-
120
- it "can use the beta tier" do
121
- @api.rest_call("fql.query", {:query => "select first_name from user where uid = #{KoalaTest.user2_id}"}, :beta => true)
122
- end
123
- end
124
-
125
- shared_examples_for "Koala RestAPI with an access token" do
126
- describe "#set_app_properties" do
127
- it "sends Facebook the properties JSON-encoded as :properties" do
128
- props = {:a => 2, :c => [1, 2, "d"]}
129
- expect(@api).to receive(:rest_call).with(anything, hash_including(:properties => JSON.dump(props)), anything, anything)
130
- @api.set_app_properties(props)
131
- end
132
-
133
- it "calls the admin.setAppProperties method" do
134
- expect(@api).to receive(:rest_call).with("admin.setAppProperties", anything, anything, anything)
135
- @api.set_app_properties({})
136
- end
137
-
138
- it "includes any other provided arguments" do
139
- args = {:c => 3, :d => "a"}
140
- expect(@api).to receive(:rest_call).with(anything, hash_including(args), anything, anything)
141
- @api.set_app_properties({:a => 2}, args)
142
- end
143
-
144
- it "includes any http_options provided" do
145
- opts = {:c => 3, :d => "a"}
146
- expect(@api).to receive(:rest_call).with(anything, anything, opts, anything)
147
- @api.set_app_properties({}, {}, opts)
148
- end
149
-
150
- it "makes a POST" do
151
- expect(@api).to receive(:rest_call).with(anything, anything, anything, "post")
152
- @api.set_app_properties({})
153
- end
154
-
155
- it "can set app properties using the app's access token" do
156
- oauth = Koala::Facebook::OAuth.new(KoalaTest.app_id, KoalaTest.secret)
157
- app_token = oauth.get_app_access_token
158
- @app_api = Koala::Facebook::API.new(app_token)
159
- expect(@app_api.set_app_properties(KoalaTest.app_properties)).to be_truthy
160
- end
161
- end
162
- end
163
-
164
- shared_examples_for "Koala RestAPI without an access token" do
165
- it "can't use set_app_properties" do
166
- expect { @api.set_app_properties(:desktop => 0) }.to raise_error(Koala::Facebook::AuthenticationError)
167
- end
168
- end