tinify 1.6.0 → 1.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9aadffa84ff9efe65549cdd2ffc0e3aa15290bf9c761c9bb6a2cf230b673371b
4
- data.tar.gz: f0eb080d6e890d1e06a96524046991768b30eccf52e436bf7ae030ae3fe0d31e
3
+ metadata.gz: af537d83d7cd098489a231282b5e847fa63537aa116d9489897906cccf54d4d3
4
+ data.tar.gz: 017bd7ce4f73aac4d6042481ef126d3a7fed319ba67da35ff6e7671705f50a03
5
5
  SHA512:
6
- metadata.gz: bffe92ca1ff9e0cbf9de95590fbf2c2e73e764e2a8cab6fc107d30a0cea6554409146db037bfd1c52a3640d17151557414d24de366e554830d65570bb538582e
7
- data.tar.gz: bb6135ba1eedacd4bbed3dbc29e8d456f9486f9845c6c8e584f3e39da01e9f44ef742105e8191b2126e6cd755d1083ca5eb552f1eb62e439b139574ba6b1c7de
6
+ metadata.gz: 9bc3ab091b52286e90bd0af83aed1fadc868642fbbfd1297e477f977ab97f8ffa06dd12bd9c8dd2007efcea2d216500e6fe486693cd2ae6220783b80a99f8256
7
+ data.tar.gz: c140345d128d4317d4d653af7008e71972a82b2e30c06aab93f10e6662bacfcb4fdf11bddac60ece01e76eac7b4c53aeed1cef9285968bd083917c93f0764784
@@ -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@v3
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
- "2.7", "3.1"
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@v3
62
+ - uses: actions/checkout@v4
66
63
  - name: Set up ruby ${{ matrix.ruby-version }}
67
- uses: actions/setup-ruby@v1
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 2.7
86
+ - name: Set up Ruby 3.4
90
87
  uses: ruby/setup-ruby@v1
91
88
  with:
92
- ruby-version: 2.7
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')";
@@ -1,3 +1,22 @@
1
+ ## 1.7.1
2
+ * Update `rexml` because of `CVE-2025-58767`.
3
+ * Fix source `:result` to use post when a body is given.
4
+
5
+ ## 1.7.0
6
+
7
+ * Added base64 gem to Gemfile
8
+
9
+ Extend runtime support for:
10
+
11
+ * Ruby 3.2
12
+ * Ruby 3.3
13
+ * Ruby 3.4
14
+
15
+ Remove runtime support for:
16
+
17
+ * Ruby 2.6
18
+ * Ruby 3.0
19
+
1
20
  ## 1.6.0
2
21
 
3
22
  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 "rake", ">= 12.3.3"
7
- gem 'minitest', '~> 5.5'
8
-
9
- # TODO: Pinned because `Webmock ~> 1.24` breaks specs. Unpin in future
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.6.0)
5
- httpclient (~> 2.6)
4
+ tinify (1.7.1)
5
+ httpclient (>= 2.9, < 3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.1)
11
- public_suffix (>= 2.0.2, < 6.0)
12
- crack (0.4.5)
10
+ addressable (2.8.7)
11
+ public_suffix (>= 2.0.2, < 7.0)
12
+ base64 (0.3.0)
13
+ bigdecimal (3.2.3)
14
+ bigdecimal (3.2.3-java)
15
+ crack (1.0.0)
16
+ bigdecimal
13
17
  rexml
14
- hashdiff (0.3.9)
15
- httpclient (2.8.3)
16
- minitest (5.16.3)
17
- public_suffix (5.0.0)
18
- rake (13.0.6)
19
- rexml (3.2.5)
20
- webmock (1.23.0)
21
- addressable (>= 2.3.6)
18
+ hashdiff (1.2.1)
19
+ httpclient (2.9.0)
20
+ mutex_m
21
+ minitest (5.25.5)
22
+ mutex_m (0.3.0)
23
+ public_suffix (6.0.2)
24
+ rake (13.3.0)
25
+ rexml (3.4.4)
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
- minitest (~> 5.5)
30
- rake (>= 12.3.3)
40
+ base64
41
+ minitest
42
+ rake
31
43
  tinify!
32
- webmock (~> 1.23.0)
44
+ webmock
33
45
 
34
46
  BUNDLED WITH
35
- 2.3.19
47
+ 2.3.27
data/lib/tinify/source.rb CHANGED
@@ -43,7 +43,12 @@ module Tinify
43
43
  end
44
44
 
45
45
  def result
46
- response = Tinify.client.request(:get, @url, @commands)
46
+ response = if @commands&.empty?
47
+ Tinify.client.request(:get, @url)
48
+ else
49
+ Tinify.client.request(:post, @url, @commands)
50
+ end
51
+
47
52
  Result.new(response.headers, response.body).freeze
48
53
  end
49
54
 
@@ -1,3 +1,3 @@
1
1
  module Tinify
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.1"
3
3
  end
data/test/helper.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require "bundler/setup"
2
- require "minitest/autorun"
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
- class MiniTest::Spec
32
- include TestHelpers
31
+ module Minitest
32
+ class Spec
33
+ include TestHelpers
34
+ end
33
35
  end
@@ -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:key@api.tinify.com").to_return(
15
- status: 201,
16
- headers: { "Compression-Count" => "12" }
17
- )
18
- stub_request(:get, "https://api:key@api.tinify.com/shrink").to_return(
19
- status: 201,
20
- headers: {
21
- "Compression-Count" => "12",
22
- "Location" => "https://api.tinify.com/output/3spbi1cd7rs812lb.png"
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:key@api.tinify.com",
30
- headers: { "Authorization" => "Basic " + ["api:key"].pack("m").chomp }
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:key@api.tinify.com/shrink"
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:key@api.tinify.com/shrink"
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:key@api.tinify.com", body: nil
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:key@api.tinify.com",
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:key@api.tinify.com",
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:key@api.tinify.com",
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:key@api.tinify.com",
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:key@api.tinify.com",
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:key@api.tinify.com").to_timeout
105
- .then.to_return(status: 201)
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:key@api.tinify.com").to_timeout
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:key@api.tinify.com")
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:key@api.tinify.com").to_raise(SocketError.new("nodename nor servname provided"))
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:key@api.tinify.com")
178
+ stub_request(:get, "https://api.tinify.com")
179
+ .with(basic_auth: ['api', 'key'])
166
180
  .to_raise("some error")
167
- .then.to_return(status: 201)
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:key@api.tinify.com").to_raise("some error")
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:key@api.tinify.com").to_return(
197
- status: 584,
198
- body: '{"error":"InternalServerError","message":"Oops!"}'
199
- ).then.to_return(status: 201)
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:key@api.tinify.com").to_return(
211
- status: 584,
212
- body: '{"error":"InternalServerError","message":"Oops!"}'
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:key@api.tinify.com").to_return(
232
- status: 543,
233
- body: '<!-- this is not json -->'
234
- ).then.to_return(status: 201)
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:key@api.tinify.com").to_return(
246
- status: 543,
247
- body: '<!-- this is not json -->'
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 /\(HTTP 543\/ParseError\)/ do
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:key@api.tinify.com").to_return(
267
- status: 492,
268
- body: '{"error":"BadRequest","message":"Oops!"}'
269
- ).then.to_return(status: 201)
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:key@api.tinify.com").to_return(
289
- status: 401,
290
- body: '{"error":"Unauthorized","message":"Oops!"}'
291
- ).then.to_return(status: 201)
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
@@ -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:invalid@api.tinify.com/shrink")
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:valid@api.tinify.com/shrink")
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:valid@api.tinify.com/some/location")
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:valid@api.tinify.com/shrink")
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:valid@api.tinify.com/some/location")
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:valid@api.tinify.com/shrink")
95
- .with(body: '{"source":{"url":"http://example.com/test.jpg"}}')
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:valid@api.tinify.com/shrink")
102
- .with(body: '{"source":{"url":"file://wrong"}}')
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:valid@api.tinify.com/some/location")
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,33 +139,64 @@ describe Tinify::Source do
127
139
 
128
140
  describe "result" do
129
141
  before do
130
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
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:valid@api.tinify.com/some/location")
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")
140
154
  end
141
155
 
142
- it "should return result" do
143
- assert_kind_of Tinify::Result, Tinify::Source.from_buffer("png file").result
156
+ it 'has a `Tinify::Result`' do
157
+ assert_kind_of(Tinify::Result,
158
+ Tinify::Source.from_buffer("png file").result)
159
+ end
160
+
161
+ it 'has result data' do
162
+ assert_equal('compressed file',
163
+ Tinify::Source.from_buffer("png file").result.data)
164
+ end
165
+
166
+ it 'is a :get request' do
167
+ Tinify::Source.from_buffer("png file").result
168
+
169
+ assert_requested(:get, "https://api.tinify.com/some/location",
170
+ times: 1)
171
+ end
172
+
173
+ it 'is a :post request' do
174
+ stub_request(:post, "https://api.tinify.com/some/location")
175
+ .with(basic_auth: ['api', 'valid'],
176
+ body: '{"preserve":["copyright","location"]}')
177
+ .to_return(status: 200, body: "copyrighted file")
178
+
179
+ Tinify::Source.from_buffer("png file")
180
+ .preserve("copyright", "location")
181
+ .result
182
+
183
+ assert_requested(:post, "https://api.tinify.com/some/location",
184
+ times: 1)
144
185
  end
145
186
  end
146
187
 
147
188
  describe "preserve" do
148
189
  before do
149
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
190
+ stub_request(:post, "https://api.tinify.com/shrink")
191
+ .with(basic_auth: ['api', 'valid'])
150
192
  .to_return(
151
193
  status: 201,
152
194
  headers: { Location: "https://api.tinify.com/some/location" },
153
195
  body: '{}')
154
196
 
155
- stub_request(:get, "https://api:valid@api.tinify.com/some/location")
197
+ stub_request(:post, "https://api.tinify.com/some/location")
156
198
  .with(
199
+ basic_auth: ['api', 'valid'],
157
200
  body: '{"preserve":["copyright","location"]}')
158
201
  .to_return(
159
202
  status: 200,
@@ -176,8 +219,9 @@ describe Tinify::Source do
176
219
  end
177
220
 
178
221
  it "should include other options if set" do
179
- stub_request(:get, "https://api:valid@api.tinify.com/some/location")
222
+ stub_request(:post, "https://api.tinify.com/some/location")
180
223
  .with(
224
+ basic_auth: ['api', 'valid'],
181
225
  body: '{"resize":{"width":400},"preserve":["copyright","location"]}')
182
226
  .to_return(
183
227
  status: 200,
@@ -190,14 +234,16 @@ describe Tinify::Source do
190
234
 
191
235
  describe "resize" do
192
236
  before do
193
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
237
+ stub_request(:post, "https://api.tinify.com/shrink")
238
+ .with(basic_auth: ['api', 'valid'])
194
239
  .to_return(
195
240
  status: 201,
196
241
  headers: { Location: "https://api.tinify.com/some/location" },
197
242
  body: '{}')
198
243
 
199
- stub_request(:get, "https://api:valid@api.tinify.com/some/location")
244
+ stub_request(:post, "https://api.tinify.com/some/location")
200
245
  .with(
246
+ basic_auth: ['api', 'valid'],
201
247
  body: '{"resize":{"width":400}}')
202
248
  .to_return(
203
249
  status: 200,
@@ -215,14 +261,16 @@ describe Tinify::Source do
215
261
 
216
262
  describe "convert" do
217
263
  before do
218
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
264
+ stub_request(:post, "https://api.tinify.com/shrink")
265
+ .with(basic_auth: ['api', 'valid'])
219
266
  .to_return(
220
267
  status: 201,
221
268
  headers: { Location: "https://api.tinify.com/some/location" },
222
269
  body: '{}')
223
270
 
224
- stub_request(:get, "https://api:valid@api.tinify.com/some/location")
271
+ stub_request(:post, "https://api.tinify.com/some/location")
225
272
  .with(
273
+ basic_auth: ['api', 'valid'],
226
274
  body: '{"convert":{"type":["image/webp"]}}')
227
275
  .to_return(
228
276
  status: 200,
@@ -240,14 +288,16 @@ describe Tinify::Source do
240
288
 
241
289
  describe "transform" do
242
290
  before do
243
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
291
+ stub_request(:post, "https://api.tinify.com/shrink")
292
+ .with(basic_auth: ['api', 'valid'])
244
293
  .to_return(
245
294
  status: 201,
246
295
  headers: { Location: "https://api.tinify.com/some/location" },
247
296
  body: '{}')
248
297
 
249
- stub_request(:get, "https://api:valid@api.tinify.com/some/location")
298
+ stub_request(:post, "https://api.tinify.com/some/location")
250
299
  .with(
300
+ basic_auth: ['api', 'valid'],
251
301
  body: '{"transform":{"color":"black"}}')
252
302
  .to_return(
253
303
  status: 200,
@@ -263,30 +313,28 @@ describe Tinify::Source do
263
313
  end
264
314
 
265
315
  it "should include other options if set" do
266
-
267
- stub_request(:get, "https://api:valid@api.tinify.com/some/location").
268
- with(:body => '{"convert":{"type":["image/webp"]},"transform":{"color":"black"}}',
269
- ).
270
- to_return(:status => 200, :body => "trans-formed-and-coded", :headers => {})
316
+ stub_request(:post, "https://api.tinify.com/some/location")
317
+ .with(:body => '{"convert":{"type":["image/webp"]},"transform":{"color":"black"}}')
318
+ .to_return(:status => 200, :body => "trans-formed-and-coded", :headers => {})
271
319
 
272
320
  result = Tinify::Source.from_buffer("png file").convert(type: ["image/webp"]).transform(color: "black")
273
321
  assert_equal "trans-formed-and-coded", result.to_buffer
274
322
  end
275
-
276
-
277
323
  end
278
324
 
279
325
  describe "store" do
280
326
  before do
281
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
327
+ stub_request(:post, "https://api.tinify.com/shrink")
328
+ .with(basic_auth: ['api', 'valid'])
282
329
  .to_return(
283
330
  status: 201,
284
331
  headers: { Location: "https://api.tinify.com/some/location" },
285
332
  body: '{}'
286
333
  )
287
334
 
288
- stub_request(:post, "https://api:valid@api.tinify.com/some/location")
335
+ stub_request(:post, "https://api.tinify.com/some/location")
289
336
  .with(
337
+ basic_auth: ['api', 'valid'],
290
338
  body: '{"store":{"service":"s3"}}')
291
339
  .to_return(
292
340
  status: 200,
@@ -303,8 +351,9 @@ describe Tinify::Source do
303
351
  end
304
352
 
305
353
  it "should include other options if set" do
306
- stub_request(:post, "https://api:valid@api.tinify.com/some/location")
354
+ stub_request(:post, "https://api.tinify.com/some/location")
307
355
  .with(
356
+ basic_auth: ['api', 'valid'],
308
357
  body: '{"resize":{"width":400},"store":{"service":"s3"}}')
309
358
  .to_return(
310
359
  status: 200,
@@ -317,16 +366,19 @@ describe Tinify::Source do
317
366
 
318
367
  describe "to_buffer" do
319
368
  before do
320
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
369
+ stub_request(:post, "https://api.tinify.com/shrink")
370
+ .with(basic_auth: ['api', 'valid'])
321
371
  .to_return(
322
372
  status: 201,
323
373
  headers: { Location: "https://api.tinify.com/some/location" },
324
374
  body: '{}')
325
375
 
326
- stub_request(:get, "https://api:valid@api.tinify.com/some/location").to_return(
327
- status: 200,
328
- body: "compressed file"
329
- )
376
+ stub_request(:get, "https://api.tinify.com/some/location")
377
+ .with(basic_auth: ['api', 'valid'])
378
+ .to_return(
379
+ status: 200,
380
+ body: "compressed file"
381
+ )
330
382
  end
331
383
 
332
384
  it "should return image data" do
@@ -336,16 +388,19 @@ describe Tinify::Source do
336
388
 
337
389
  describe "to_file" do
338
390
  before do
339
- stub_request(:post, "https://api:valid@api.tinify.com/shrink")
391
+ stub_request(:post, "https://api.tinify.com/shrink")
392
+ .with(basic_auth: ['api', 'valid'])
340
393
  .to_return(
341
394
  status: 201,
342
395
  headers: { Location: "https://api.tinify.com/some/location" },
343
396
  body: '{}')
344
397
 
345
- stub_request(:get, "https://api:valid@api.tinify.com/some/location").to_return(
346
- status: 200,
347
- body: "compressed file"
348
- )
398
+ stub_request(:get, "https://api.tinify.com/some/location")
399
+ .with(basic_auth: ['api', 'valid'])
400
+ .to_return(
401
+ status: 200,
402
+ body: "compressed file"
403
+ )
349
404
  end
350
405
 
351
406
  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:fghij@api.tinify.com").to_return(status: 200)
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:fghij@api.tinify.com",
17
- headers: { "Authorization" => "Basic " + ["api:fghij"].pack("m").chomp }
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:abcde@api.tinify.com").to_return(status: 200)
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:abcde@api.tinify.com",
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:abcde@api.tinify.com").to_return(status: 200)
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:abcde@api.tinify.com",
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:valid@api.tinify.com/shrink").to_return(
86
- status: 400,
87
- body: '{"error":"Input missing","message":"No input"}'
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:valid@api.tinify.com/shrink").to_return(
101
- status: 429,
102
- body: '{"error":"Too many requests","message":"Your monthly limit has been exceeded"}'
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:invalid@api.tinify.com/shrink").to_return(
116
- status: 401,
117
- body: '{"error":"Unauthorized","message":"Credentials are invalid"}'
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:valid@api.tinify.com/shrink").to_return(
134
- status: 201,
135
- headers: { Location: "https://api.tinify.com/some/location" },
136
- body: '{}'
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:valid@api.tinify.com/shrink").to_return(
150
- status: 201,
151
- headers: { Location: "https://api.tinify.com/some/location" },
152
- body: '{}'
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:valid@api.tinify.com/shrink").to_return(
166
- status: 201,
167
- headers: { Location: "https://api.tinify.com/some/location" },
168
- body: '{}'
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
@@ -18,5 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^test/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency("httpclient", "~> 2.6")
21
+ spec.add_dependency('httpclient', '>= 2.9', '< 3')
22
22
  end
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.6.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Timmermans
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 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.6'
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: '2.6'
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:
@@ -34,7 +39,7 @@ extra_rdoc_files: []
34
39
  files:
35
40
  - ".github/workflows/ci-cd.yaml"
36
41
  - ".gitignore"
37
- - CHANGES.md
42
+ - CHANGELOG.md
38
43
  - Gemfile
39
44
  - Gemfile.lock
40
45
  - LICENSE
@@ -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.1.6
82
- signing_key:
85
+ rubygems_version: 3.6.9
83
86
  specification_version: 4
84
87
  summary: Ruby client for the Tinify API.
85
88
  test_files: