tinify 1.8.0 → 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: 9b620618c58618a929492dfc67176be15e5aa9aac7b9f751ac242595559918f1
4
- data.tar.gz: 51e65f1a4bdd85333466f8cc45eb59a6bbbe376722fef3d0381e82958ce84333
3
+ metadata.gz: 8ef479bb3aaa044249d97b2ceef7a20617451d07c66c6ffd7d37de60ccd98c83
4
+ data.tar.gz: 5b230b0036f3b1c0afa091b07b0e09afc6374fd017310627cc723dc709bb3764
5
5
  SHA512:
6
- metadata.gz: fa09aa50924772c6fe5c01e354270be10d4e1812ed4ab31d7c8db83d05a267f952d701d1c7321f9f70ce194e53be72c1a3495f4ff874810e5c754bfc6a8e78de
7
- data.tar.gz: c77d6ab6fd5202f92432cc45d1dd6adb0cc683775a65280fd18ed463eb28d1f30111d3909ff6ce6cc533d2fcde4e3ad461f0b9dac3db2d164aa307b897e975f7
6
+ metadata.gz: 9f0ab7bf57e13b1b21e10613d61ffcb46fb89daa0bd0578646afe1bbc3a292ccc6283d81064625221a79b8a0e589f63c4e4d2352565caaee27d06c4c86fe9e0a
7
+ data.tar.gz: 1a4e19479aa751eecf943bdb4281832d8814234d00918cff3719236594f0cf6efd19beb496db637a3793c4b460e9428ac388e2c67ed957d7f45dc2ef2d2c9da6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.9.0
2
+
3
+ * Added `Tinify::Format` constants for the media types `convert` accepts, including JPEG XL (`image/jxl`).
4
+
1
5
  ## 1.8.0
2
6
 
3
7
  * Update development dependencies.
data/Gemfile.lock CHANGED
@@ -1,31 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tinify (1.8.0)
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.8)
10
+ addressable (2.9.0)
11
11
  public_suffix (>= 2.0.2, < 8.0)
12
12
  base64 (0.3.0)
13
- bigdecimal (4.0.1)
14
- bigdecimal (4.0.1-java)
13
+ bigdecimal (4.1.2)
14
+ bigdecimal (4.1.2-java)
15
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 (6.0.1)
22
+ minitest (6.0.5)
23
+ drb (~> 2.0)
22
24
  prism (~> 1.5)
23
25
  mutex_m (0.3.0)
24
- prism (1.8.0)
25
- public_suffix (7.0.2)
26
- rake (13.3.1)
26
+ prism (1.9.0)
27
+ public_suffix (7.0.5)
28
+ rake (13.4.2)
27
29
  rexml (3.4.4)
28
- webmock (3.26.1)
30
+ webmock (3.26.2)
29
31
  addressable (>= 2.8.0)
30
32
  crack (>= 0.3.2)
31
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.8.0"
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.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Timmermans
@@ -51,6 +51,7 @@ files:
51
51
  - lib/tinify.rb
52
52
  - lib/tinify/client.rb
53
53
  - lib/tinify/error.rb
54
+ - lib/tinify/format.rb
54
55
  - lib/tinify/result.rb
55
56
  - lib/tinify/result_meta.rb
56
57
  - lib/tinify/source.rb
@@ -60,6 +61,7 @@ files:
60
61
  - test/helper.rb
61
62
  - test/integration.rb
62
63
  - test/tinify_client_test.rb
64
+ - test/tinify_format_test.rb
63
65
  - test/tinify_result_meta_test.rb
64
66
  - test/tinify_result_test.rb
65
67
  - test/tinify_source_test.rb
@@ -84,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  - !ruby/object:Gem::Version
85
87
  version: '0'
86
88
  requirements: []
87
- rubygems_version: 4.0.3
89
+ rubygems_version: 4.0.20
88
90
  specification_version: 4
89
91
  summary: Ruby client for the Tinify API.
90
92
  test_files:
@@ -93,6 +95,7 @@ test_files:
93
95
  - test/helper.rb
94
96
  - test/integration.rb
95
97
  - test/tinify_client_test.rb
98
+ - test/tinify_format_test.rb
96
99
  - test/tinify_result_meta_test.rb
97
100
  - test/tinify_result_test.rb
98
101
  - test/tinify_source_test.rb