koala 2.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +32 -0
- data/Gemfile +5 -3
- data/ISSUE_TEMPLATE +25 -0
- data/PULL_REQUEST_TEMPLATE +11 -0
- data/changelog.md +161 -4
- data/code_of_conduct.md +64 -12
- data/koala.gemspec +5 -1
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +29 -104
- data/lib/koala/api/graph_batch_api.rb +112 -65
- data/lib/koala/api/graph_collection.rb +19 -12
- data/lib/koala/api/graph_error_checker.rb +4 -3
- data/lib/koala/api.rb +65 -26
- data/lib/koala/configuration.rb +56 -0
- data/lib/koala/errors.rb +22 -2
- data/lib/koala/http_service/request.rb +133 -0
- data/lib/koala/http_service/response.rb +6 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -5
- data/lib/koala/http_service.rb +29 -76
- data/lib/koala/oauth.rb +8 -8
- data/lib/koala/realtime_updates.rb +26 -21
- data/lib/koala/test_users.rb +9 -8
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +7 -9
- data/readme.md +83 -109
- data/spec/cases/api_spec.rb +176 -69
- data/spec/cases/configuration_spec.rb +11 -0
- data/spec/cases/error_spec.rb +16 -3
- data/spec/cases/graph_api_batch_spec.rb +75 -44
- data/spec/cases/graph_api_spec.rb +15 -29
- data/spec/cases/graph_collection_spec.rb +47 -34
- data/spec/cases/graph_error_checker_spec.rb +31 -2
- data/spec/cases/http_service/request_spec.rb +250 -0
- data/spec/cases/http_service/response_spec.rb +24 -0
- data/spec/cases/http_service_spec.rb +126 -286
- data/spec/cases/koala_spec.rb +7 -5
- data/spec/cases/oauth_spec.rb +41 -2
- data/spec/cases/realtime_updates_spec.rb +51 -13
- data/spec/cases/test_users_spec.rb +56 -2
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +4 -6
- data/spec/fixtures/mock_facebook_responses.yml +41 -78
- data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
- data/spec/integration/graph_collection_spec.rb +8 -5
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +152 -337
- data/spec/support/koala_test.rb +11 -13
- data/spec/support/mock_http_service.rb +11 -14
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +47 -48
- data/.autotest +0 -12
- data/.travis.yml +0 -17
- data/Guardfile +0 -6
- data/autotest/discover.rb +0 -1
- data/lib/koala/api/rest_api.rb +0 -135
- data/lib/koala/http_service/multipart_request.rb +0 -41
- data/spec/cases/multipart_request_spec.rb +0 -65
- data/spec/support/rest_api_shared_examples.rb +0 -168
data/spec/support/koala_test.rb
CHANGED
@@ -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.
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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"] : "
|
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"] : "
|
199
|
+
test_user? ? @live_testing_friend["id"] : "koppel"
|
202
200
|
end
|
203
201
|
|
204
202
|
def self.user2_id
|
@@ -240,11 +238,11 @@ module KoalaTest
|
|
240
238
|
# JRuby doesn't support typhoeus on Travis
|
241
239
|
unless defined? JRUBY_VERSION
|
242
240
|
require adapter
|
243
|
-
require
|
241
|
+
require "faraday/#{adapter}"
|
244
242
|
Faraday.default_adapter = adapter.to_sym
|
245
243
|
end
|
246
|
-
rescue
|
247
|
-
puts "Unable to load adapter #{adapter}, using Net::HTTP."
|
244
|
+
rescue => e
|
245
|
+
puts "Unable to load adapter #{adapter}, using Net::HTTP. #{e.class} #{e.message}"
|
248
246
|
ensure
|
249
247
|
@adapter_activation_attempted = true
|
250
248
|
end
|
@@ -5,13 +5,10 @@ module Koala
|
|
5
5
|
module MockHTTPService
|
6
6
|
include Koala::HTTPService
|
7
7
|
|
8
|
-
# fix our specs to use ok_json, so we always get the same results from to_json
|
9
|
-
MultiJson.use :ok_json
|
10
|
-
|
11
8
|
# Mocks all HTTP requests for with koala_spec_with_mocks.rb
|
12
9
|
# Mocked values to be included in TEST_DATA used in specs
|
13
10
|
ACCESS_TOKEN = '*'
|
14
|
-
APP_ACCESS_TOKEN = "
|
11
|
+
APP_ACCESS_TOKEN = "********************"
|
15
12
|
OAUTH_CODE = 'OAUTHCODE'
|
16
13
|
|
17
14
|
# Loads testing data
|
@@ -33,10 +30,10 @@ module Koala
|
|
33
30
|
|
34
31
|
# Loads the mock response data via ERB to substitue values for TEST_DATA (see oauth/access_token)
|
35
32
|
mock_response_file_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'mock_facebook_responses.yml')
|
36
|
-
RESPONSES = YAML.
|
33
|
+
RESPONSES = YAML.safe_load(ERB.new(IO.read(mock_response_file_path)).result(binding), [], [], true)
|
37
34
|
|
38
|
-
def self.make_request(
|
39
|
-
if response = match_response(
|
35
|
+
def self.make_request(request)
|
36
|
+
if response = match_response(request.raw_path, request.raw_args, request.raw_verb, request.raw_options)
|
40
37
|
# create response class object
|
41
38
|
response_object = if response.is_a? String
|
42
39
|
Koala::HTTPService::Response.new(200, response, {})
|
@@ -48,12 +45,12 @@ module Koala
|
|
48
45
|
# to place a mock as well as a URL to request from
|
49
46
|
# Facebook's servers for the actual data
|
50
47
|
# (Don't forget to replace ACCESS_TOKEN with a real access token)
|
51
|
-
data_trace = [
|
48
|
+
data_trace = [request.raw_path, request.raw_args, request.raw_verb, request.raw_options] * ': '
|
52
49
|
|
53
|
-
args =
|
50
|
+
args = request.raw_args == 'no_args' ? '' : "#{request.raw_args}&"
|
54
51
|
args += 'format=json'
|
55
52
|
|
56
|
-
raise "Missing a mock response for #{data_trace}\nAPI PATH: #{[path,
|
53
|
+
raise "Missing a mock response for #{data_trace}\nAPI PATH: #{[request.path, request.raw_args].join('?')}"
|
57
54
|
end
|
58
55
|
|
59
56
|
response_object
|
@@ -68,7 +65,7 @@ module Koala
|
|
68
65
|
|
69
66
|
# For a given query, see if our mock responses YAML has a resopnse for it.
|
70
67
|
def self.match_response(path, args, verb, options = {})
|
71
|
-
server =
|
68
|
+
server = 'graph_api'
|
72
69
|
path = 'root' if path == '' || path == '/'
|
73
70
|
verb = (verb || 'get').to_s
|
74
71
|
token = args.delete('access_token')
|
@@ -91,8 +88,8 @@ module Koala
|
|
91
88
|
args = arguments.inject({}) do |hash, (k, v)|
|
92
89
|
# ensure our args are all stringified
|
93
90
|
value = if v.is_a?(String)
|
94
|
-
should_json_decode?(v) ?
|
95
|
-
elsif v.is_a?(Koala::UploadableIO)
|
91
|
+
should_json_decode?(v) ? JSON.parse(v) : v
|
92
|
+
elsif v.is_a?(Koala::HTTPService::UploadableIO)
|
96
93
|
# obviously there are no files in the yaml
|
97
94
|
"[FILE]"
|
98
95
|
else
|
@@ -122,7 +119,7 @@ module Koala
|
|
122
119
|
# will remove +'s in restriction strings
|
123
120
|
string.split("&").reduce({}) do |hash, component|
|
124
121
|
k, v = component.split("=", 2) # we only care about the first =
|
125
|
-
value = should_json_decode?(v) ?
|
122
|
+
value = should_json_decode?(v) ? JSON.parse(v) : v.to_s rescue v.to_s
|
126
123
|
# some special-casing, unfortunate but acceptable in this testing
|
127
124
|
# environment
|
128
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,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.5.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:
|
11
|
+
date: 2023-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: faraday
|
28
|
+
name: faraday-multipart
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rexml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
|
56
84
|
access to the social graph via the Graph and REST APIs, as well as support for realtime
|
57
85
|
updates and OAuth and Facebook Connect authentication. Koala is fully tested and
|
@@ -64,31 +92,30 @@ extra_rdoc_files:
|
|
64
92
|
- readme.md
|
65
93
|
- changelog.md
|
66
94
|
files:
|
67
|
-
- ".
|
95
|
+
- ".github/workflows/test.yml"
|
68
96
|
- ".gitignore"
|
69
97
|
- ".rspec"
|
70
|
-
- ".travis.yml"
|
71
98
|
- ".yardopts"
|
72
99
|
- Gemfile
|
73
|
-
-
|
100
|
+
- ISSUE_TEMPLATE
|
74
101
|
- LICENSE
|
75
102
|
- Manifest
|
103
|
+
- PULL_REQUEST_TEMPLATE
|
76
104
|
- Rakefile
|
77
|
-
- autotest/discover.rb
|
78
105
|
- changelog.md
|
79
106
|
- code_of_conduct.md
|
80
107
|
- koala.gemspec
|
81
108
|
- lib/koala.rb
|
82
109
|
- lib/koala/api.rb
|
83
110
|
- lib/koala/api/batch_operation.rb
|
84
|
-
- lib/koala/api/
|
111
|
+
- lib/koala/api/graph_api_methods.rb
|
85
112
|
- lib/koala/api/graph_batch_api.rb
|
86
113
|
- lib/koala/api/graph_collection.rb
|
87
114
|
- lib/koala/api/graph_error_checker.rb
|
88
|
-
- lib/koala/
|
115
|
+
- lib/koala/configuration.rb
|
89
116
|
- lib/koala/errors.rb
|
90
117
|
- lib/koala/http_service.rb
|
91
|
-
- lib/koala/http_service/
|
118
|
+
- lib/koala/http_service/request.rb
|
92
119
|
- lib/koala/http_service/response.rb
|
93
120
|
- lib/koala/http_service/uploadable_io.rb
|
94
121
|
- lib/koala/oauth.rb
|
@@ -98,15 +125,17 @@ files:
|
|
98
125
|
- lib/koala/version.rb
|
99
126
|
- readme.md
|
100
127
|
- spec/cases/api_spec.rb
|
128
|
+
- spec/cases/configuration_spec.rb
|
101
129
|
- spec/cases/error_spec.rb
|
102
130
|
- spec/cases/graph_api_batch_spec.rb
|
103
131
|
- spec/cases/graph_api_spec.rb
|
104
132
|
- spec/cases/graph_collection_spec.rb
|
105
133
|
- spec/cases/graph_error_checker_spec.rb
|
134
|
+
- spec/cases/http_service/request_spec.rb
|
135
|
+
- spec/cases/http_service/response_spec.rb
|
106
136
|
- spec/cases/http_service_spec.rb
|
107
137
|
- spec/cases/koala_spec.rb
|
108
138
|
- spec/cases/koala_test_spec.rb
|
109
|
-
- spec/cases/multipart_request_spec.rb
|
110
139
|
- spec/cases/oauth_spec.rb
|
111
140
|
- spec/cases/realtime_updates_spec.rb
|
112
141
|
- spec/cases/test_users_spec.rb
|
@@ -116,6 +145,7 @@ files:
|
|
116
145
|
- spec/fixtures/cat.m4v
|
117
146
|
- spec/fixtures/facebook_data.yml
|
118
147
|
- spec/fixtures/mock_facebook_responses.yml
|
148
|
+
- spec/fixtures/vcr_cassettes/app_test_accounts.yml
|
119
149
|
- spec/fixtures/vcr_cassettes/friend_list_next_page.yml
|
120
150
|
- spec/integration/graph_collection_spec.rb
|
121
151
|
- spec/spec_helper.rb
|
@@ -123,7 +153,6 @@ files:
|
|
123
153
|
- spec/support/graph_api_shared_examples.rb
|
124
154
|
- spec/support/koala_test.rb
|
125
155
|
- spec/support/mock_http_service.rb
|
126
|
-
- spec/support/rest_api_shared_examples.rb
|
127
156
|
- spec/support/uploadable_io_shared_examples.rb
|
128
157
|
homepage: http://github.com/arsduo/koala
|
129
158
|
licenses:
|
@@ -141,46 +170,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
170
|
requirements:
|
142
171
|
- - ">="
|
143
172
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
173
|
+
version: '2.1'
|
145
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
175
|
requirements:
|
147
176
|
- - ">="
|
148
177
|
- !ruby/object:Gem::Version
|
149
178
|
version: '0'
|
150
179
|
requirements: []
|
151
|
-
|
152
|
-
rubygems_version: 2.4.6
|
180
|
+
rubygems_version: 3.4.0.dev
|
153
181
|
signing_key:
|
154
182
|
specification_version: 4
|
155
183
|
summary: A lightweight, flexible library for Facebook with support for the Graph API,
|
156
184
|
the REST API, realtime updates, and OAuth authentication.
|
157
|
-
test_files:
|
158
|
-
- spec/cases/api_spec.rb
|
159
|
-
- spec/cases/error_spec.rb
|
160
|
-
- spec/cases/graph_api_batch_spec.rb
|
161
|
-
- spec/cases/graph_api_spec.rb
|
162
|
-
- spec/cases/graph_collection_spec.rb
|
163
|
-
- spec/cases/graph_error_checker_spec.rb
|
164
|
-
- spec/cases/http_service_spec.rb
|
165
|
-
- spec/cases/koala_spec.rb
|
166
|
-
- spec/cases/koala_test_spec.rb
|
167
|
-
- spec/cases/multipart_request_spec.rb
|
168
|
-
- spec/cases/oauth_spec.rb
|
169
|
-
- spec/cases/realtime_updates_spec.rb
|
170
|
-
- spec/cases/test_users_spec.rb
|
171
|
-
- spec/cases/uploadable_io_spec.rb
|
172
|
-
- spec/cases/utils_spec.rb
|
173
|
-
- spec/fixtures/beach.jpg
|
174
|
-
- spec/fixtures/cat.m4v
|
175
|
-
- spec/fixtures/facebook_data.yml
|
176
|
-
- spec/fixtures/mock_facebook_responses.yml
|
177
|
-
- spec/fixtures/vcr_cassettes/friend_list_next_page.yml
|
178
|
-
- spec/integration/graph_collection_spec.rb
|
179
|
-
- spec/spec_helper.rb
|
180
|
-
- spec/support/custom_matchers.rb
|
181
|
-
- spec/support/graph_api_shared_examples.rb
|
182
|
-
- spec/support/koala_test.rb
|
183
|
-
- spec/support/mock_http_service.rb
|
184
|
-
- spec/support/rest_api_shared_examples.rb
|
185
|
-
- spec/support/uploadable_io_shared_examples.rb
|
186
|
-
has_rdoc:
|
185
|
+
test_files: []
|
data/.autotest
DELETED
data/.travis.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
# MRI
|
6
|
-
- 2.0
|
7
|
-
- 2.1
|
8
|
-
- 2.2
|
9
|
-
- 2.3.0
|
10
|
-
# Rubinius is failing due to segfaults on Travis (and takes significantly longer to run)
|
11
|
-
# those builds will be restored later
|
12
|
-
# jruby
|
13
|
-
- jruby-19mode
|
14
|
-
bundler_args: --without development
|
15
|
-
addons:
|
16
|
-
code_climate:
|
17
|
-
repo_token: 7af99d9225b4c14640f9ec3cb2e24d2f7103ac49417b0bd989188fb6c25f2909
|
data/Guardfile
DELETED
data/autotest/discover.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Autotest.add_discovery { "rspec2" }
|
data/lib/koala/api/rest_api.rb
DELETED
@@ -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 => MultiJson.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 = MultiJson.load(response.body)
|
48
|
-
rescue MultiJson::DecodeError
|
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,41 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Koala
|
4
|
-
module HTTPService
|
5
|
-
class MultipartRequest < Faraday::Request::Multipart
|
6
|
-
# Facebook expects nested parameters to be passed in a certain way
|
7
|
-
# Based on our testing (https://github.com/arsduo/koala/issues/125),
|
8
|
-
# Faraday needs two changes to make that work:
|
9
|
-
# 1) [] need to be escaped (e.g. params[foo]=bar ==> params%5Bfoo%5D=bar)
|
10
|
-
# 2) such messages need to be multipart-encoded
|
11
|
-
|
12
|
-
self.mime_type = 'multipart/form-data'.freeze
|
13
|
-
|
14
|
-
def process_request?(env)
|
15
|
-
# if the request values contain any hashes or arrays, multipart it
|
16
|
-
super || !!(env[:body].respond_to?(:values) && env[:body].values.find {|v| v.is_a?(Hash) || v.is_a?(Array)})
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def process_params(params, prefix = nil, pieces = nil, &block)
|
21
|
-
params.inject(pieces || []) do |all, (key, value)|
|
22
|
-
key = "#{prefix}%5B#{key}%5D" if prefix
|
23
|
-
|
24
|
-
case value
|
25
|
-
when Array
|
26
|
-
values = value.inject([]) { |a,v| a << [nil, v] }
|
27
|
-
process_params(values, key, all, &block)
|
28
|
-
when Hash
|
29
|
-
process_params(value, key, all, &block)
|
30
|
-
else
|
31
|
-
all << block.call(key, value)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# @private
|
39
|
-
# legacy support for when MultipartRequest lived directly under Koala
|
40
|
-
MultipartRequest = HTTPService::MultipartRequest
|
41
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Koala::HTTPService::MultipartRequest do
|
4
|
-
it "is a subclass of Faraday::Request::Multipart" do
|
5
|
-
expect(Koala::HTTPService::MultipartRequest.superclass).to eq(Faraday::Request::Multipart)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "defines mime_type as multipart/form-data" do
|
9
|
-
expect(Koala::HTTPService::MultipartRequest.mime_type).to eq('multipart/form-data')
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#process_request?" do
|
13
|
-
before :each do
|
14
|
-
@env = Faraday::Env.new
|
15
|
-
@multipart = Koala::HTTPService::MultipartRequest.new
|
16
|
-
allow(@multipart).to receive(:request_type).and_return("")
|
17
|
-
end
|
18
|
-
|
19
|
-
# no way to test the call to super, unfortunately
|
20
|
-
it "returns true if env[:body] is a hash with at least one hash in its values" do
|
21
|
-
@env[:body] = {:a => {:c => 2}}
|
22
|
-
expect(@multipart.process_request?(@env)).to be_truthy
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns true if env[:body] is a hash with at least one array in its values" do
|
26
|
-
@env[:body] = {:a => [:c, 2]}
|
27
|
-
expect(@multipart.process_request?(@env)).to be_truthy
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns true if env[:body] is a hash with mixed objects in its values" do
|
31
|
-
@env[:body] = {:a => [:c, 2], :b => {:e => :f}}
|
32
|
-
expect(@multipart.process_request?(@env)).to be_truthy
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns false if env[:body] is a string" do
|
36
|
-
@env[:body] = "my body"
|
37
|
-
expect(@multipart.process_request?(@env)).to be_falsey
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns false if env[:body] is a hash without an array or hash value" do
|
41
|
-
@env[:body] = {:a => 3}
|
42
|
-
expect(@multipart.process_request?(@env)).to be_falsey
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#process_params" do
|
47
|
-
before :each do
|
48
|
-
@parent = Faraday::Request::Multipart.new
|
49
|
-
@multipart = Koala::HTTPService::MultipartRequest.new
|
50
|
-
@block = lambda {|k, v| "#{k}=#{v}"}
|
51
|
-
end
|
52
|
-
|
53
|
-
it "is identical to the parent for requests without a prefix" do
|
54
|
-
hash = {:a => 2, :c => "3"}
|
55
|
-
expect(@multipart.process_params(hash, &@block)).to eq(@parent.process_params(hash, &@block))
|
56
|
-
end
|
57
|
-
|
58
|
-
it "replaces encodes [ and ] if the request has a prefix" do
|
59
|
-
hash = {:a => 2, :c => "3"}
|
60
|
-
prefix = "foo"
|
61
|
-
# process_params returns an array
|
62
|
-
expect(@multipart.process_params(hash, prefix, &@block).join("&")).to eq(@parent.process_params(hash, prefix, &@block).join("&").gsub(/\[/, "%5B").gsub(/\]/, "%5D"))
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|