tinify 0.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 +7 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +21 -0
- data/README.md +30 -0
- data/Rakefile +8 -0
- data/lib/data/cacert.pem +3894 -0
- data/lib/tinify.rb +45 -0
- data/lib/tinify/client.rb +52 -0
- data/lib/tinify/error.rb +35 -0
- data/lib/tinify/result.rb +32 -0
- data/lib/tinify/source.rb +40 -0
- data/lib/tinify/version.rb +3 -0
- data/test/examples/dummy.png +0 -0
- data/test/helper.rb +28 -0
- data/test/tinify_client_test.rb +193 -0
- data/test/tinify_result_test.rb +44 -0
- data/test/tinify_source_test.rb +123 -0
- data/test/tinify_test.rb +96 -0
- data/tinify.gemspec +27 -0
- metadata +141 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.expand_path("../helper", __FILE__)
|
2
|
+
|
3
|
+
describe Tinify::Source do
|
4
|
+
dummy_file = File.expand_path("../examples/dummy.png", __FILE__)
|
5
|
+
|
6
|
+
describe "with invalid api key" do
|
7
|
+
before do
|
8
|
+
Tinify.key = "invalid"
|
9
|
+
|
10
|
+
stub_request(:post, "https://api:invalid@api.tinify.com/shrink").to_return(
|
11
|
+
status: 401,
|
12
|
+
body: '{"error":"Unauthorized","message":"Credentials are invalid"}'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "from_file" do
|
17
|
+
it "should raise account error" do
|
18
|
+
assert_raises Tinify::AccountError do
|
19
|
+
Tinify::Source.from_file(dummy_file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "from_buffer" do
|
25
|
+
it "should raise account error" do
|
26
|
+
assert_raises Tinify::AccountError do
|
27
|
+
Tinify::Source.from_buffer("png file")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with valid api key" do
|
34
|
+
before do
|
35
|
+
Tinify.key = "valid"
|
36
|
+
|
37
|
+
stub_request(:post, "https://api:valid@api.tinify.com/shrink").to_return(
|
38
|
+
status: 201,
|
39
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
40
|
+
body: '{}'
|
41
|
+
)
|
42
|
+
|
43
|
+
stub_request(:get, "https://api:valid@api.tinify.com/some/location").to_return(
|
44
|
+
status: 200,
|
45
|
+
body: "compressed file"
|
46
|
+
)
|
47
|
+
|
48
|
+
stub_request(:get, "https://api:valid@api.tinify.com/some/location").with(
|
49
|
+
body: '{"resize":{"width":400}}'
|
50
|
+
).to_return(
|
51
|
+
status: 200,
|
52
|
+
body: "small file"
|
53
|
+
)
|
54
|
+
|
55
|
+
stub_request(:post, "https://api:valid@api.tinify.com/some/location").with(
|
56
|
+
body: '{"store":{"service":"s3"}}'
|
57
|
+
).to_return(
|
58
|
+
status: 200,
|
59
|
+
headers: { Location: "https://bucket.s3.amazonaws.com/example" }
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "from_file" do
|
64
|
+
it "should return source" do
|
65
|
+
assert_kind_of Tinify::Source, Tinify::Source.from_file(dummy_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return source with data" do
|
69
|
+
assert_equal "compressed file", Tinify::Source.from_file(dummy_file).to_buffer
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "from_buffer" do
|
74
|
+
it "should return source" do
|
75
|
+
assert_kind_of Tinify::Source, Tinify::Source.from_buffer("png file")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return source with data" do
|
79
|
+
assert_equal "compressed file", Tinify::Source.from_buffer("png file").to_buffer
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "result" do
|
84
|
+
it "should return result" do
|
85
|
+
assert_kind_of Tinify::Result, Tinify::Source.from_buffer("png file").result
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "resize" do
|
90
|
+
it "should return source" do
|
91
|
+
assert_kind_of Tinify::Source, Tinify::Source.from_buffer("png file").resize(width: 400)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return source with data" do
|
95
|
+
assert_equal "small file", Tinify::Source.from_buffer("png file").resize(width: 400).to_buffer
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "store" do
|
100
|
+
it "should return result" do
|
101
|
+
assert_kind_of Tinify::Result, Tinify::Source.from_buffer("png file").store(service: "s3")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "to_buffer" do
|
106
|
+
it "should return image data" do
|
107
|
+
assert_equal "compressed file", Tinify::Source.from_buffer("png file").to_buffer
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "to_file" do
|
112
|
+
it "should store image data" do
|
113
|
+
begin
|
114
|
+
tmp = Tempfile.open("foo")
|
115
|
+
Tinify::Source.from_buffer("png file").to_file(tmp.path)
|
116
|
+
assert_equal "compressed file", File.binread(tmp.path)
|
117
|
+
ensure
|
118
|
+
tmp.unlink
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/test/tinify_test.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.expand_path("../helper", __FILE__)
|
2
|
+
|
3
|
+
describe Tinify do
|
4
|
+
dummy_file = File.expand_path("../examples/dummy.png", __FILE__)
|
5
|
+
|
6
|
+
describe "reset" do
|
7
|
+
it "should reset key" do
|
8
|
+
Tinify.key = "abcde"
|
9
|
+
Tinify.reset!
|
10
|
+
assert_equal nil, Tinify.key
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "client" do
|
15
|
+
describe "with key" do
|
16
|
+
it "should return client" do
|
17
|
+
Tinify.key = "abcde"
|
18
|
+
assert_kind_of Tinify::Client, Tinify.client
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "without key" do
|
23
|
+
it "should raise error" do
|
24
|
+
assert_raises Tinify::AccountError do
|
25
|
+
Tinify.client
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "validate" do
|
32
|
+
describe "with valid key" do
|
33
|
+
before do
|
34
|
+
Tinify.key = "valid"
|
35
|
+
|
36
|
+
stub_request(:post, "https://api:valid@api.tinify.com/shrink").to_return(
|
37
|
+
status: 400,
|
38
|
+
body: '{"error":"InputMissing","message":"No input"}'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return true" do
|
43
|
+
assert_equal true, Tinify.validate!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with error" do
|
48
|
+
before do
|
49
|
+
Tinify.key = "invalid"
|
50
|
+
|
51
|
+
stub_request(:post, "https://api:invalid@api.tinify.com/shrink").to_return(
|
52
|
+
status: 401,
|
53
|
+
body: '{"error":"Unauthorized","message":"Credentials are invalid"}'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise error" do
|
58
|
+
assert_raises Tinify::AccountError do
|
59
|
+
Tinify.validate!
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "from_buffer" do
|
66
|
+
before do
|
67
|
+
Tinify.key = "valid"
|
68
|
+
|
69
|
+
stub_request(:post, "https://api:valid@api.tinify.com/shrink").to_return(
|
70
|
+
status: 201,
|
71
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
72
|
+
body: '{}'
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return source" do
|
77
|
+
assert_kind_of Tinify::Source, Tinify::Source.from_buffer("png file")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "from_file" do
|
82
|
+
before do
|
83
|
+
Tinify.key = "valid"
|
84
|
+
|
85
|
+
stub_request(:post, "https://api:valid@api.tinify.com/shrink").to_return(
|
86
|
+
status: 201,
|
87
|
+
headers: { Location: "https://api.tinify.com/some/location" },
|
88
|
+
body: '{}'
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return source" do
|
93
|
+
assert_kind_of Tinify::Source, Tinify::Source.from_file(dummy_file)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/tinify.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "tinify/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tinify"
|
8
|
+
spec.version = Tinify::VERSION
|
9
|
+
spec.summary = "Ruby client for the Tinify API."
|
10
|
+
spec.description = "Ruby client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com."
|
11
|
+
spec.authors = ["Rolf Timmermans"]
|
12
|
+
spec.email = ["rolftimmermans@voormedia.com"]
|
13
|
+
spec.homepage = "https://tinify.com/developers"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tinify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rolf Timmermans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
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
|
+
description: Ruby client for the Tinify API. Tinify compresses your images intelligently.
|
84
|
+
Read more at https://tinify.com.
|
85
|
+
email:
|
86
|
+
- rolftimmermans@voormedia.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/data/cacert.pem
|
98
|
+
- lib/tinify.rb
|
99
|
+
- lib/tinify/client.rb
|
100
|
+
- lib/tinify/error.rb
|
101
|
+
- lib/tinify/result.rb
|
102
|
+
- lib/tinify/source.rb
|
103
|
+
- lib/tinify/version.rb
|
104
|
+
- test/examples/dummy.png
|
105
|
+
- test/helper.rb
|
106
|
+
- test/tinify_client_test.rb
|
107
|
+
- test/tinify_result_test.rb
|
108
|
+
- test/tinify_source_test.rb
|
109
|
+
- test/tinify_test.rb
|
110
|
+
- tinify.gemspec
|
111
|
+
homepage: https://tinify.com/developers
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.4.5
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Ruby client for the Tinify API.
|
135
|
+
test_files:
|
136
|
+
- test/examples/dummy.png
|
137
|
+
- test/helper.rb
|
138
|
+
- test/tinify_client_test.rb
|
139
|
+
- test/tinify_result_test.rb
|
140
|
+
- test/tinify_source_test.rb
|
141
|
+
- test/tinify_test.rb
|