tinify 1.7.1 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af537d83d7cd098489a231282b5e847fa63537aa116d9489897906cccf54d4d3
4
- data.tar.gz: 017bd7ce4f73aac4d6042481ef126d3a7fed319ba67da35ff6e7671705f50a03
3
+ metadata.gz: 8ef479bb3aaa044249d97b2ceef7a20617451d07c66c6ffd7d37de60ccd98c83
4
+ data.tar.gz: 5b230b0036f3b1c0afa091b07b0e09afc6374fd017310627cc723dc709bb3764
5
5
  SHA512:
6
- metadata.gz: 9bc3ab091b52286e90bd0af83aed1fadc868642fbbfd1297e477f977ab97f8ffa06dd12bd9c8dd2007efcea2d216500e6fe486693cd2ae6220783b80a99f8256
7
- data.tar.gz: c140345d128d4317d4d653af7008e71972a82b2e30c06aab93f10e6662bacfcb4fdf11bddac60ece01e76eac7b4c53aeed1cef9285968bd083917c93f0764784
6
+ metadata.gz: 9f0ab7bf57e13b1b21e10613d61ffcb46fb89daa0bd0578646afe1bbc3a292ccc6283d81064625221a79b8a0e589f63c4e4d2352565caaee27d06c4c86fe9e0a
7
+ data.tar.gz: 1a4e19479aa751eecf943bdb4281832d8814234d00918cff3719236594f0cf6efd19beb496db637a3793c4b460e9428ac388e2c67ed957d7f45dc2ef2d2c9da6
@@ -11,7 +11,7 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- ruby-version: ['3.1', '3.2', '3.3', '3.4', 'jruby']
14
+ ruby-version: ['3.2', '3.3', '3.4', '4.0', 'jruby']
15
15
  os: [ubuntu-latest, macOS-latest, windows-latest]
16
16
  # experimental: [false]
17
17
  include:
@@ -27,7 +27,7 @@ jobs:
27
27
  os: ubuntu-latest
28
28
  experimental: false
29
29
  steps:
30
- - uses: actions/checkout@v4
30
+ - uses: actions/checkout@v5
31
31
 
32
32
  - name: Set up ruby ${{ matrix.ruby-version }}
33
33
  uses: ruby/setup-ruby@v1
@@ -49,9 +49,7 @@ jobs:
49
49
  strategy:
50
50
  fail-fast: false
51
51
  matrix:
52
- ruby-version: [
53
- "3.1", "3.4"
54
- ]
52
+ ruby-version: ['3.2', '3.3', '3.4', '4.0', 'jruby']
55
53
  os: [
56
54
  ubuntu-latest,
57
55
  macOS-latest,
@@ -59,7 +57,7 @@ jobs:
59
57
  # windows-latest
60
58
  ]
61
59
  steps:
62
- - uses: actions/checkout@v4
60
+ - uses: actions/checkout@v5
63
61
  - name: Set up ruby ${{ matrix.ruby-version }}
64
62
  uses: ruby/setup-ruby@v1
65
63
  with:
@@ -82,11 +80,11 @@ jobs:
82
80
  needs: [Unit_tests, Integration_tests]
83
81
  runs-on: ubuntu-latest
84
82
  steps:
85
- - uses: actions/checkout@v3
86
- - name: Set up Ruby 3.4
83
+ - uses: actions/checkout@v5
84
+ - name: Setup Ruby 4.0
87
85
  uses: ruby/setup-ruby@v1
88
86
  with:
89
- ruby-version: 3.4
87
+ ruby-version: 4.0
90
88
  - name: Check if properly tagged
91
89
  run: |
92
90
  PACKAGE_VERSION="$(ruby -e 'puts Gem::Specification::load("tinify.gemspec").version')";
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.9.0
2
+
3
+ * Added `Tinify::Format` constants for the media types `convert` accepts, including JPEG XL (`image/jxl`).
4
+
5
+ ## 1.8.0
6
+
7
+ * Update development dependencies.
8
+
9
+ Extend runtime support for:
10
+
11
+ * Ruby 4.0
12
+
13
+ Remove runtime support for:
14
+
15
+ * Ruby 3.1
16
+
1
17
  ## 1.7.1
2
18
  * Update `rexml` because of `CVE-2025-58767`.
3
19
  * Fix source `:result` to use post when a body is given.
data/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ FROM "docker.io/ruby:4.0-alpine"
2
+
3
+ ARG UID=1000
4
+ ARG GID=1000
5
+
6
+ RUN addgroup -g "$GID" -S 'app' \
7
+ && adduser -u "$UID" -G 'app' -S 'app'
8
+
9
+ WORKDIR /home/app
10
+
11
+ COPY --chown=app:app . .
12
+
13
+ RUN apk add --no-cache --update alpine-sdk yaml-dev \
14
+ && bundle install \
15
+ && chown -R app:app /usr/local/bundle
16
+
17
+ ENTRYPOINT /bin/sh
18
+ USER app
data/Gemfile.lock CHANGED
@@ -1,29 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tinify (1.7.1)
4
+ tinify (1.9.0)
5
5
  httpclient (>= 2.9, < 3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.7)
11
- public_suffix (>= 2.0.2, < 7.0)
10
+ addressable (2.9.0)
11
+ public_suffix (>= 2.0.2, < 8.0)
12
12
  base64 (0.3.0)
13
- bigdecimal (3.2.3)
14
- bigdecimal (3.2.3-java)
15
- crack (1.0.0)
13
+ bigdecimal (4.1.2)
14
+ bigdecimal (4.1.2-java)
15
+ crack (1.0.1)
16
16
  bigdecimal
17
17
  rexml
18
+ drb (2.2.3)
18
19
  hashdiff (1.2.1)
19
20
  httpclient (2.9.0)
20
21
  mutex_m
21
- minitest (5.25.5)
22
+ minitest (6.0.5)
23
+ drb (~> 2.0)
24
+ prism (~> 1.5)
22
25
  mutex_m (0.3.0)
23
- public_suffix (6.0.2)
24
- rake (13.3.0)
26
+ prism (1.9.0)
27
+ public_suffix (7.0.5)
28
+ rake (13.4.2)
25
29
  rexml (3.4.4)
26
- webmock (3.25.1)
30
+ webmock (3.26.2)
27
31
  addressable (>= 2.8.0)
28
32
  crack (>= 0.3.2)
29
33
  hashdiff (>= 0.4.0, < 2.0.0)
data/README.md CHANGED
@@ -33,6 +33,27 @@ Tinify.key = "YOUR_API_KEY"
33
33
  Tinify.from_file("unoptimized.png").to_file("optimized.png")
34
34
  ```
35
35
 
36
+ Convert to another format with the `Tinify::Format` constants (`WEBP`, `PNG`,
37
+ `JPEG`, `JPG`, `AVIF`, `JXL` and `ANY`):
38
+
39
+ ```ruby
40
+ Tinify.from_file("unoptimized.png")
41
+ .convert(type: Tinify::Format::JXL)
42
+ .to_file("optimized.jxl")
43
+ ```
44
+
45
+ Pass several and the API returns the smallest result:
46
+
47
+ ```ruby
48
+ result = Tinify.from_file("unoptimized.png")
49
+ .convert(type: [Tinify::Format::JXL, Tinify::Format::WEBP])
50
+ .result
51
+
52
+ result.to_file("optimized.#{result.extension}")
53
+ ```
54
+
55
+ The constants are plain strings, so `type: "image/jxl"` keeps working.
56
+
36
57
  ## Running tests
37
58
 
38
59
  ```
@@ -0,0 +1,39 @@
1
+ module Tinify
2
+ # Media types that images can be converted to.
3
+ #
4
+ # Use these constants with Source#convert:
5
+ #
6
+ # Tinify.from_file("input.png")
7
+ # .convert(type: Tinify::Format::JXL)
8
+ # .to_file("output.jxl")
9
+ #
10
+ # Multiple types may be supplied, in which case the API returns the smallest
11
+ # result:
12
+ #
13
+ # convert(type: [Tinify::Format::JXL, Tinify::Format::WEBP])
14
+ module Format
15
+ # WebP.
16
+ WEBP = "image/webp".freeze
17
+
18
+ # PNG.
19
+ PNG = "image/png".freeze
20
+
21
+ # JPEG.
22
+ JPEG = "image/jpeg".freeze
23
+
24
+ # JPEG, under the alternative image/jpg media type the API also accepts.
25
+ # The API normalises this to image/jpeg, so the result is identical to
26
+ # JPEG. The two constants hold different strings but select the same
27
+ # format.
28
+ JPG = "image/jpg".freeze
29
+
30
+ # AVIF.
31
+ AVIF = "image/avif".freeze
32
+
33
+ # JPEG XL.
34
+ JXL = "image/jxl".freeze
35
+
36
+ # Wildcard, returns the smallest of the supported types.
37
+ ANY = "*/*".freeze
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Tinify
2
- VERSION = "1.7.1"
2
+ VERSION = "1.9.0"
3
3
  end
data/lib/tinify.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "tinify/version"
2
2
  require "tinify/error"
3
+ require "tinify/format"
3
4
 
4
5
  require "tinify/client"
5
6
  require "tinify/result_meta"
@@ -0,0 +1,56 @@
1
+ require File.expand_path("../helper", __FILE__)
2
+
3
+ describe Tinify::Format do
4
+ describe "constants" do
5
+ it "should expose the supported media types" do
6
+ assert_equal "image/webp", Tinify::Format::WEBP
7
+ assert_equal "image/png", Tinify::Format::PNG
8
+ assert_equal "image/jpeg", Tinify::Format::JPEG
9
+ assert_equal "image/jpg", Tinify::Format::JPG
10
+ assert_equal "image/avif", Tinify::Format::AVIF
11
+ assert_equal "image/jxl", Tinify::Format::JXL
12
+ assert_equal "*/*", Tinify::Format::ANY
13
+ end
14
+ end
15
+
16
+ describe "convert" do
17
+ before do
18
+ Tinify.key = "valid"
19
+
20
+ stub_request(:post, "https://api.tinify.com/shrink")
21
+ .with(basic_auth: ['api', 'valid'])
22
+ .to_return(
23
+ status: 201,
24
+ headers: { Location: "https://api.tinify.com/some/location" },
25
+ body: '{}')
26
+ end
27
+
28
+ it "should serialize a single format" do
29
+ stub_request(:post, "https://api.tinify.com/some/location")
30
+ .with(
31
+ basic_auth: ['api', 'valid'],
32
+ body: '{"convert":{"type":"image/jxl"}}')
33
+ .to_return(
34
+ status: 200,
35
+ body: "converted file")
36
+
37
+ source = Tinify::Source.from_buffer("png file")
38
+ .convert(type: Tinify::Format::JXL)
39
+ assert_equal "converted file", source.to_buffer
40
+ end
41
+
42
+ it "should serialize multiple formats" do
43
+ stub_request(:post, "https://api.tinify.com/some/location")
44
+ .with(
45
+ basic_auth: ['api', 'valid'],
46
+ body: '{"convert":{"type":["image/jxl","image/webp"]}}')
47
+ .to_return(
48
+ status: 200,
49
+ body: "converted file")
50
+
51
+ source = Tinify::Source.from_buffer("png file")
52
+ .convert(type: [Tinify::Format::JXL, Tinify::Format::WEBP])
53
+ assert_equal "converted file", source.to_buffer
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Timmermans
@@ -39,7 +39,9 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - ".github/workflows/ci-cd.yaml"
41
41
  - ".gitignore"
42
+ - ".ruby-version"
42
43
  - CHANGELOG.md
44
+ - Dockerfile
43
45
  - Gemfile
44
46
  - Gemfile.lock
45
47
  - LICENSE
@@ -49,6 +51,7 @@ files:
49
51
  - lib/tinify.rb
50
52
  - lib/tinify/client.rb
51
53
  - lib/tinify/error.rb
54
+ - lib/tinify/format.rb
52
55
  - lib/tinify/result.rb
53
56
  - lib/tinify/result_meta.rb
54
57
  - lib/tinify/source.rb
@@ -58,6 +61,7 @@ files:
58
61
  - test/helper.rb
59
62
  - test/integration.rb
60
63
  - test/tinify_client_test.rb
64
+ - test/tinify_format_test.rb
61
65
  - test/tinify_result_meta_test.rb
62
66
  - test/tinify_result_test.rb
63
67
  - test/tinify_source_test.rb
@@ -82,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
86
  - !ruby/object:Gem::Version
83
87
  version: '0'
84
88
  requirements: []
85
- rubygems_version: 3.6.9
89
+ rubygems_version: 4.0.20
86
90
  specification_version: 4
87
91
  summary: Ruby client for the Tinify API.
88
92
  test_files:
@@ -91,6 +95,7 @@ test_files:
91
95
  - test/helper.rb
92
96
  - test/integration.rb
93
97
  - test/tinify_client_test.rb
98
+ - test/tinify_format_test.rb
94
99
  - test/tinify_result_meta_test.rb
95
100
  - test/tinify_result_test.rb
96
101
  - test/tinify_source_test.rb