tinify 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tinify/result.rb CHANGED
@@ -20,5 +20,12 @@ module Tinify
20
20
  @meta["Content-Type"]
21
21
  end
22
22
  alias_method :content_type, :media_type
23
+
24
+ def extension
25
+ if @meta['Content-Type']
26
+ parts = @meta["Content-Type"].split "/"
27
+ parts.last
28
+ end
29
+ end
23
30
  end
24
31
  end
data/lib/tinify/source.rb CHANGED
@@ -29,6 +29,14 @@ module Tinify
29
29
  self.class.new(@url, @commands.merge(resize: options))
30
30
  end
31
31
 
32
+ def convert(options)
33
+ self.class.new(@url, @commands.merge(convert: options))
34
+ end
35
+
36
+ def transform(options)
37
+ self.class.new(@url, @commands.merge(transform: options))
38
+ end
39
+
32
40
  def store(options)
33
41
  response = Tinify.client.request(:post, @url, @commands.merge(store: options))
34
42
  ResultMeta.new(response.headers).freeze
@@ -1,3 +1,3 @@
1
1
  module Tinify
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
data/test/helper.rb CHANGED
@@ -1,6 +1,10 @@
1
+ require "bundler/setup"
1
2
  require "minitest/autorun"
3
+
2
4
  require "webmock/minitest"
3
5
 
6
+ WebMock.disable_net_connect!(allow_localhost: true)
7
+
4
8
  require "tinify"
5
9
 
6
10
  module TestHelpers
data/test/integration.rb CHANGED
@@ -76,4 +76,15 @@ describe "client integration" do
76
76
  assert_includes contents, "Copyright Voormedia".force_encoding("binary")
77
77
  end
78
78
  end
79
+
80
+ it "should convert" do
81
+ Tempfile.open("optimized.png", encoding: "binary") do |file|
82
+ optimized.convert(type: "image/webp").to_file(file.path)
83
+ r = file.read
84
+
85
+ assert_equal r[0..3], "RIFF".force_encoding("binary")
86
+ assert_equal r[8..11], "WEBP".force_encoding("binary")
87
+ end
88
+ end
89
+
79
90
  end
@@ -255,7 +255,7 @@ describe Tinify::Client do
255
255
  end
256
256
 
257
257
  it "should raise error with message" do
258
- assert_raise_with_message %r{Error while parsing response: .*unexpected token at '<!-- this is not json -->' \(HTTP 543/ParseError\)} do
258
+ assert_raise_with_message /\(HTTP 543\/ParseError\)/ do
259
259
  subject.request(:get, "/")
260
260
  end
261
261
  end
@@ -47,6 +47,12 @@ describe Tinify::Result do
47
47
  assert_equal "image data", subject.to_buffer
48
48
  end
49
49
  end
50
+
51
+ describe "extension" do
52
+ it "should return extension" do
53
+ assert_equal "png", subject.extension
54
+ end
55
+ end
50
56
  end
51
57
 
52
58
  describe "without meta and data" do
@@ -89,5 +95,12 @@ describe Tinify::Result do
89
95
  assert_nil subject.to_buffer
90
96
  end
91
97
  end
98
+
99
+ describe "extension" do
100
+ it "should return nil" do
101
+ assert_nil subject.extension
102
+ end
103
+ end
104
+
92
105
  end
93
106
  end
@@ -213,6 +213,69 @@ describe Tinify::Source do
213
213
  end
214
214
  end
215
215
 
216
+ describe "convert" do
217
+ before do
218
+ stub_request(:post, "https://api:valid@api.tinify.com/shrink")
219
+ .to_return(
220
+ status: 201,
221
+ headers: { Location: "https://api.tinify.com/some/location" },
222
+ body: '{}')
223
+
224
+ stub_request(:get, "https://api:valid@api.tinify.com/some/location")
225
+ .with(
226
+ body: '{"convert":{"type":["image/webp"]}}')
227
+ .to_return(
228
+ status: 200,
229
+ body: "converted file")
230
+ end
231
+
232
+ it "should return source" do
233
+ assert_kind_of Tinify::Source, Tinify::Source.from_buffer("png file").convert(type: ["image/webp"])
234
+ end
235
+
236
+ it "should return source with data" do
237
+ assert_equal "converted file", Tinify::Source.from_buffer("png file").convert(type: ["image/webp"]).to_buffer
238
+ end
239
+ end
240
+
241
+ describe "transform" do
242
+ before do
243
+ stub_request(:post, "https://api:valid@api.tinify.com/shrink")
244
+ .to_return(
245
+ status: 201,
246
+ headers: { Location: "https://api.tinify.com/some/location" },
247
+ body: '{}')
248
+
249
+ stub_request(:get, "https://api:valid@api.tinify.com/some/location")
250
+ .with(
251
+ body: '{"transform":{"color":"black"}}')
252
+ .to_return(
253
+ status: 200,
254
+ body: "transformd file")
255
+ end
256
+
257
+ it "should return source" do
258
+ assert_kind_of Tinify::Source, Tinify::Source.from_buffer("png file").transform(color: "black'")
259
+ end
260
+
261
+ it "should return source with data" do
262
+ assert_equal "transformd file", Tinify::Source.from_buffer("png file").transform(color: "black").to_buffer
263
+ end
264
+
265
+ 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 => {})
271
+
272
+ result = Tinify::Source.from_buffer("png file").convert(type: ["image/webp"]).transform(color: "black")
273
+ assert_equal "trans-formed-and-coded", result.to_buffer
274
+ end
275
+
276
+
277
+ end
278
+
216
279
  describe "store" do
217
280
  before do
218
281
  stub_request(:post, "https://api:valid@api.tinify.com/shrink")
data/tinify.gemspec CHANGED
@@ -19,9 +19,4 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency("httpclient", "~> 2.6")
22
-
23
- spec.add_development_dependency("bundler", "~> 1.7")
24
- spec.add_development_dependency("rake", "~> 10.0")
25
- spec.add_development_dependency("minitest", "~> 5.5")
26
- spec.add_development_dependency("webmock", "~> 1.20")
27
22
  end
data/update-cacert.sh CHANGED
@@ -1,17 +1,17 @@
1
- #!/bin/sh
1
+ #!/usr/bin/env bash
2
2
  dir=lib/data
3
3
 
4
4
  cert=0
5
- curl https://curl.haxx.se/ca/cacert.pem | while read line; do
5
+ curl --silent --fail https://curl.se/ca/cacert.pem | while read -r line; do
6
6
  if [ "-----BEGIN CERTIFICATE-----" == "$line" ]; then
7
7
  cert=1
8
- echo $line
8
+ echo "$line"
9
9
  elif [ "-----END CERTIFICATE-----" == "$line" ]; then
10
10
  cert=0
11
- echo $line
11
+ echo "$line"
12
12
  else
13
13
  if [ $cert == 1 ]; then
14
- echo $line
14
+ echo "$line"
15
15
  fi
16
16
  fi
17
- done > $dir/cacert.pem
17
+ done > "$dir/cacert.pem"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Timmermans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.6'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.7'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.5'
69
- - !ruby/object:Gem::Dependency
70
- name: webmock
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.20'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.20'
83
27
  description: Ruby client for the Tinify API. Tinify compresses your images intelligently.
84
28
  Read more at https://tinify.com.
85
29
  email:
@@ -88,7 +32,8 @@ executables: []
88
32
  extensions: []
89
33
  extra_rdoc_files: []
90
34
  files:
91
- - ".travis.yml"
35
+ - ".github/workflows/ci-cd.yaml"
36
+ - ".gitignore"
92
37
  - CHANGES.md
93
38
  - Gemfile
94
39
  - Gemfile.lock
@@ -133,8 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
78
  - !ruby/object:Gem::Version
134
79
  version: '0'
135
80
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.4.5
81
+ rubygems_version: 3.1.6
138
82
  signing_key:
139
83
  specification_version: 4
140
84
  summary: Ruby client for the Tinify API.
data/.travis.yml DELETED
@@ -1,38 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0
6
- - 2.1
7
- - 2.2
8
- - 2.3.0
9
- - ruby-head
10
- - jruby-19mode
11
- - jruby-20mode
12
- - rbx-2
13
- env:
14
- global:
15
- - secure: u2JnTDMbqgf0kP5vDywFP+lL0ON135Q4a4jXTS1J4K8Kp7qFe/yzyrtYSmDJux31U3Ob/U/ptwYLlFUYuwjwMgTb4ow35jms8d9RvLb6vIBH7Yw9Sf6eq3iJxHGNOjM2pTL9N5DHx4TTO2ov+vQ1PT/QY5P70LVrSKurgKFDjgIZKwnYbFSZtusHX0qTPPQ3FL+NDdcuDmxLxiGt294o+9pFrUAQUKVV4NAk+HUnLjpqKWFqD9pMEw/DYrX4g9RAmN5YWt0sE+CCMFEaKh6Ghrfcfxov9yDEcKDz2ELXNiot9526wwoNONA/zT9hNQXfxhIXfV/67JsJ9cmbZIgP9FLWd/ziRs/yjoTJRaSloifXtAXAft2PMiNx7dnB2C9FFnDzJuTTkJdQfdSEkcXkn0a1Hy5wUI6Ur9Vdjn/Jc5yAHF6Uc78ekgkXBIVxc/J9J9EjophlaCsZHQbgM2H+mADbRIAA/qV1WD9XTISxANP6N19Pt6xFW+wGDnfBBDqbzCO6vK9M+9fU2LW4N8177rtCEG7XkUVSllbJvq841MPqOi2k++B9LD2xAu6Db3ubV5KFL/wg1QBoyP5QOd1uAZ+goQFdvxOZ/7mN/45ytKYYammQlngZFUi638dAE6f4j+NUtrczk4QQJmDuFxXoP+KBtgiD1nrtmenaxOEp/gk=
16
- matrix:
17
- allow_failures:
18
- - rvm: jruby-20mode
19
- - rvm: ruby-head
20
- - rvm: rbx-2
21
- include:
22
- - rvm: 2.2
23
- env: INTEGRATION_TESTS=true
24
- script: "if [ \"$TRAVIS_PULL_REQUEST\" == \"false\" ]; then rake integration; fi"
25
- notifications:
26
- email: false
27
- slack:
28
- secure: udqUs5rLo5XXIM+PpqBDCTOEobzqnQs2Vq+eHOBaJggVSjfYrN6OYQAmZVBLIpysCJPcuZhZ64u93p2Zl+Yu9vJHXPnhFIBEmQlFybCjRIQtz1MMaeqZTMCO49avY+SCjBvXZV902PKJ8vVeeR2O3T5oj894JTejtAnXm5yEInNft3ODMsF+v3R5WFjD8cS+RWegZRotkbhQmQNrqCKxD7rZ3ufTyJuhpVnJPsUZVyaMJbWUWJRsessbl9nBxk3fFR74KXoURgEOv/OmbQD5AkVv1FkxGh0Y7wpn0aU9UOSmJZzzsXp/MaGNfZW7UwGx4iMtTa1YK+h+/fD3PNePfCPLZfvIvxnheIUn3Zrky9TDfK3KP9KHNuAtGdW3c5oxSCimRNTmx2MmsnbGO2sElR/u+Jxr+h0NO5xaBQBmHQeGKjv7VYv3Hexeac0I9lf6lQzmpk6XlstsPfht/Qwia/45RyEu2E8/s4OTFiKYgCBtpttkQ1VTvRowUPgHcuddldUKlI0j6CZlM2gpt9oLAQvzSmdlGX3j4Hpa6nCHILzW8vLoNHvMHTgjz6GU6RJwSj9JjIDkg1XCmq60EmQOKaacjEGXAG2plp0Fulm5THgU7WKnxC5PA+lrSgspmUFb8A0nmKG3tyuSOytVGBRAyu3FLEQih0xrPcZJ2rZ5T0s=
29
- deploy:
30
- provider: rubygems
31
- api_key:
32
- secure: E+dMU6AJuijnGrStl1+hrPizsiPzkWOAjpEG+zAhnuC6pBxTt0Ximc+UcrQiDmQdYQpxhulHreSO2otU9GkvDbpfrP+WE0c9j3AcAAHex6oHIctONWHwcbFnyyIMCNZpcFfMgVH8Nay3vnqVK+bhvNGLP/fVFeQE2co++JQp6BHpIMN6yxlIkGiJeP38Wcv4TVZmJMDcSxgLm+XlZ8xBIMkez9GEADnKXm2ZFfcx8p9K4bXK3hbZ34DF7bYYCN0eDqV4Y5ZGBF9FugUTz19fALyTlQxCks6NM2VT6gM/tg2ibGnzCQ4Wa3XR0pPH6H3xPJBtXlprUvXu27LYrb/PZ0rPN+cXI3nqGKsy6oxfCpVjr26qa5OoRG4XaX8w5ojUDo+D90HyT5Wxpe0BCAVQ+h/rgqOo9X0iByC2S9ORgCmo2lPPCUG442wmiX1V3um29rSNqX9CEb8WC0zZDgGwDp9YjlyztSy+hB96Ljy9rmQcSkQdcQETYSwareBqQmWFeHZbzy2iMR8xEzFpdCVUEnsY9isBVBeoJYYsAlrDRTrlt/A78K32JxP+9E5gQQegv6WQ/0nVJ9fmP6tnmFOLb1CUksmuAIJHA4FdVc0yZDnixHqZy8dyOxJ6dLwjAUx75TThI1ts36wATb8LBXIGgXXJb0y3RNP3KVY/DXPJE64=
33
- gem: tinify
34
- on:
35
- tags: true
36
- repo: tinify/tinify-ruby
37
- ruby: 2.2
38
- condition: "$INTEGRATION_TESTS != true"