koala 2.5.0 → 3.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -3
  3. data/Gemfile +1 -1
  4. data/ISSUE_TEMPLATE +25 -0
  5. data/PULL_REQUEST_TEMPLATE +11 -0
  6. data/changelog.md +66 -4
  7. data/code_of_conduct.md +64 -12
  8. data/koala.gemspec +3 -0
  9. data/lib/koala/api/batch_operation.rb +3 -6
  10. data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +13 -102
  11. data/lib/koala/api/graph_batch_api.rb +112 -65
  12. data/lib/koala/api/graph_collection.rb +19 -12
  13. data/lib/koala/api/graph_error_checker.rb +1 -1
  14. data/lib/koala/api.rb +49 -25
  15. data/lib/koala/configuration.rb +49 -0
  16. data/lib/koala/errors.rb +1 -1
  17. data/lib/koala/http_service/multipart_request.rb +6 -10
  18. data/lib/koala/http_service/request.rb +135 -0
  19. data/lib/koala/http_service/response.rb +6 -4
  20. data/lib/koala/http_service/uploadable_io.rb +0 -4
  21. data/lib/koala/http_service.rb +18 -76
  22. data/lib/koala/oauth.rb +7 -7
  23. data/lib/koala/realtime_updates.rb +26 -21
  24. data/lib/koala/test_users.rb +9 -8
  25. data/lib/koala/version.rb +1 -1
  26. data/lib/koala.rb +6 -8
  27. data/readme.md +50 -109
  28. data/spec/cases/api_spec.rb +99 -69
  29. data/spec/cases/configuration_spec.rb +11 -0
  30. data/spec/cases/graph_api_batch_spec.rb +73 -42
  31. data/spec/cases/graph_api_spec.rb +15 -29
  32. data/spec/cases/graph_collection_spec.rb +47 -34
  33. data/spec/cases/graph_error_checker_spec.rb +6 -1
  34. data/spec/cases/http_service/request_spec.rb +242 -0
  35. data/spec/cases/http_service/response_spec.rb +24 -0
  36. data/spec/cases/http_service_spec.rb +102 -296
  37. data/spec/cases/koala_spec.rb +7 -5
  38. data/spec/cases/oauth_spec.rb +40 -1
  39. data/spec/cases/realtime_updates_spec.rb +51 -13
  40. data/spec/cases/test_users_spec.rb +56 -2
  41. data/spec/cases/uploadable_io_spec.rb +31 -31
  42. data/spec/fixtures/cat.m4v +0 -0
  43. data/spec/fixtures/facebook_data.yml +4 -6
  44. data/spec/fixtures/mock_facebook_responses.yml +29 -69
  45. data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
  46. data/spec/integration/graph_collection_spec.rb +8 -5
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/support/graph_api_shared_examples.rb +143 -336
  49. data/spec/support/koala_test.rb +8 -10
  50. data/spec/support/mock_http_service.rb +9 -9
  51. data/spec/support/uploadable_io_shared_examples.rb +4 -4
  52. metadata +31 -11
  53. data/.autotest +0 -12
  54. data/Guardfile +0 -6
  55. data/autotest/discover.rb +0 -1
  56. data/lib/koala/api/rest_api.rb +0 -135
  57. data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -106,8 +106,6 @@ module KoalaTest
106
106
  self.code = data["oauth_test_data"]["code"]
107
107
  self.session_key = data["oauth_test_data"]["session_key"]
108
108
 
109
- self.vcr_oauth_token = data["vcr_data"]["oauth_token"]
110
-
111
109
  # fix the search time so it can be used in the mock responses
112
110
  self.search_time = data["search_time"] || (Time.now - 3600).to_s
113
111
  end
@@ -157,12 +155,12 @@ module KoalaTest
157
155
  print "Validating permissions for live testing..."
158
156
  # make sure we have the necessary permissions
159
157
  api = Koala::Facebook::API.new(token)
160
- perms = api.fql_query("select #{testing_permissions} from permissions where uid = me()")[0]
161
- perms.each_pair do |perm, value|
162
- if value == (perm == "read_insights" ? 1 : 0) # live testing depends on insights calls failing
163
- puts "failed!\n" # put a new line after the print above
164
- raise ArgumentError, "Your access token must have #{testing_permissions.join(", ")}, and lack read_insights. You have: #{perms.inspect}"
165
- end
158
+ perms = api.get_connect("me", "permissions")["data"]
159
+
160
+ # live testing depends on insights calls failing
161
+ if perms.keys.include?("read_insights") || (perms.keys & testing_permissions) != testing_permissions
162
+ puts "failed!\n" # put a new line after the print above
163
+ raise ArgumentError, "Your access token must have #{testing_permissions.join(", ")}, and lack read_insights. You have: #{perms.inspect}"
166
164
  end
167
165
  puts "done!"
168
166
  end
@@ -183,7 +181,7 @@ module KoalaTest
183
181
  # Data for testing
184
182
  def self.user1
185
183
  # user ID, either numeric or username
186
- test_user? ? @live_testing_user["id"] : "koppel"
184
+ test_user? ? @live_testing_user["id"] : "barackobama"
187
185
  end
188
186
 
189
187
  def self.user1_id
@@ -198,7 +196,7 @@ module KoalaTest
198
196
 
199
197
  def self.user2
200
198
  # see notes for user1
201
- test_user? ? @live_testing_friend["id"] : "lukeshepard"
199
+ test_user? ? @live_testing_friend["id"] : "koppel"
202
200
  end
203
201
 
204
202
  def self.user2_id
@@ -32,8 +32,8 @@ module Koala
32
32
  mock_response_file_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'mock_facebook_responses.yml')
33
33
  RESPONSES = YAML.load(ERB.new(IO.read(mock_response_file_path)).result(binding))
34
34
 
35
- def self.make_request(path, args, verb, options = {})
36
- if response = match_response(path, args, verb, options)
35
+ def self.make_request(request)
36
+ if response = match_response(request.raw_path, request.raw_args, request.raw_verb, request.raw_options)
37
37
  # create response class object
38
38
  response_object = if response.is_a? String
39
39
  Koala::HTTPService::Response.new(200, response, {})
@@ -45,12 +45,12 @@ module Koala
45
45
  # to place a mock as well as a URL to request from
46
46
  # Facebook's servers for the actual data
47
47
  # (Don't forget to replace ACCESS_TOKEN with a real access token)
48
- data_trace = [path, args, verb, options] * ': '
48
+ data_trace = [request.raw_path, request.raw_args, request.raw_verb, request.raw_options] * ': '
49
49
 
50
- args = args == 'no_args' ? '' : "#{args}&"
50
+ args = request.raw_args == 'no_args' ? '' : "#{request.raw_args}&"
51
51
  args += 'format=json'
52
52
 
53
- raise "Missing a mock response for #{data_trace}\nAPI PATH: #{[path, args].join('?')}"
53
+ raise "Missing a mock response for #{data_trace}\nAPI PATH: #{[request.path, request.raw_args].join('?')}"
54
54
  end
55
55
 
56
56
  response_object
@@ -65,7 +65,7 @@ module Koala
65
65
 
66
66
  # For a given query, see if our mock responses YAML has a resopnse for it.
67
67
  def self.match_response(path, args, verb, options = {})
68
- server = options[:rest_api] ? 'rest_api' : 'graph_api'
68
+ server = 'graph_api'
69
69
  path = 'root' if path == '' || path == '/'
70
70
  verb = (verb || 'get').to_s
71
71
  token = args.delete('access_token')
@@ -88,8 +88,8 @@ module Koala
88
88
  args = arguments.inject({}) do |hash, (k, v)|
89
89
  # ensure our args are all stringified
90
90
  value = if v.is_a?(String)
91
- should_json_decode?(v) ? JSON.load(v) : v
92
- elsif v.is_a?(Koala::UploadableIO)
91
+ should_json_decode?(v) ? JSON.parse(v) : v
92
+ elsif v.is_a?(Koala::HTTPService::UploadableIO)
93
93
  # obviously there are no files in the yaml
94
94
  "[FILE]"
95
95
  else
@@ -119,7 +119,7 @@ module Koala
119
119
  # will remove +'s in restriction strings
120
120
  string.split("&").reduce({}) do |hash, component|
121
121
  k, v = component.split("=", 2) # we only care about the first =
122
- value = should_json_decode?(v) ? JSON.load(v) : v.to_s rescue v.to_s
122
+ value = should_json_decode?(v) ? JSON.parse(v) : v.to_s rescue v.to_s
123
123
  # some special-casing, unfortunate but acceptable in this testing
124
124
  # environment
125
125
  value = nil if value.empty?
@@ -12,7 +12,7 @@ shared_examples_for "MIME::Types can't return results" do
12
12
  else
13
13
  @koala_io_params[0] = path
14
14
  end
15
- expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
15
+ expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
16
16
  end
17
17
 
18
18
  it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
@@ -22,7 +22,7 @@ shared_examples_for "MIME::Types can't return results" do
22
22
  else
23
23
  @koala_io_params[0] = path
24
24
  end
25
- expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
25
+ expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
26
26
  end
27
27
  end
28
28
 
@@ -37,7 +37,7 @@ shared_examples_for "MIME::Types can't return results" do
37
37
  end
38
38
 
39
39
  it "should throw an exception" do
40
- expect { Koala::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
40
+ expect { Koala::HTTPService::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
41
41
  end
42
42
  end
43
43
  end
@@ -47,7 +47,7 @@ shared_examples_for "determining a mime type" do
47
47
  it "should return an UploadIO with MIME::Types-determined type if the type exists" do
48
48
  type_result = ["type"]
49
49
  allow(Koala::MIME::Types).to receive(:type_for).and_return(type_result)
50
- expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(type_result.first)
50
+ expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(type_result.first)
51
51
  end
52
52
  end
53
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Koppel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
41
55
  description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
42
56
  access to the social graph via the Graph and REST APIs, as well as support for realtime
43
57
  updates and OAuth and Facebook Connect authentication. Koala is fully tested and
@@ -50,31 +64,31 @@ extra_rdoc_files:
50
64
  - readme.md
51
65
  - changelog.md
52
66
  files:
53
- - ".autotest"
54
67
  - ".gitignore"
55
68
  - ".rspec"
56
69
  - ".travis.yml"
57
70
  - ".yardopts"
58
71
  - Gemfile
59
- - Guardfile
72
+ - ISSUE_TEMPLATE
60
73
  - LICENSE
61
74
  - Manifest
75
+ - PULL_REQUEST_TEMPLATE
62
76
  - Rakefile
63
- - autotest/discover.rb
64
77
  - changelog.md
65
78
  - code_of_conduct.md
66
79
  - koala.gemspec
67
80
  - lib/koala.rb
68
81
  - lib/koala/api.rb
69
82
  - lib/koala/api/batch_operation.rb
70
- - lib/koala/api/graph_api.rb
83
+ - lib/koala/api/graph_api_methods.rb
71
84
  - lib/koala/api/graph_batch_api.rb
72
85
  - lib/koala/api/graph_collection.rb
73
86
  - lib/koala/api/graph_error_checker.rb
74
- - lib/koala/api/rest_api.rb
87
+ - lib/koala/configuration.rb
75
88
  - lib/koala/errors.rb
76
89
  - lib/koala/http_service.rb
77
90
  - lib/koala/http_service/multipart_request.rb
91
+ - lib/koala/http_service/request.rb
78
92
  - lib/koala/http_service/response.rb
79
93
  - lib/koala/http_service/uploadable_io.rb
80
94
  - lib/koala/oauth.rb
@@ -84,11 +98,14 @@ files:
84
98
  - lib/koala/version.rb
85
99
  - readme.md
86
100
  - spec/cases/api_spec.rb
101
+ - spec/cases/configuration_spec.rb
87
102
  - spec/cases/error_spec.rb
88
103
  - spec/cases/graph_api_batch_spec.rb
89
104
  - spec/cases/graph_api_spec.rb
90
105
  - spec/cases/graph_collection_spec.rb
91
106
  - spec/cases/graph_error_checker_spec.rb
107
+ - spec/cases/http_service/request_spec.rb
108
+ - spec/cases/http_service/response_spec.rb
92
109
  - spec/cases/http_service_spec.rb
93
110
  - spec/cases/koala_spec.rb
94
111
  - spec/cases/koala_test_spec.rb
@@ -102,6 +119,7 @@ files:
102
119
  - spec/fixtures/cat.m4v
103
120
  - spec/fixtures/facebook_data.yml
104
121
  - spec/fixtures/mock_facebook_responses.yml
122
+ - spec/fixtures/vcr_cassettes/app_test_accounts.yml
105
123
  - spec/fixtures/vcr_cassettes/friend_list_next_page.yml
106
124
  - spec/integration/graph_collection_spec.rb
107
125
  - spec/spec_helper.rb
@@ -109,7 +127,6 @@ files:
109
127
  - spec/support/graph_api_shared_examples.rb
110
128
  - spec/support/koala_test.rb
111
129
  - spec/support/mock_http_service.rb
112
- - spec/support/rest_api_shared_examples.rb
113
130
  - spec/support/uploadable_io_shared_examples.rb
114
131
  homepage: http://github.com/arsduo/koala
115
132
  licenses:
@@ -127,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
144
  requirements:
128
145
  - - ">="
129
146
  - !ruby/object:Gem::Version
130
- version: '0'
147
+ version: '2.1'
131
148
  required_rubygems_version: !ruby/object:Gem::Requirement
132
149
  requirements:
133
150
  - - ">="
@@ -135,18 +152,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
152
  version: '0'
136
153
  requirements: []
137
154
  rubyforge_project:
138
- rubygems_version: 2.4.3
155
+ rubygems_version: 2.6.10
139
156
  signing_key:
140
157
  specification_version: 4
141
158
  summary: A lightweight, flexible library for Facebook with support for the Graph API,
142
159
  the REST API, realtime updates, and OAuth authentication.
143
160
  test_files:
144
161
  - spec/cases/api_spec.rb
162
+ - spec/cases/configuration_spec.rb
145
163
  - spec/cases/error_spec.rb
146
164
  - spec/cases/graph_api_batch_spec.rb
147
165
  - spec/cases/graph_api_spec.rb
148
166
  - spec/cases/graph_collection_spec.rb
149
167
  - spec/cases/graph_error_checker_spec.rb
168
+ - spec/cases/http_service/request_spec.rb
169
+ - spec/cases/http_service/response_spec.rb
150
170
  - spec/cases/http_service_spec.rb
151
171
  - spec/cases/koala_spec.rb
152
172
  - spec/cases/koala_test_spec.rb
@@ -160,6 +180,7 @@ test_files:
160
180
  - spec/fixtures/cat.m4v
161
181
  - spec/fixtures/facebook_data.yml
162
182
  - spec/fixtures/mock_facebook_responses.yml
183
+ - spec/fixtures/vcr_cassettes/app_test_accounts.yml
163
184
  - spec/fixtures/vcr_cassettes/friend_list_next_page.yml
164
185
  - spec/integration/graph_collection_spec.rb
165
186
  - spec/spec_helper.rb
@@ -167,6 +188,5 @@ test_files:
167
188
  - spec/support/graph_api_shared_examples.rb
168
189
  - spec/support/koala_test.rb
169
190
  - spec/support/mock_http_service.rb
170
- - spec/support/rest_api_shared_examples.rb
171
191
  - spec/support/uploadable_io_shared_examples.rb
172
192
  has_rdoc:
data/.autotest DELETED
@@ -1,12 +0,0 @@
1
- # Override autotest default magic to rerun all tests every time a
2
- # change is detected on the file system.
3
- class Autotest
4
-
5
- def get_to_green
6
- begin
7
- rerun_all_tests
8
- wait_for_changes unless all_good
9
- end until all_good
10
- end
11
-
12
- end
data/Guardfile DELETED
@@ -1,6 +0,0 @@
1
- guard 'rspec', :version => 2 do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
6
-
data/autotest/discover.rb DELETED
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
@@ -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