koala 3.2.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile +1 -0
- data/changelog.md +24 -0
- data/koala.gemspec +2 -1
- data/lib/koala/http_service/request.rb +1 -3
- data/lib/koala/http_service/uploadable_io.rb +0 -1
- data/lib/koala/http_service.rb +2 -2
- data/lib/koala/version.rb +1 -1
- data/spec/cases/api_spec.rb +1 -1
- data/spec/cases/graph_error_checker_spec.rb +1 -1
- data/spec/cases/http_service/request_spec.rb +14 -6
- data/spec/cases/http_service_spec.rb +5 -10
- data/spec/support/koala_test.rb +3 -3
- metadata +21 -9
- data/lib/koala/http_service/multipart_request.rb +0 -37
- data/spec/cases/multipart_request_spec.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd1ef11b53dbfd2dc45d096a2b3f26d86aab74927758638b95670be82d5a81b3
|
4
|
+
data.tar.gz: 4f8694539f46568a268740064fa16f5f9084198f90ccdb2bf66b532d0fd280ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa13fcdb702dacaf5ea61d905f1d4d09e067b8181c9bbe9f1e210d80718eb8015953b770fc79332658bf9a0c5b11e0923a31c85049fde4a5dc566367f5ed63a1
|
7
|
+
data.tar.gz: cda4d98559e43ce1cb2cfd4c308431020c32443282cf2161230f6cae81bfc7608494181f55cc15e8dfc4386b248a81ec7d2306125487a41b6d4c7c6f4bc84c09
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
data/changelog.md
CHANGED
@@ -15,6 +15,30 @@ Testing improvements:
|
|
15
15
|
|
16
16
|
Others:
|
17
17
|
|
18
|
+
v3.4.0 (2023-01-05)
|
19
|
+
======
|
20
|
+
|
21
|
+
Updated features:
|
22
|
+
|
23
|
+
* Force use by default of HTTPS (instead of HTTP) when there is no access token.
|
24
|
+
HTTP can still be used by passing :use_ssl => false in the options hash for an api call ([#678](https://github.com/arsduo/koala/pull/678/files))
|
25
|
+
|
26
|
+
v3.3.0 (2022-09-27)
|
27
|
+
======
|
28
|
+
|
29
|
+
Updated features:
|
30
|
+
|
31
|
+
* Removed restriction on faraday < 2 ([#666](https://github.com/arsduo/koala/pull/666))
|
32
|
+
|
33
|
+
Internal improvements:
|
34
|
+
|
35
|
+
* Remove multipart hack and use default faraday multipart middleware ([#664](https://github.com/arsduo/koala/pull/664))
|
36
|
+
|
37
|
+
Testing improvements:
|
38
|
+
|
39
|
+
* Fix tests with ruby-head ([#674](https://github.com/arsduo/koala/pull/674))
|
40
|
+
* Keep supported rubies (non EOL) for CI ([#675](https://github.com/arsduo/koala/pull/675))
|
41
|
+
|
18
42
|
v3.2.0 (2022-05-27)
|
19
43
|
======
|
20
44
|
|
data/koala.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |gem|
|
|
23
23
|
|
24
24
|
gem.required_ruby_version = '>= 2.1'
|
25
25
|
|
26
|
-
gem.add_runtime_dependency("faraday"
|
26
|
+
gem.add_runtime_dependency("faraday")
|
27
|
+
gem.add_runtime_dependency("faraday-multipart")
|
27
28
|
gem.add_runtime_dependency("addressable")
|
28
29
|
gem.add_runtime_dependency("json", ">= 1.8")
|
29
30
|
gem.add_runtime_dependency("rexml")
|
@@ -106,9 +106,7 @@ module Koala
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def add_ssl_options(opts)
|
109
|
-
# require https
|
110
|
-
return opts unless raw_args["access_token"]
|
111
|
-
|
109
|
+
# require https by default (can be overriden by explicitly setting other SSL options)
|
112
110
|
{
|
113
111
|
use_ssl: true,
|
114
112
|
ssl: {verify: true}.merge(opts[:ssl] || {})
|
data/lib/koala/http_service.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'faraday/multipart' unless defined? Faraday::FilePart # hack for faraday < 1.9 to avoid warnings
|
3
3
|
require 'koala/http_service/uploadable_io'
|
4
4
|
require 'koala/http_service/response'
|
5
5
|
require 'koala/http_service/request'
|
@@ -19,7 +19,7 @@ module Koala
|
|
19
19
|
# We encode requests in a Facebook-compatible multipart request,
|
20
20
|
# and use whichever adapter has been configured for this application.
|
21
21
|
DEFAULT_MIDDLEWARE = Proc.new do |builder|
|
22
|
-
builder.
|
22
|
+
builder.request :multipart
|
23
23
|
builder.request :url_encoded
|
24
24
|
builder.adapter Faraday.default_adapter
|
25
25
|
end
|
data/lib/koala/version.rb
CHANGED
data/spec/cases/api_spec.rb
CHANGED
@@ -345,7 +345,7 @@ describe "Koala::Facebook::API" do
|
|
345
345
|
response = Koala::HTTPService::Response.new(200, result.to_json, { "x-ad-account-usage" => "{\"acc_id_util_pct\"9.67}"})
|
346
346
|
allow(Koala).to receive(:make_request).and_return(response)
|
347
347
|
|
348
|
-
expect(Koala::Utils.logger).to receive(:error).with(
|
348
|
+
expect(Koala::Utils.logger).to receive(:error).with(/JSON::ParserError:.*unexpected token at '{"acc_id_util_pct"9.67}' while parsing x-ad-account-usage = {"acc_id_util_pct"9.67}/)
|
349
349
|
api.graph_call('anything')
|
350
350
|
end
|
351
351
|
|
@@ -104,7 +104,7 @@ module Koala
|
|
104
104
|
"x-app-usage" => '{invalid:json}'
|
105
105
|
)
|
106
106
|
|
107
|
-
expect(Koala::Utils.logger).to receive(:error).with(
|
107
|
+
expect(Koala::Utils.logger).to receive(:error).with(/JSON::ParserError:.*unexpected token at '{invalid:json}' while parsing x-app-usage = {invalid:json}/)
|
108
108
|
expect(error.fb_app_usage).to eq(nil)
|
109
109
|
end
|
110
110
|
|
@@ -176,9 +176,9 @@ module Koala
|
|
176
176
|
end
|
177
177
|
|
178
178
|
describe "ssl options" do
|
179
|
-
it "
|
179
|
+
it "includes the default SSL options even if there's no access token" do
|
180
180
|
request_options = Request.new(path: path, args: args.delete_if {|k, _v| k == "access_token"}, verb: verb, options: options).options
|
181
|
-
expect(request_options).
|
181
|
+
expect(request_options).to include(use_ssl: true, ssl: {verify: true})
|
182
182
|
end
|
183
183
|
|
184
184
|
context "if there is an access_token" do
|
@@ -193,9 +193,9 @@ module Koala
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it "overrides default SSL options with what's provided" do
|
196
|
-
new_ssl_options = {verify: :dunno}
|
197
|
-
request_options = Request.new(path: path, args: args, verb: verb, options: options.merge(
|
198
|
-
expect(request_options
|
196
|
+
new_ssl_options = {use_ssl: false, ssl:{verify: :dunno}}
|
197
|
+
request_options = Request.new(path: path, args: args, verb: verb, options: options.merge(new_ssl_options)).options
|
198
|
+
expect(request_options).to include(new_ssl_options)
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -211,9 +211,17 @@ module Koala
|
|
211
211
|
expect(request.server).to eq("https://foo")
|
212
212
|
end
|
213
213
|
|
214
|
-
context "if
|
214
|
+
context "if there is no access token" do
|
215
215
|
let(:args) { {"a" => "b"} }
|
216
216
|
|
217
|
+
it "uses https" do
|
218
|
+
expect(request.server).to eq("https://graph.facebook.com")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "if options[:use_ssl] is false" do
|
223
|
+
let(:options) { {use_ssl: false} }
|
224
|
+
|
217
225
|
it "uses http" do
|
218
226
|
expect(request.server).to eq("http://graph.facebook.com")
|
219
227
|
end
|
@@ -39,8 +39,7 @@ describe Koala::HTTPService do
|
|
39
39
|
|
40
40
|
it "adds the right default middleware" do
|
41
41
|
Koala::HTTPService::DEFAULT_MIDDLEWARE.call(builder)
|
42
|
-
expect(builder.requests).to eq([:url_encoded])
|
43
|
-
expect(builder.uses).to eq([Koala::HTTPService::MultipartRequest])
|
42
|
+
expect(builder.requests).to eq([:multipart, :url_encoded])
|
44
43
|
expect(builder.adapters).to eq([Faraday.default_adapter])
|
45
44
|
end
|
46
45
|
end
|
@@ -194,18 +193,16 @@ describe Koala::HTTPService do
|
|
194
193
|
|
195
194
|
it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
|
196
195
|
block = Proc.new { |builder|
|
197
|
-
builder.
|
196
|
+
builder.request :multipart
|
198
197
|
builder.request :url_encoded
|
199
|
-
builder.use Koala::HTTPService::MultipartRequest
|
200
198
|
}
|
201
199
|
stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
|
202
200
|
allow(Koala::HTTPService).to receive(:faraday_middleware).and_return(nil)
|
203
201
|
|
204
202
|
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
205
203
|
expect(instance.builder.handlers).to eq([
|
206
|
-
|
204
|
+
Faraday::Multipart::Middleware,
|
207
205
|
Faraday::Request::UrlEncoded,
|
208
|
-
Koala::HTTPService::MultipartRequest
|
209
206
|
])
|
210
207
|
mock_http_response
|
211
208
|
end
|
@@ -215,17 +212,15 @@ describe Koala::HTTPService do
|
|
215
212
|
|
216
213
|
it "uses the defined HTTPService.faraday_middleware block if defined" do
|
217
214
|
block = Proc.new { |builder|
|
218
|
-
builder.
|
215
|
+
builder.request :multipart
|
219
216
|
builder.request :url_encoded
|
220
|
-
builder.use Koala::HTTPService::MultipartRequest
|
221
217
|
}
|
222
218
|
expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
|
223
219
|
|
224
220
|
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
225
221
|
expect(instance.builder.handlers).to eq([
|
226
|
-
|
222
|
+
Faraday::Multipart::Middleware,
|
227
223
|
Faraday::Request::UrlEncoded,
|
228
|
-
Koala::HTTPService::MultipartRequest
|
229
224
|
])
|
230
225
|
mock_http_response
|
231
226
|
end
|
data/spec/support/koala_test.rb
CHANGED
@@ -238,11 +238,11 @@ module KoalaTest
|
|
238
238
|
# JRuby doesn't support typhoeus on Travis
|
239
239
|
unless defined? JRUBY_VERSION
|
240
240
|
require adapter
|
241
|
-
require
|
241
|
+
require "faraday/#{adapter}"
|
242
242
|
Faraday.default_adapter = adapter.to_sym
|
243
243
|
end
|
244
|
-
rescue
|
245
|
-
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}"
|
246
246
|
ensure
|
247
247
|
@adapter_activation_attempted = true
|
248
248
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.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-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
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
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-multipart
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
25
32
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: addressable
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +115,6 @@ files:
|
|
101
115
|
- lib/koala/configuration.rb
|
102
116
|
- lib/koala/errors.rb
|
103
117
|
- lib/koala/http_service.rb
|
104
|
-
- lib/koala/http_service/multipart_request.rb
|
105
118
|
- lib/koala/http_service/request.rb
|
106
119
|
- lib/koala/http_service/response.rb
|
107
120
|
- lib/koala/http_service/uploadable_io.rb
|
@@ -123,7 +136,6 @@ files:
|
|
123
136
|
- spec/cases/http_service_spec.rb
|
124
137
|
- spec/cases/koala_spec.rb
|
125
138
|
- spec/cases/koala_test_spec.rb
|
126
|
-
- spec/cases/multipart_request_spec.rb
|
127
139
|
- spec/cases/oauth_spec.rb
|
128
140
|
- spec/cases/realtime_updates_spec.rb
|
129
141
|
- spec/cases/test_users_spec.rb
|
@@ -165,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
177
|
- !ruby/object:Gem::Version
|
166
178
|
version: '0'
|
167
179
|
requirements: []
|
168
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.2.32
|
169
181
|
signing_key:
|
170
182
|
specification_version: 4
|
171
183
|
summary: A lightweight, flexible library for Facebook with support for the Graph API,
|
@@ -1,37 +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
|
-
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
|