tinify 1.6.0 → 1.7.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/ci-cd.yaml +7 -10
- data/CHANGES.md +15 -0
- data/Gemfile +4 -6
- data/Gemfile.lock +29 -17
- data/lib/tinify/version.rb +1 -1
- data/test/helper.rb +7 -5
- data/test/tinify_client_test.rb +89 -54
- data/test/tinify_source_test.rb +67 -37
- data/test/tinify_test.rb +52 -34
- data/tinify.gemspec +1 -1
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6947ac2a5fe37cabbd10fcafeb6e762fc15a19c637f6f617b5179b7057ecb2c4
|
4
|
+
data.tar.gz: 2b8964ae5761665b4400f83008a4a43bf795ce6e0c60e3d8a9f02f11e3505a58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 473ff8623d4142617493e00c2f0d1a2e06ea9342ceccdd07794df8113e378c3b583c1a3a98d4d22d558003ba1c65d7fdc668e592cbd7b2710830185dbbe3914e
|
7
|
+
data.tar.gz: ee5ef195846f70e996576295c7f06c2403d77ddb8d03984162baf4b8b29622f86f62ef93be1d29943d0f50355ef89cc00b3db70ee63513d5ca7e4cf777ec8316
|
@@ -11,10 +11,7 @@ jobs:
|
|
11
11
|
strategy:
|
12
12
|
fail-fast: false
|
13
13
|
matrix:
|
14
|
-
ruby-version: [
|
15
|
-
'2.6', '2.7', '3.0', '3.1',
|
16
|
-
jruby,
|
17
|
-
]
|
14
|
+
ruby-version: ['3.1', '3.2', '3.3', '3.4', 'jruby']
|
18
15
|
os: [ubuntu-latest, macOS-latest, windows-latest]
|
19
16
|
# experimental: [false]
|
20
17
|
include:
|
@@ -30,7 +27,7 @@ jobs:
|
|
30
27
|
os: ubuntu-latest
|
31
28
|
experimental: false
|
32
29
|
steps:
|
33
|
-
- uses: actions/checkout@
|
30
|
+
- uses: actions/checkout@v4
|
34
31
|
|
35
32
|
- name: Set up ruby ${{ matrix.ruby-version }}
|
36
33
|
uses: ruby/setup-ruby@v1
|
@@ -53,7 +50,7 @@ jobs:
|
|
53
50
|
fail-fast: false
|
54
51
|
matrix:
|
55
52
|
ruby-version: [
|
56
|
-
"
|
53
|
+
"3.1", "3.4"
|
57
54
|
]
|
58
55
|
os: [
|
59
56
|
ubuntu-latest,
|
@@ -62,9 +59,9 @@ jobs:
|
|
62
59
|
# windows-latest
|
63
60
|
]
|
64
61
|
steps:
|
65
|
-
- uses: actions/checkout@
|
62
|
+
- uses: actions/checkout@v4
|
66
63
|
- name: Set up ruby ${{ matrix.ruby-version }}
|
67
|
-
uses:
|
64
|
+
uses: ruby/setup-ruby@v1
|
68
65
|
with:
|
69
66
|
ruby-version: ${{ matrix.ruby-version }}
|
70
67
|
bundler-cache: true
|
@@ -86,10 +83,10 @@ jobs:
|
|
86
83
|
runs-on: ubuntu-latest
|
87
84
|
steps:
|
88
85
|
- uses: actions/checkout@v3
|
89
|
-
- name: Set up Ruby
|
86
|
+
- name: Set up Ruby 3.4
|
90
87
|
uses: ruby/setup-ruby@v1
|
91
88
|
with:
|
92
|
-
ruby-version:
|
89
|
+
ruby-version: 3.4
|
93
90
|
- name: Check if properly tagged
|
94
91
|
run: |
|
95
92
|
PACKAGE_VERSION="$(ruby -e 'puts Gem::Specification::load("tinify.gemspec").version')";
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 1.7.0
|
2
|
+
|
3
|
+
* Added base64 gem to Gemfile
|
4
|
+
|
5
|
+
Extend runtime support for:
|
6
|
+
|
7
|
+
* Ruby 3.2
|
8
|
+
* Ruby 3.3
|
9
|
+
* Ruby 3.4
|
10
|
+
|
11
|
+
Remove runtime support for:
|
12
|
+
|
13
|
+
* Ruby 2.6
|
14
|
+
* Ruby 3.0
|
15
|
+
|
1
16
|
## 1.6.0
|
2
17
|
|
3
18
|
Added transform & convert methods for the Tinify API.
|
data/Gemfile
CHANGED
@@ -3,9 +3,7 @@ source "https://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in tinify.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem '
|
8
|
-
|
9
|
-
|
10
|
-
# refactor.
|
11
|
-
gem 'webmock', '~> 1.23.0'
|
6
|
+
gem 'base64'
|
7
|
+
gem 'rake'
|
8
|
+
gem 'minitest'
|
9
|
+
gem 'webmock'
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tinify (1.
|
5
|
-
httpclient (
|
4
|
+
tinify (1.7.0)
|
5
|
+
httpclient (>= 2.9, < 3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.8.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
|
10
|
+
addressable (2.8.7)
|
11
|
+
public_suffix (>= 2.0.2, < 7.0)
|
12
|
+
base64 (0.2.0)
|
13
|
+
bigdecimal (3.1.9)
|
14
|
+
bigdecimal (3.1.9-java)
|
15
|
+
crack (1.0.0)
|
16
|
+
bigdecimal
|
13
17
|
rexml
|
14
|
-
hashdiff (
|
15
|
-
httpclient (2.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
hashdiff (1.1.2)
|
19
|
+
httpclient (2.9.0)
|
20
|
+
mutex_m
|
21
|
+
minitest (5.25.5)
|
22
|
+
mutex_m (0.3.0)
|
23
|
+
public_suffix (6.0.1)
|
24
|
+
rake (13.2.1)
|
25
|
+
rexml (3.4.1)
|
26
|
+
webmock (3.25.1)
|
27
|
+
addressable (>= 2.8.0)
|
22
28
|
crack (>= 0.3.2)
|
23
|
-
hashdiff
|
29
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
24
30
|
|
25
31
|
PLATFORMS
|
32
|
+
arm64-darwin
|
33
|
+
java
|
26
34
|
ruby
|
35
|
+
x64-mingw-ucrt
|
36
|
+
x86_64-darwin
|
37
|
+
x86_64-linux
|
27
38
|
|
28
39
|
DEPENDENCIES
|
29
|
-
|
30
|
-
|
40
|
+
base64
|
41
|
+
minitest
|
42
|
+
rake
|
31
43
|
tinify!
|
32
|
-
webmock
|
44
|
+
webmock
|
33
45
|
|
34
46
|
BUNDLED WITH
|
35
47
|
2.3.19
|
data/lib/tinify/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "bundler/setup"
|
2
|
-
require
|
2
|
+
Bundler.require
|
3
3
|
|
4
|
+
require "minitest/autorun"
|
4
5
|
require "webmock/minitest"
|
6
|
+
require "tinify"
|
5
7
|
|
6
8
|
WebMock.disable_net_connect!(allow_localhost: true)
|
7
9
|
|
8
|
-
require "tinify"
|
9
|
-
|
10
10
|
module TestHelpers
|
11
11
|
def before_setup
|
12
12
|
Tinify.key = nil
|
@@ -28,6 +28,8 @@ module TestHelpers
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
module Minitest
|
32
|
+
class Spec
|
33
|
+
include TestHelpers
|
34
|
+
end
|
33
35
|
end
|
data/test/tinify_client_test.rb
CHANGED
@@ -11,33 +11,38 @@ describe Tinify::Client do
|
|
11
11
|
describe "request" do
|
12
12
|
describe "when valid" do
|
13
13
|
before do
|
14
|
-
stub_request(:get, "https://api
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
stub_request(:get, "https://api.tinify.com")
|
15
|
+
.with(basic_auth: ['api', 'key'])
|
16
|
+
.to_return(
|
17
|
+
status: 201,
|
18
|
+
headers: { "Compression-Count" => "12" }
|
19
|
+
)
|
20
|
+
|
21
|
+
stub_request(:get, "https://api.tinify.com/shrink")
|
22
|
+
.with(basic_auth: ['api', 'key'])
|
23
|
+
.to_return(
|
24
|
+
status: 201,
|
25
|
+
headers: {
|
26
|
+
"Compression-Count" => "12",
|
27
|
+
"Location" => "https://api.tinify.com/output/3spbi1cd7rs812lb.png"
|
28
|
+
}
|
29
|
+
)
|
25
30
|
end
|
26
31
|
|
27
32
|
it "should issue request" do
|
28
33
|
subject.request(:get, "/")
|
29
|
-
assert_requested :get, "https://api
|
30
|
-
headers: { "Authorization" => "Basic
|
34
|
+
assert_requested :get, "https://api.tinify.com",
|
35
|
+
headers: { "Authorization" => "Basic #{ Base64.strict_encode64('api:key').chomp}" }
|
31
36
|
end
|
32
37
|
|
33
38
|
it "should issue request to endpoint" do
|
34
39
|
subject.request(:get, "/shrink", {})
|
35
|
-
assert_requested :get, "https://api
|
40
|
+
assert_requested :get, "https://api.tinify.com/shrink"
|
36
41
|
end
|
37
42
|
|
38
43
|
it "should issue request with method" do
|
39
44
|
subject.request(:get, "/shrink", {})
|
40
|
-
assert_requested :get, "https://api
|
45
|
+
assert_requested :get, "https://api.tinify.com/shrink"
|
41
46
|
end
|
42
47
|
|
43
48
|
it "should return response" do
|
@@ -47,25 +52,25 @@ describe Tinify::Client do
|
|
47
52
|
|
48
53
|
it "should issue request without body when options are empty" do
|
49
54
|
subject.request(:get, "/", {})
|
50
|
-
assert_requested :get, "https://api
|
55
|
+
assert_requested :get, "https://api.tinify.com", body: nil
|
51
56
|
end
|
52
57
|
|
53
58
|
it "should issue request without content type when options are empty" do
|
54
59
|
subject.request(:get, "/", {})
|
55
|
-
assert_not_requested :get, "https://api
|
60
|
+
assert_not_requested :get, "https://api.tinify.com",
|
56
61
|
headers: { "Content-Type" => "application/x-www-form-urlencoded" }
|
57
62
|
end
|
58
63
|
|
59
64
|
it "should issue request with json body" do
|
60
65
|
subject.request(:get, "/", { hello: "world" })
|
61
|
-
assert_requested :get, "https://api
|
66
|
+
assert_requested :get, "https://api.tinify.com",
|
62
67
|
headers: { "Content-Type" => "application/json" },
|
63
68
|
body: '{"hello":"world"}'
|
64
69
|
end
|
65
70
|
|
66
71
|
it "should issue request with user agent" do
|
67
72
|
subject.request(:get, "/")
|
68
|
-
assert_requested :get, "https://api
|
73
|
+
assert_requested :get, "https://api.tinify.com",
|
69
74
|
headers: { "User-Agent" => Tinify::Client::USER_AGENT }
|
70
75
|
end
|
71
76
|
|
@@ -81,7 +86,7 @@ describe Tinify::Client do
|
|
81
86
|
|
82
87
|
it "should issue request with user agent" do
|
83
88
|
subject.request(:get, "/")
|
84
|
-
assert_requested :get, "https://api
|
89
|
+
assert_requested :get, "https://api.tinify.com",
|
85
90
|
headers: { "User-Agent" => "#{Tinify::Client::USER_AGENT} TestApp/0.1" }
|
86
91
|
end
|
87
92
|
end
|
@@ -93,7 +98,7 @@ describe Tinify::Client do
|
|
93
98
|
|
94
99
|
it "should issue request with proxy authorization" do
|
95
100
|
subject.request(:get, "/")
|
96
|
-
assert_requested :get, "https://api
|
101
|
+
assert_requested :get, "https://api.tinify.com",
|
97
102
|
headers: { "Proxy-Authorization" => "Basic dXNlcjpwYXNz" }
|
98
103
|
end
|
99
104
|
end
|
@@ -101,8 +106,11 @@ describe Tinify::Client do
|
|
101
106
|
|
102
107
|
describe "with timeout once" do
|
103
108
|
before do
|
104
|
-
stub_request(:get, "https://api
|
105
|
-
.
|
109
|
+
stub_request(:get, "https://api.tinify.com")
|
110
|
+
.with(basic_auth: ['api', 'key'])
|
111
|
+
.to_timeout
|
112
|
+
.then
|
113
|
+
.to_return(status: 201)
|
106
114
|
end
|
107
115
|
|
108
116
|
it "should return response" do
|
@@ -113,7 +121,9 @@ describe Tinify::Client do
|
|
113
121
|
|
114
122
|
describe "with timeout repeatedly" do
|
115
123
|
before do
|
116
|
-
stub_request(:get, "https://api
|
124
|
+
stub_request(:get, "https://api.tinify.com")
|
125
|
+
.with(basic_auth: ['api', 'key'])
|
126
|
+
.to_timeout
|
117
127
|
end
|
118
128
|
|
119
129
|
it "should raise connection error" do
|
@@ -131,7 +141,8 @@ describe Tinify::Client do
|
|
131
141
|
|
132
142
|
describe "with socket error once" do
|
133
143
|
before do
|
134
|
-
stub_request(:get, "https://api
|
144
|
+
stub_request(:get, "https://api.tinify.com")
|
145
|
+
.with(basic_auth: ['api', 'key'])
|
135
146
|
.to_raise(SocketError.new("nodename nor servname provided"))
|
136
147
|
.then.to_return(status: 201)
|
137
148
|
end
|
@@ -144,7 +155,9 @@ describe Tinify::Client do
|
|
144
155
|
|
145
156
|
describe "with socket error repeatedly" do
|
146
157
|
before do
|
147
|
-
stub_request(:get, "https://api
|
158
|
+
stub_request(:get, "https://api.tinify.com")
|
159
|
+
.with(basic_auth: ['api', 'key'])
|
160
|
+
.to_raise(SocketError.new("nodename nor servname provided"))
|
148
161
|
end
|
149
162
|
|
150
163
|
it "should raise error" do
|
@@ -162,9 +175,11 @@ describe Tinify::Client do
|
|
162
175
|
|
163
176
|
describe "with unexpected error once" do
|
164
177
|
before do
|
165
|
-
stub_request(:get, "https://api
|
178
|
+
stub_request(:get, "https://api.tinify.com")
|
179
|
+
.with(basic_auth: ['api', 'key'])
|
166
180
|
.to_raise("some error")
|
167
|
-
.then
|
181
|
+
.then
|
182
|
+
.to_return(status: 201)
|
168
183
|
end
|
169
184
|
|
170
185
|
it "should return response" do
|
@@ -175,7 +190,9 @@ describe Tinify::Client do
|
|
175
190
|
|
176
191
|
describe "with unexpected error repeatedly" do
|
177
192
|
before do
|
178
|
-
stub_request(:get, "https://api
|
193
|
+
stub_request(:get, "https://api.tinify.com")
|
194
|
+
.with(basic_auth: ['api', 'key'])
|
195
|
+
.to_raise("some error")
|
179
196
|
end
|
180
197
|
|
181
198
|
it "should raise error" do
|
@@ -193,10 +210,14 @@ describe Tinify::Client do
|
|
193
210
|
|
194
211
|
describe "with server error once" do
|
195
212
|
before do
|
196
|
-
stub_request(:get, "https://api
|
197
|
-
|
198
|
-
|
199
|
-
|
213
|
+
stub_request(:get, "https://api.tinify.com")
|
214
|
+
.with(basic_auth: ['api', 'key'])
|
215
|
+
.to_return(
|
216
|
+
status: 584,
|
217
|
+
body: '{"error":"InternalServerError","message":"Oops!"}'
|
218
|
+
)
|
219
|
+
.then
|
220
|
+
.to_return(status: 201)
|
200
221
|
end
|
201
222
|
|
202
223
|
it "should return response" do
|
@@ -207,10 +228,12 @@ describe Tinify::Client do
|
|
207
228
|
|
208
229
|
describe "with server error repeatedly" do
|
209
230
|
before do
|
210
|
-
stub_request(:get, "https://api
|
211
|
-
|
212
|
-
|
213
|
-
|
231
|
+
stub_request(:get, "https://api.tinify.com")
|
232
|
+
.with(basic_auth: ['api', 'key'])
|
233
|
+
.to_return(
|
234
|
+
status: 584,
|
235
|
+
body: '{"error":"InternalServerError","message":"Oops!"}'
|
236
|
+
)
|
214
237
|
end
|
215
238
|
|
216
239
|
it "should raise server error" do
|
@@ -228,10 +251,14 @@ describe Tinify::Client do
|
|
228
251
|
|
229
252
|
describe "with bad server response once" do
|
230
253
|
before do
|
231
|
-
stub_request(:get, "https://api
|
232
|
-
|
233
|
-
|
234
|
-
|
254
|
+
stub_request(:get, "https://api.tinify.com")
|
255
|
+
.with(basic_auth: ['api', 'key'])
|
256
|
+
.to_return(
|
257
|
+
status: 543,
|
258
|
+
body: '<!-- this is not json -->'
|
259
|
+
)
|
260
|
+
.then
|
261
|
+
.to_return(status: 201)
|
235
262
|
end
|
236
263
|
|
237
264
|
it "should return response" do
|
@@ -242,10 +269,12 @@ describe Tinify::Client do
|
|
242
269
|
|
243
270
|
describe "with bad server response repeatedly" do
|
244
271
|
before do
|
245
|
-
stub_request(:get, "https://api
|
246
|
-
|
247
|
-
|
248
|
-
|
272
|
+
stub_request(:get, "https://api.tinify.com")
|
273
|
+
.with(basic_auth: ['api', 'key'])
|
274
|
+
.to_return(
|
275
|
+
status: 543,
|
276
|
+
body: '<!-- this is not json -->'
|
277
|
+
)
|
249
278
|
end
|
250
279
|
|
251
280
|
it "should raise server error" do
|
@@ -255,7 +284,7 @@ describe Tinify::Client do
|
|
255
284
|
end
|
256
285
|
|
257
286
|
it "should raise error with message" do
|
258
|
-
assert_raise_with_message
|
287
|
+
assert_raise_with_message(/\(HTTP 543\/ParseError\)/) do
|
259
288
|
subject.request(:get, "/")
|
260
289
|
end
|
261
290
|
end
|
@@ -263,10 +292,13 @@ describe Tinify::Client do
|
|
263
292
|
|
264
293
|
describe "with client error" do
|
265
294
|
before do
|
266
|
-
stub_request(:get, "https://api
|
267
|
-
|
268
|
-
|
269
|
-
|
295
|
+
stub_request(:get, "https://api.tinify.com")
|
296
|
+
.with(basic_auth: ['api', 'key'])
|
297
|
+
.to_return(
|
298
|
+
status: 492,
|
299
|
+
body: '{"error":"BadRequest","message":"Oops!"}'
|
300
|
+
).then
|
301
|
+
.to_return(status: 201)
|
270
302
|
end
|
271
303
|
|
272
304
|
it "should raise client error" do
|
@@ -285,10 +317,13 @@ describe Tinify::Client do
|
|
285
317
|
|
286
318
|
describe "with bad credentials" do
|
287
319
|
before do
|
288
|
-
stub_request(:get, "https://api
|
289
|
-
|
290
|
-
|
291
|
-
|
320
|
+
stub_request(:get, "https://api.tinify.com")
|
321
|
+
.with(basic_auth: ['api', 'key'])
|
322
|
+
.to_return(
|
323
|
+
status: 401,
|
324
|
+
body: '{"error":"Unauthorized","message":"Oops!"}'
|
325
|
+
).then
|
326
|
+
.to_return(status: 201)
|
292
327
|
end
|
293
328
|
|
294
329
|
it "should raise account error" do
|
data/test/tinify_source_test.rb
CHANGED
@@ -7,7 +7,8 @@ describe Tinify::Source do
|
|
7
7
|
before do
|
8
8
|
Tinify.key = "invalid"
|
9
9
|
|
10
|
-
stub_request(:post, "https://api
|
10
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
11
|
+
.with(basic_auth: ['api', 'invalid'])
|
11
12
|
.to_return(
|
12
13
|
status: 401,
|
13
14
|
body: '{"error":"Unauthorized","message":"Credentials are invalid"}')
|
@@ -45,13 +46,15 @@ describe Tinify::Source do
|
|
45
46
|
|
46
47
|
describe "from_file" do
|
47
48
|
before do
|
48
|
-
stub_request(:post, "https://api
|
49
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
50
|
+
.with(basic_auth: ['api', 'valid'])
|
49
51
|
.to_return(
|
50
52
|
status: 201,
|
51
53
|
headers: { Location: "https://api.tinify.com/some/location" },
|
52
54
|
body: '{}')
|
53
55
|
|
54
|
-
stub_request(:get, "https://api
|
56
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
57
|
+
.with(basic_auth: ['api', 'valid'])
|
55
58
|
.to_return(
|
56
59
|
status: 200,
|
57
60
|
body: "compressed file")
|
@@ -68,13 +71,15 @@ describe Tinify::Source do
|
|
68
71
|
|
69
72
|
describe "from_buffer" do
|
70
73
|
before do
|
71
|
-
stub_request(:post, "https://api
|
74
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
75
|
+
.with(basic_auth: ['api', 'valid'])
|
72
76
|
.to_return(
|
73
77
|
status: 201,
|
74
78
|
headers: { Location: "https://api.tinify.com/some/location" },
|
75
79
|
body: '{}')
|
76
80
|
|
77
|
-
stub_request(:get, "https://api
|
81
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
82
|
+
.with(basic_auth: ['api', 'valid'])
|
78
83
|
.to_return(
|
79
84
|
status: 200,
|
80
85
|
body: "compressed file")
|
@@ -91,20 +96,27 @@ describe Tinify::Source do
|
|
91
96
|
|
92
97
|
describe "from_url" do
|
93
98
|
before do
|
94
|
-
stub_request(:post, "https://api
|
95
|
-
.with(
|
99
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
100
|
+
.with(
|
101
|
+
basic_auth: ['api', 'valid'],
|
102
|
+
body: '{"source":{"url":"http://example.com/test.jpg"}}'
|
103
|
+
)
|
96
104
|
.to_return(
|
97
105
|
status: 201,
|
98
106
|
headers: { Location: "https://api.tinify.com/some/location" },
|
99
107
|
body: '{}')
|
100
108
|
|
101
|
-
stub_request(:post, "https://api
|
102
|
-
.with(
|
109
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
110
|
+
.with(
|
111
|
+
body: '{"source":{"url":"file://wrong"}}',
|
112
|
+
basic_auth: ['api', 'valid']
|
113
|
+
)
|
103
114
|
.to_return(
|
104
115
|
status: 400,
|
105
116
|
body: '{"error":"Source not found","message":"Cannot parse URL"}')
|
106
117
|
|
107
|
-
stub_request(:get, "https://api
|
118
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
119
|
+
.with(basic_auth: ['api', 'valid'])
|
108
120
|
.to_return(
|
109
121
|
status: 200,
|
110
122
|
body: "compressed file")
|
@@ -127,13 +139,15 @@ describe Tinify::Source do
|
|
127
139
|
|
128
140
|
describe "result" do
|
129
141
|
before do
|
130
|
-
stub_request(:post, "https://api
|
142
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
143
|
+
.with(basic_auth: ['api', 'valid'])
|
131
144
|
.to_return(
|
132
145
|
status: 201,
|
133
146
|
headers: { Location: "https://api.tinify.com/some/location" },
|
134
147
|
body: '{}')
|
135
148
|
|
136
|
-
stub_request(:get, "https://api
|
149
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
150
|
+
.with(basic_auth: ['api', 'valid'])
|
137
151
|
.to_return(
|
138
152
|
status: 200,
|
139
153
|
body: "compressed file")
|
@@ -146,14 +160,16 @@ describe Tinify::Source do
|
|
146
160
|
|
147
161
|
describe "preserve" do
|
148
162
|
before do
|
149
|
-
stub_request(:post, "https://api
|
163
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
164
|
+
.with(basic_auth: ['api', 'valid'])
|
150
165
|
.to_return(
|
151
166
|
status: 201,
|
152
167
|
headers: { Location: "https://api.tinify.com/some/location" },
|
153
168
|
body: '{}')
|
154
169
|
|
155
|
-
stub_request(:get, "https://api
|
170
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
156
171
|
.with(
|
172
|
+
basic_auth: ['api', 'valid'],
|
157
173
|
body: '{"preserve":["copyright","location"]}')
|
158
174
|
.to_return(
|
159
175
|
status: 200,
|
@@ -176,8 +192,9 @@ describe Tinify::Source do
|
|
176
192
|
end
|
177
193
|
|
178
194
|
it "should include other options if set" do
|
179
|
-
stub_request(:get, "https://api
|
195
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
180
196
|
.with(
|
197
|
+
basic_auth: ['api', 'valid'],
|
181
198
|
body: '{"resize":{"width":400},"preserve":["copyright","location"]}')
|
182
199
|
.to_return(
|
183
200
|
status: 200,
|
@@ -190,14 +207,16 @@ describe Tinify::Source do
|
|
190
207
|
|
191
208
|
describe "resize" do
|
192
209
|
before do
|
193
|
-
stub_request(:post, "https://api
|
210
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
211
|
+
.with(basic_auth: ['api', 'valid'])
|
194
212
|
.to_return(
|
195
213
|
status: 201,
|
196
214
|
headers: { Location: "https://api.tinify.com/some/location" },
|
197
215
|
body: '{}')
|
198
216
|
|
199
|
-
stub_request(:get, "https://api
|
217
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
200
218
|
.with(
|
219
|
+
basic_auth: ['api', 'valid'],
|
201
220
|
body: '{"resize":{"width":400}}')
|
202
221
|
.to_return(
|
203
222
|
status: 200,
|
@@ -215,14 +234,16 @@ describe Tinify::Source do
|
|
215
234
|
|
216
235
|
describe "convert" do
|
217
236
|
before do
|
218
|
-
stub_request(:post, "https://api
|
237
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
238
|
+
.with(basic_auth: ['api', 'valid'])
|
219
239
|
.to_return(
|
220
240
|
status: 201,
|
221
241
|
headers: { Location: "https://api.tinify.com/some/location" },
|
222
242
|
body: '{}')
|
223
243
|
|
224
|
-
stub_request(:get, "https://api
|
244
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
225
245
|
.with(
|
246
|
+
basic_auth: ['api', 'valid'],
|
226
247
|
body: '{"convert":{"type":["image/webp"]}}')
|
227
248
|
.to_return(
|
228
249
|
status: 200,
|
@@ -240,14 +261,16 @@ describe Tinify::Source do
|
|
240
261
|
|
241
262
|
describe "transform" do
|
242
263
|
before do
|
243
|
-
stub_request(:post, "https://api
|
264
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
265
|
+
.with(basic_auth: ['api', 'valid'])
|
244
266
|
.to_return(
|
245
267
|
status: 201,
|
246
268
|
headers: { Location: "https://api.tinify.com/some/location" },
|
247
269
|
body: '{}')
|
248
270
|
|
249
|
-
stub_request(:get, "https://api
|
271
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
250
272
|
.with(
|
273
|
+
basic_auth: ['api', 'valid'],
|
251
274
|
body: '{"transform":{"color":"black"}}')
|
252
275
|
.to_return(
|
253
276
|
status: 200,
|
@@ -264,7 +287,7 @@ describe Tinify::Source do
|
|
264
287
|
|
265
288
|
it "should include other options if set" do
|
266
289
|
|
267
|
-
stub_request(:get, "https://api
|
290
|
+
stub_request(:get, "https://api.tinify.com/some/location").
|
268
291
|
with(:body => '{"convert":{"type":["image/webp"]},"transform":{"color":"black"}}',
|
269
292
|
).
|
270
293
|
to_return(:status => 200, :body => "trans-formed-and-coded", :headers => {})
|
@@ -272,21 +295,21 @@ describe Tinify::Source do
|
|
272
295
|
result = Tinify::Source.from_buffer("png file").convert(type: ["image/webp"]).transform(color: "black")
|
273
296
|
assert_equal "trans-formed-and-coded", result.to_buffer
|
274
297
|
end
|
275
|
-
|
276
|
-
|
277
298
|
end
|
278
299
|
|
279
300
|
describe "store" do
|
280
301
|
before do
|
281
|
-
stub_request(:post, "https://api
|
302
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
303
|
+
.with(basic_auth: ['api', 'valid'])
|
282
304
|
.to_return(
|
283
305
|
status: 201,
|
284
306
|
headers: { Location: "https://api.tinify.com/some/location" },
|
285
307
|
body: '{}'
|
286
308
|
)
|
287
309
|
|
288
|
-
stub_request(:post, "https://api
|
310
|
+
stub_request(:post, "https://api.tinify.com/some/location")
|
289
311
|
.with(
|
312
|
+
basic_auth: ['api', 'valid'],
|
290
313
|
body: '{"store":{"service":"s3"}}')
|
291
314
|
.to_return(
|
292
315
|
status: 200,
|
@@ -303,8 +326,9 @@ describe Tinify::Source do
|
|
303
326
|
end
|
304
327
|
|
305
328
|
it "should include other options if set" do
|
306
|
-
stub_request(:post, "https://api
|
329
|
+
stub_request(:post, "https://api.tinify.com/some/location")
|
307
330
|
.with(
|
331
|
+
basic_auth: ['api', 'valid'],
|
308
332
|
body: '{"resize":{"width":400},"store":{"service":"s3"}}')
|
309
333
|
.to_return(
|
310
334
|
status: 200,
|
@@ -317,16 +341,19 @@ describe Tinify::Source do
|
|
317
341
|
|
318
342
|
describe "to_buffer" do
|
319
343
|
before do
|
320
|
-
stub_request(:post, "https://api
|
344
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
345
|
+
.with(basic_auth: ['api', 'valid'])
|
321
346
|
.to_return(
|
322
347
|
status: 201,
|
323
348
|
headers: { Location: "https://api.tinify.com/some/location" },
|
324
349
|
body: '{}')
|
325
350
|
|
326
|
-
stub_request(:get, "https://api
|
327
|
-
|
328
|
-
|
329
|
-
|
351
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
352
|
+
.with(basic_auth: ['api', 'valid'])
|
353
|
+
.to_return(
|
354
|
+
status: 200,
|
355
|
+
body: "compressed file"
|
356
|
+
)
|
330
357
|
end
|
331
358
|
|
332
359
|
it "should return image data" do
|
@@ -336,16 +363,19 @@ describe Tinify::Source do
|
|
336
363
|
|
337
364
|
describe "to_file" do
|
338
365
|
before do
|
339
|
-
stub_request(:post, "https://api
|
366
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
367
|
+
.with(basic_auth: ['api', 'valid'])
|
340
368
|
.to_return(
|
341
369
|
status: 201,
|
342
370
|
headers: { Location: "https://api.tinify.com/some/location" },
|
343
371
|
body: '{}')
|
344
372
|
|
345
|
-
stub_request(:get, "https://api
|
346
|
-
|
347
|
-
|
348
|
-
|
373
|
+
stub_request(:get, "https://api.tinify.com/some/location")
|
374
|
+
.with(basic_auth: ['api', 'valid'])
|
375
|
+
.to_return(
|
376
|
+
status: 200,
|
377
|
+
body: "compressed file"
|
378
|
+
)
|
349
379
|
end
|
350
380
|
|
351
381
|
it "should store image data" do
|
data/test/tinify_test.rb
CHANGED
@@ -5,7 +5,9 @@ describe Tinify do
|
|
5
5
|
|
6
6
|
describe "key" do
|
7
7
|
before do
|
8
|
-
stub_request(:get, "https://api
|
8
|
+
stub_request(:get, "https://api.tinify.com")
|
9
|
+
.with(basic_auth: ['api', 'fghij'])
|
10
|
+
.to_return(status: 200)
|
9
11
|
end
|
10
12
|
|
11
13
|
it "should reset client with new key" do
|
@@ -13,14 +15,16 @@ describe Tinify do
|
|
13
15
|
Tinify.client
|
14
16
|
Tinify.key = "fghij"
|
15
17
|
Tinify.client.request(:get, "/")
|
16
|
-
assert_requested :get, "https://api
|
17
|
-
headers: { "Authorization" => "Basic
|
18
|
+
assert_requested :get, "https://api.tinify.com",
|
19
|
+
headers: { "Authorization" => "Basic #{ Base64.strict_encode64('api:fghij').chomp}" }
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
describe "app_identifier" do
|
22
24
|
before do
|
23
|
-
stub_request(:get, "https://api
|
25
|
+
stub_request(:get, "https://api.tinify.com")
|
26
|
+
.with(basic_auth: ['api', 'abcde'])
|
27
|
+
.to_return(status: 200)
|
24
28
|
end
|
25
29
|
|
26
30
|
it "should reset client with new app identifier" do
|
@@ -29,14 +33,16 @@ describe Tinify do
|
|
29
33
|
Tinify.client
|
30
34
|
Tinify.app_identifier = "MyApp/2.0"
|
31
35
|
Tinify.client.request(:get, "/")
|
32
|
-
assert_requested :get, "https://api
|
36
|
+
assert_requested :get, "https://api.tinify.com",
|
33
37
|
headers: { "User-Agent" => "#{Tinify::Client::USER_AGENT} MyApp/2.0" }
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
41
|
describe "proxy" do
|
38
42
|
before do
|
39
|
-
stub_request(:get, "https://api
|
43
|
+
stub_request(:get, "https://api.tinify.com")
|
44
|
+
.with(basic_auth: ['api', 'abcde'])
|
45
|
+
.to_return(status: 200)
|
40
46
|
end
|
41
47
|
|
42
48
|
it "should reset client with new proxy" do
|
@@ -45,7 +51,7 @@ describe Tinify do
|
|
45
51
|
Tinify.client
|
46
52
|
Tinify.proxy = "http://user:pass@localhost:8080"
|
47
53
|
Tinify.client.request(:get, "/")
|
48
|
-
assert_requested :get, "https://api
|
54
|
+
assert_requested :get, "https://api.tinify.com",
|
49
55
|
headers: { "Proxy-Authorization" => "Basic dXNlcjpwYXNz" }
|
50
56
|
end
|
51
57
|
end
|
@@ -82,10 +88,12 @@ describe Tinify do
|
|
82
88
|
before do
|
83
89
|
Tinify.key = "valid"
|
84
90
|
|
85
|
-
stub_request(:post, "https://api
|
86
|
-
|
87
|
-
|
88
|
-
|
91
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
92
|
+
.with(basic_auth: ['api', 'valid'])
|
93
|
+
.to_return(
|
94
|
+
status: 400,
|
95
|
+
body: '{"error":"Input missing","message":"No input"}'
|
96
|
+
)
|
89
97
|
end
|
90
98
|
|
91
99
|
it "should return true" do
|
@@ -97,10 +105,12 @@ describe Tinify do
|
|
97
105
|
before do
|
98
106
|
Tinify.key = "valid"
|
99
107
|
|
100
|
-
stub_request(:post, "https://api
|
101
|
-
|
102
|
-
|
103
|
-
|
108
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
109
|
+
.with(basic_auth: ['api', 'valid'])
|
110
|
+
.to_return(
|
111
|
+
status: 429,
|
112
|
+
body: '{"error":"Too many requests","message":"Your monthly limit has been exceeded"}'
|
113
|
+
)
|
104
114
|
end
|
105
115
|
|
106
116
|
it "should return true" do
|
@@ -112,10 +122,12 @@ describe Tinify do
|
|
112
122
|
before do
|
113
123
|
Tinify.key = "invalid"
|
114
124
|
|
115
|
-
stub_request(:post, "https://api
|
116
|
-
|
117
|
-
|
118
|
-
|
125
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
126
|
+
.with(basic_auth: ['api', 'invalid'])
|
127
|
+
.to_return(
|
128
|
+
status: 401,
|
129
|
+
body: '{"error":"Unauthorized","message":"Credentials are invalid"}'
|
130
|
+
)
|
119
131
|
end
|
120
132
|
|
121
133
|
it "should raise error" do
|
@@ -130,11 +142,13 @@ describe Tinify do
|
|
130
142
|
before do
|
131
143
|
Tinify.key = "valid"
|
132
144
|
|
133
|
-
stub_request(:post, "https://api
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
145
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
146
|
+
.with(basic_auth: ['api', 'valid'])
|
147
|
+
.to_return(
|
148
|
+
status: 201,
|
149
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
150
|
+
body: '{}'
|
151
|
+
)
|
138
152
|
end
|
139
153
|
|
140
154
|
it "should return source" do
|
@@ -146,11 +160,13 @@ describe Tinify do
|
|
146
160
|
before do
|
147
161
|
Tinify.key = "valid"
|
148
162
|
|
149
|
-
stub_request(:post, "https://api
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
163
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
164
|
+
.with(basic_auth: ['api', 'valid'])
|
165
|
+
.to_return(
|
166
|
+
status: 201,
|
167
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
168
|
+
body: '{}'
|
169
|
+
)
|
154
170
|
end
|
155
171
|
|
156
172
|
it "should return source" do
|
@@ -162,11 +178,13 @@ describe Tinify do
|
|
162
178
|
before do
|
163
179
|
Tinify.key = "valid"
|
164
180
|
|
165
|
-
stub_request(:post, "https://api
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
181
|
+
stub_request(:post, "https://api.tinify.com/shrink")
|
182
|
+
.with(basic_auth: ['api', 'valid'])
|
183
|
+
.to_return(
|
184
|
+
status: 201,
|
185
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
186
|
+
body: '{}'
|
187
|
+
)
|
170
188
|
end
|
171
189
|
|
172
190
|
it "should return source" do
|
data/tinify.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolf Timmermans
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: httpclient
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
18
|
+
version: '2.9'
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- - "
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '2.9'
|
29
|
+
- - "<"
|
25
30
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
31
|
+
version: '3'
|
27
32
|
description: Ruby client for the Tinify API. Tinify compresses your images intelligently.
|
28
33
|
Read more at https://tinify.com.
|
29
34
|
email:
|
@@ -63,7 +68,6 @@ homepage: https://tinify.com/developers
|
|
63
68
|
licenses:
|
64
69
|
- MIT
|
65
70
|
metadata: {}
|
66
|
-
post_install_message:
|
67
71
|
rdoc_options: []
|
68
72
|
require_paths:
|
69
73
|
- lib
|
@@ -78,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
82
|
- !ruby/object:Gem::Version
|
79
83
|
version: '0'
|
80
84
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
85
|
+
rubygems_version: 3.6.2
|
83
86
|
specification_version: 4
|
84
87
|
summary: Ruby client for the Tinify API.
|
85
88
|
test_files:
|