koala 3.2.0 → 3.3.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 +16 -0
- data/koala.gemspec +2 -1
- 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_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: f3709b2644f9f0259e68e181d629754ffe3ba0213322cfb3bad0d369ad04543c
|
4
|
+
data.tar.gz: 7c3e3760d2ee7958b199713c7308f291552ee80a7badddc9ea9434a71cb024a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a22e1b9de96408d3273816150d5e0d55768f72b8b48a93ea276b7d2dc5d35f45de38cb8aad847345faf9c6997d7d0f19d21f177882cfb024e472e8681c9bbd2d
|
7
|
+
data.tar.gz: 5d66a1c10d8bd3d8153eb8faa02ee7ae901aae7321141d12f39abaeb33b6193cea2e3c7215b813942b714965d6048abda867f1d269de39dbdfc0bc137f3a0dc6
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
data/changelog.md
CHANGED
@@ -15,6 +15,22 @@ Testing improvements:
|
|
15
15
|
|
16
16
|
Others:
|
17
17
|
|
18
|
+
v3.3.0 (2022-09-27)
|
19
|
+
======
|
20
|
+
|
21
|
+
Updated features:
|
22
|
+
|
23
|
+
* Removed restriction on faraday < 2 ([#666](https://github.com/arsduo/koala/pull/666))
|
24
|
+
|
25
|
+
Internal improvements:
|
26
|
+
|
27
|
+
* Remove multipart hack and use default faraday multipart middleware ([#664](https://github.com/arsduo/koala/pull/664))
|
28
|
+
|
29
|
+
Testing improvements:
|
30
|
+
|
31
|
+
* Fix tests with ruby-head ([#674](https://github.com/arsduo/koala/pull/674))
|
32
|
+
* Keep supported rubies (non EOL) for CI ([#675](https://github.com/arsduo/koala/pull/675))
|
33
|
+
|
18
34
|
v3.2.0 (2022-05-27)
|
19
35
|
======
|
20
36
|
|
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")
|
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
|
|
@@ -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.3.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: 2022-
|
11
|
+
date: 2022-09-27 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.0.
|
180
|
+
rubygems_version: 3.4.0.dev
|
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
|