koala 3.5.0 → 3.6.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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +3 -3
- data/changelog.md +18 -0
- data/koala.gemspec +1 -0
- data/lib/koala/api/graph_batch_api.rb +21 -8
- data/lib/koala/errors.rb +4 -2
- data/lib/koala/version.rb +1 -1
- data/spec/cases/error_spec.rb +4 -2
- data/spec/cases/graph_api_batch_spec.rb +68 -11
- data/spec/cases/graph_error_checker_spec.rb +4 -2
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27591b64021ee915c13d9bcea2763739c2c86ce04d961dd5b540d964515a9905
|
4
|
+
data.tar.gz: 4a8c184674f681b193a3686b4eeb0023da0c00765d60be9694af9098014dacfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e4a3d670c3524211d438b8b67713f3f27cc0638aee6660b544b8b3b83a99397546a96ae826c6d613a1b6799184894c816b95008dc6083689f866357ae7ae13
|
7
|
+
data.tar.gz: 7a135a41f63d84e7e4f6c68632574eb19140aaf32ea9d9220bb2aaa4c79c50097c7ee1c957f7e9740d6b2c1141b5d24ebffdb47edd510c28bd7590f3cc09bf4f
|
data/.github/workflows/test.yml
CHANGED
@@ -10,11 +10,11 @@ jobs:
|
|
10
10
|
strategy:
|
11
11
|
fail-fast: false
|
12
12
|
matrix:
|
13
|
-
ruby: [2.7, "3.0", 3.1, head]
|
13
|
+
ruby: [2.7, "3.0", 3.1, 3.2, 3.3, head]
|
14
14
|
|
15
15
|
steps:
|
16
16
|
- name: Checkout repository
|
17
|
-
uses: actions/checkout@
|
17
|
+
uses: actions/checkout@v4
|
18
18
|
|
19
19
|
- name: Set up Ruby
|
20
20
|
uses: ruby/setup-ruby@v1
|
@@ -25,7 +25,7 @@ jobs:
|
|
25
25
|
run: bundle install --jobs 4 --retry 3
|
26
26
|
|
27
27
|
- name: Specs & Coverage
|
28
|
-
uses: paambaati/codeclimate-action@
|
28
|
+
uses: paambaati/codeclimate-action@v6
|
29
29
|
env:
|
30
30
|
CC_TEST_REPORTER_ID: 7af99d9225b4c14640f9ec3cb2e24d2f7103ac49417b0bd989188fb6c25f2909
|
31
31
|
with:
|
data/changelog.md
CHANGED
@@ -15,6 +15,24 @@ Testing improvements:
|
|
15
15
|
|
16
16
|
Others:
|
17
17
|
|
18
|
+
v3.6.0 (2024-06-27)
|
19
|
+
==========
|
20
|
+
|
21
|
+
Updated features:
|
22
|
+
|
23
|
+
* Add fbtrace_id, x-fb-rev, x-fb-debug to error messages and error class ([#668](https://github.com/arsduo/koala/pull/686))
|
24
|
+
* Handles the invalid JSON response from Facebook when the request's http_options[:http_component] is set to ':response' ([#689](https://github.com/arsduo/koala/pull/689))
|
25
|
+
|
26
|
+
Internal improvements:
|
27
|
+
|
28
|
+
* Require base64 for ruby 3.4 support ([#688](https://github.com/arsduo/koala/pull/688))
|
29
|
+
|
30
|
+
Testing improvements:
|
31
|
+
|
32
|
+
* Fix CI for ruby 3.4 ([#688](https://github.com/arsduo/koala/pull/688))
|
33
|
+
* Add latest rubies to CI ([#687](https://github.com/arsduo/koala/pull/687))
|
34
|
+
* Bump GHA action plugins to avoid deprecation warnings ([#689](https://github.com/arsduo/koala/pull/689))
|
35
|
+
|
18
36
|
v3.5.0 (2023-08-23)
|
19
37
|
======
|
20
38
|
|
data/koala.gemspec
CHANGED
@@ -53,7 +53,16 @@ module Koala
|
|
53
53
|
end
|
54
54
|
|
55
55
|
original_api.graph_call("/", args, "post", http_options) do |response|
|
56
|
-
raise bad_response if response.nil?
|
56
|
+
raise bad_response('Facebook returned an empty body') if response.nil?
|
57
|
+
|
58
|
+
# when http_component is set we receive Koala::Http_service response object
|
59
|
+
# from graph_call so this needs to be parsed
|
60
|
+
# as generate_results method handles only JSON response
|
61
|
+
if http_options[:http_component] && http_options[:http_component] == :response
|
62
|
+
response = json_body(response.body)
|
63
|
+
|
64
|
+
raise bad_response('Facebook returned an invalid body') unless response.is_a?(Array)
|
65
|
+
end
|
57
66
|
|
58
67
|
batch_results += generate_results(response, batch)
|
59
68
|
end
|
@@ -81,9 +90,9 @@ module Koala
|
|
81
90
|
end
|
82
91
|
end
|
83
92
|
|
84
|
-
def bad_response
|
93
|
+
def bad_response(message)
|
85
94
|
# Facebook sometimes reportedly returns an empty body at times
|
86
|
-
BadFacebookResponse.new(200,
|
95
|
+
BadFacebookResponse.new(200, '', message)
|
87
96
|
end
|
88
97
|
|
89
98
|
def result_from_response(response, options)
|
@@ -123,14 +132,17 @@ module Koala
|
|
123
132
|
JSON.dump calls
|
124
133
|
end
|
125
134
|
|
126
|
-
def json_body(
|
127
|
-
|
128
|
-
|
129
|
-
JSON.parse(
|
135
|
+
def json_body(body)
|
136
|
+
return if body.nil?
|
137
|
+
|
138
|
+
JSON.parse(body)
|
139
|
+
rescue JSON::ParserError => e
|
140
|
+
Koala::Utils.logger.error("#{e.class}: #{e.message} while parsing #{body}")
|
141
|
+
nil
|
130
142
|
end
|
131
143
|
|
132
144
|
def desired_component(component:, response:, headers:)
|
133
|
-
result = Koala::HTTPService::Response.new(response['
|
145
|
+
result = Koala::HTTPService::Response.new(response['code'], response['body'], headers)
|
134
146
|
|
135
147
|
# Get the HTTP component they want
|
136
148
|
case component
|
@@ -138,6 +150,7 @@ module Koala
|
|
138
150
|
# facebook returns the headers as an array of k/v pairs, but we want a regular hash
|
139
151
|
when :headers then headers
|
140
152
|
# (see note in regular api method about JSON parsing)
|
153
|
+
when :response then result
|
141
154
|
else GraphCollection.evaluate(result, original_api)
|
142
155
|
end
|
143
156
|
end
|
data/lib/koala/errors.rb
CHANGED
@@ -22,6 +22,7 @@ module Koala
|
|
22
22
|
:fb_error_user_msg,
|
23
23
|
:fb_error_user_title,
|
24
24
|
:fb_error_trace_id,
|
25
|
+
:fb_error_debug_trace_id,
|
25
26
|
:fb_error_debug,
|
26
27
|
:fb_error_rev,
|
27
28
|
:fb_buc_usage,
|
@@ -65,8 +66,9 @@ module Koala
|
|
65
66
|
self.fb_error_message = error_info["message"]
|
66
67
|
self.fb_error_user_msg = error_info["error_user_msg"]
|
67
68
|
self.fb_error_user_title = error_info["error_user_title"]
|
69
|
+
self.fb_error_trace_id = error_info["fbtrace_id"]
|
68
70
|
|
69
|
-
self.
|
71
|
+
self.fb_error_debug_trace_id = error_info["x-fb-trace-id"]
|
70
72
|
self.fb_error_debug = error_info["x-fb-debug"]
|
71
73
|
self.fb_error_rev = error_info["x-fb-rev"]
|
72
74
|
self.fb_buc_usage = json_parse_for(error_info, "x-business-use-case-usage")
|
@@ -74,7 +76,7 @@ module Koala
|
|
74
76
|
self.fb_app_usage = json_parse_for(error_info, "x-app-usage")
|
75
77
|
|
76
78
|
error_array = []
|
77
|
-
%w(type code error_subcode message error_user_title error_user_msg x-fb-trace-id).each do |key|
|
79
|
+
%w(type code error_subcode message error_user_title error_user_msg fbtrace_id x-fb-trace-id x-fb-debug x-fb-rev).each do |key|
|
78
80
|
error_array << "#{key}: #{error_info[key]}" if error_info[key]
|
79
81
|
end
|
80
82
|
|
data/lib/koala/version.rb
CHANGED
data/spec/cases/error_spec.rb
CHANGED
@@ -34,7 +34,8 @@ describe Koala::Facebook::APIError do
|
|
34
34
|
'error_subcode' => 'subcode',
|
35
35
|
'error_user_msg' => 'error user message',
|
36
36
|
'error_user_title' => 'error user title',
|
37
|
-
'
|
37
|
+
'fbtrace_id' => 'fb trace id',
|
38
|
+
'x-fb-trace-id' => 'x-fb trace id',
|
38
39
|
'x-fb-debug' => 'fb debug token',
|
39
40
|
'x-fb-rev' => 'fb revision',
|
40
41
|
'x-business-use-case-usage' => BUC_USAGE_JSON,
|
@@ -52,6 +53,7 @@ describe Koala::Facebook::APIError do
|
|
52
53
|
:fb_error_user_msg => 'error user message',
|
53
54
|
:fb_error_user_title => 'error user title',
|
54
55
|
:fb_error_trace_id => 'fb trace id',
|
56
|
+
:fb_error_debug_trace_id => 'x-fb trace id',
|
55
57
|
:fb_error_debug => 'fb debug token',
|
56
58
|
:fb_error_rev => 'fb revision',
|
57
59
|
:fb_buc_usage => JSON.parse(BUC_USAGE_JSON),
|
@@ -64,7 +66,7 @@ describe Koala::Facebook::APIError do
|
|
64
66
|
end
|
65
67
|
|
66
68
|
it "sets the error message appropriately" do
|
67
|
-
expect(error.message).to eq("type: type, code: 1, error_subcode: subcode, message: message, error_user_title: error user title, error_user_msg: error user message, x-fb-trace-id: fb trace id [HTTP 400]")
|
69
|
+
expect(error.message).to eq("type: type, code: 1, error_subcode: subcode, message: message, error_user_title: error user title, error_user_msg: error user message, fbtrace_id: fb trace id, x-fb-trace-id: x-fb trace id, x-fb-debug: fb debug token, x-fb-rev: fb revision [HTTP 400]")
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -383,28 +383,85 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
383
383
|
end
|
384
384
|
end
|
385
385
|
|
386
|
-
describe
|
387
|
-
|
386
|
+
describe 'processing the request' do
|
387
|
+
let(:response_status) { 203 }
|
388
|
+
let(:response_body) { '{\"id\":\"1234\"}'.gsub('\\', '') }
|
389
|
+
let(:response_headers) { { 'Content-Type' => 'text/javascript; charset=UTF-8' } }
|
390
|
+
|
391
|
+
it 'returns the result headers as a hash if http_component is headers' do
|
388
392
|
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
389
393
|
result = @api.batch do |batch_api|
|
390
394
|
batch_api.get_object(KoalaTest.user1, {}, :http_component => :headers)
|
391
395
|
end
|
392
|
-
expect(
|
396
|
+
expect(response_headers).to eq(result[0])
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'returns the complete response if http_component is response' do
|
400
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
401
|
+
result = @api.batch do |batch_api|
|
402
|
+
batch_api.get_object(KoalaTest.user1, {}, :http_component => :response)
|
403
|
+
end
|
404
|
+
|
405
|
+
expect(response_status).to eq(result[0].status)
|
406
|
+
expect(response_body).to eq(result[0].body)
|
407
|
+
expect(response_headers).to eq(result[0].headers)
|
393
408
|
end
|
394
409
|
|
395
|
-
describe
|
396
|
-
it
|
397
|
-
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500,
|
410
|
+
describe 'if it errors' do
|
411
|
+
it 'raises an APIError if the response is not 200' do
|
412
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, '[]', {}))
|
398
413
|
expect {
|
399
|
-
Koala::Facebook::API.new(
|
414
|
+
Koala::Facebook::API.new('foo').batch { |batch_api| batch_api.get_object('me') }
|
400
415
|
}.to raise_exception(Koala::Facebook::APIError)
|
401
416
|
end
|
402
417
|
|
403
|
-
it
|
404
|
-
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200,
|
418
|
+
it 'raises a BadFacebookResponse if the body is empty' do
|
419
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '', {}))
|
405
420
|
expect {
|
406
|
-
Koala::Facebook::API.new(
|
407
|
-
}.to raise_exception(Koala::Facebook::BadFacebookResponse)
|
421
|
+
Koala::Facebook::API.new('foo').batch { |batch_api| batch_api.get_object('me') }
|
422
|
+
}.to raise_exception(Koala::Facebook::BadFacebookResponse, /Facebook returned an empty body \[HTTP 200\]/)
|
423
|
+
end
|
424
|
+
|
425
|
+
describe 'handle invalid body errors' do
|
426
|
+
describe 'with http_component set to :response' do
|
427
|
+
it 'raises a BadFacebookResponse if the body is non-empty, non-array' do
|
428
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '200', {}))
|
429
|
+
expect {
|
430
|
+
Koala::Facebook::API.new('foo').batch(http_component: :response) do |batch_api|
|
431
|
+
batch_api.get_object('me')
|
432
|
+
end
|
433
|
+
}.to raise_exception(Koala::Facebook::BadFacebookResponse, /Facebook returned an invalid body \[HTTP 200\]/)
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'raises a BadFacebookResponse if the body is invalid JSON' do
|
437
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"\"id\":\1234\"}"}', {}))
|
438
|
+
expect {
|
439
|
+
Koala::Facebook::API.new('foo').batch(http_component: :response) do |batch_api|
|
440
|
+
batch_api.get_object('me')
|
441
|
+
end
|
442
|
+
}.to raise_exception(Koala::Facebook::BadFacebookResponse, /Facebook returned an invalid body \[HTTP 200\]/)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
%i[headers status].each do |component|
|
447
|
+
describe "with http_component set to #{component}" do
|
448
|
+
it 'should not raise a BadFacebookResponse if the body is non-empty, non-array' do
|
449
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '200', {}))
|
450
|
+
expect {
|
451
|
+
Koala::Facebook::API.new('foo').batch(http_component: component) { |batch_api| batch_api.get_object('me') }
|
452
|
+
}.not_to raise_exception(Koala::Facebook::BadFacebookResponse, /Facebook returned an invalid body \[HTTP 200\]/)
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'should not raise a BadFacebookResponse if the body is invalid JSON' do
|
456
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"\"id\":\1234\"}"}', {}))
|
457
|
+
expect {
|
458
|
+
Koala::Facebook::API.new('foo').batch(http_component: component) do |batch_api|
|
459
|
+
batch_api.get_object('me')
|
460
|
+
end
|
461
|
+
}.not_to raise_exception(Koala::Facebook::BadFacebookResponse, /Facebook returned an invalid body \[HTTP 200\]/)
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
408
465
|
end
|
409
466
|
|
410
467
|
context "with error info" do
|
@@ -76,10 +76,12 @@ module Koala
|
|
76
76
|
"error_subcode" => "FB error subcode",
|
77
77
|
"message" => "An error occurred!",
|
78
78
|
"error_user_msg" => "A user msg",
|
79
|
-
"error_user_title" => "usr title"
|
79
|
+
"error_user_title" => "usr title",
|
80
|
+
"fbtrace_id" => "fbtrace_id"
|
80
81
|
}
|
81
82
|
body.replace({"error" => error_data}.to_json)
|
82
83
|
|
84
|
+
expect(error.fb_error_trace_id).to eq(error_data["fbtrace_id"])
|
83
85
|
expect(error.fb_error_type).to eq(error_data["type"])
|
84
86
|
expect(error.fb_error_code).to eq(error_data["code"])
|
85
87
|
expect(error.fb_error_subcode).to eq(error_data["error_subcode"])
|
@@ -97,7 +99,7 @@ module Koala
|
|
97
99
|
"x-ad-account-usage" => { 'c' => 3, 'd' => 4 }.to_json,
|
98
100
|
"x-app-usage" => { 'e' => 5, 'f' => 6 }.to_json
|
99
101
|
)
|
100
|
-
expect(error.
|
102
|
+
expect(error.fb_error_debug_trace_id).to eq(headers["x-fb-trace-id"])
|
101
103
|
expect(error.fb_error_debug).to eq(headers["x-fb-debug"])
|
102
104
|
expect(error.fb_error_rev).to eq(headers["x-fb-rev"])
|
103
105
|
expect(error.fb_buc_usage).to eq({ 'a' => 1, 'b' => 2 })
|
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: 3.
|
4
|
+
version: 3.6.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: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: base64
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
|
84
98
|
access to the social graph via the Graph and REST APIs, as well as support for realtime
|
85
99
|
updates and OAuth and Facebook Connect authentication. Koala is fully tested and
|
@@ -177,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
191
|
- !ruby/object:Gem::Version
|
178
192
|
version: '0'
|
179
193
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
194
|
+
rubygems_version: 3.3.26
|
181
195
|
signing_key:
|
182
196
|
specification_version: 4
|
183
197
|
summary: A lightweight, flexible library for Facebook with support for the Graph API,
|