tinify 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTg3Y2VkOGIxZWJjNjVjNzIzOGU0ZWM4NjQ1MDE0ZGEyNzUyOGM4ZQ==
5
- data.tar.gz: !binary |-
6
- NzJiYjliMmNhYTQ1ZGJjN2FjMDdmNTNiYTcxNzIyZmYyZDU2MDM0Yw==
2
+ SHA1:
3
+ metadata.gz: d85217d62041c83e2295ef83e13a66bad20da81b
4
+ data.tar.gz: 501c89384831554faa4d7673ce2f1af222b9ec86
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODI3MmJmMDhlYTg2MGE1YzVlOWYzYjRkNjAwMDRiNjMzNjlkZWJhODgzM2Rk
10
- NDE1Njk3ODc2OWZkODlhNjNiNGYyMjE2N2I4MTUxMzNmODRhYTk5ODVlOWRm
11
- YTc0MTVkM2NiZDQ1NjNhMDRmMTFlM2FlNGU5YjliZWQwODRiMTg=
12
- data.tar.gz: !binary |-
13
- MzIxZTJlZWQwMDZhMzU4ZDkyODA3N2I5M2JiNGEwZTM4ODI0NjcxYTcxMWZj
14
- ZTBjYjc5ZGJlYjg5MmU5MGZlZDVlYmI4YmViYjMxY2QzYWQyNWFlMWZmY2I3
15
- YjY0N2Q3ZmU0YTQzNjk1ZTQ3NWI1YTEyOTMwNTgyYzM1MDdkNmI=
6
+ metadata.gz: abec96bd6ed1c1e66ab83f66a6920d6fdd03ac41e4ec9d73411f96f7b573f0ca0705287e2a4eea9329c3460c60bf9339d546350590c75a1be0534d6d565bf0ea
7
+ data.tar.gz: 1caf02c88fc5f118f4234375664c72c7d19800e2973216fee50120846f5f7495ae71f008010c512769efad2f2faf46a28cf6e266ae31b2a10c74994aaaa6c2c9
@@ -16,6 +16,7 @@ env:
16
16
  matrix:
17
17
  allow_failures:
18
18
  - rvm: ruby-head
19
+ - rvm: rbx-2
19
20
  include:
20
21
  - rvm: 2.2
21
22
  env: INTEGRATION_TESTS=true
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tinify (1.3.0)
4
+ tinify (1.4.0)
5
5
  httpclient (~> 2.6)
6
6
 
7
7
  GEM
@@ -27,3 +27,6 @@ DEPENDENCIES
27
27
  rake (~> 10.0)
28
28
  tinify!
29
29
  webmock (~> 1.20)
30
+
31
+ BUNDLED WITH
32
+ 1.13.6
@@ -12,6 +12,7 @@ module Tinify
12
12
  class << self
13
13
  attr_reader :key
14
14
  attr_reader :app_identifier
15
+ attr_reader :proxy
15
16
  attr_accessor :compression_count
16
17
 
17
18
  def key=(key)
@@ -24,6 +25,11 @@ module Tinify
24
25
  @client = nil
25
26
  end
26
27
 
28
+ def proxy=(proxy)
29
+ @proxy = proxy
30
+ @client = nil
31
+ end
32
+
27
33
  def from_file(path)
28
34
  Source.from_file(path)
29
35
  end
@@ -38,6 +44,9 @@ module Tinify
38
44
 
39
45
  def validate!
40
46
  client.request(:post, "/shrink")
47
+ rescue AccountError => err
48
+ return true if err.status == 429
49
+ raise err
41
50
  rescue ClientError
42
51
  true
43
52
  end
@@ -48,7 +57,7 @@ module Tinify
48
57
  raise AccountError.new("Provide an API key with Tinify.key = ...") unless key
49
58
  return @client if @client
50
59
  @@mutex.synchronize do
51
- @client ||= Client.new(key, app_identifier).freeze
60
+ @client ||= Client.new(key, app_identifier, proxy).freeze
52
61
  end
53
62
  end
54
63
  end
@@ -7,8 +7,13 @@ module Tinify
7
7
  USER_AGENT = "Tinify/#{VERSION} Ruby/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "unknown"})".freeze
8
8
  CA_BUNDLE = File.expand_path("../../data/cacert.pem", __FILE__).freeze
9
9
 
10
- def initialize(key, app_identifier = nil)
11
- @client = HTTPClient.new
10
+ def initialize(key, app_identifier = nil, proxy = nil)
11
+ begin
12
+ @client = HTTPClient.new(proxy)
13
+ rescue ArgumentError => err
14
+ raise ConnectionError.new("Invalid proxy: #{err.message}")
15
+ end
16
+
12
17
  @client.base_url = API_ENDPOINT
13
18
  @client.default_header = { "User-Agent" => [USER_AGENT, app_identifier].compact.join(" ") }
14
19
 
@@ -14,12 +14,14 @@ module Tinify
14
14
  end
15
15
  end
16
16
 
17
+ attr_reader :status
18
+
17
19
  def initialize(message, type = self.class.name.split("::").last, status = nil)
18
20
  @message, @type, @status = message, type, status
19
21
  end
20
22
 
21
23
  def message
22
- if @status
24
+ if status
23
25
  "#{@message} (HTTP #{@status}/#{@type})"
24
26
  else
25
27
  "#{@message}"
@@ -1,3 +1,3 @@
1
1
  module Tinify
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -6,6 +6,7 @@ require "tinify"
6
6
  module TestHelpers
7
7
  def before_setup
8
8
  Tinify.key = nil
9
+ Tinify.proxy = nil
9
10
  super
10
11
  end
11
12
 
@@ -7,6 +7,7 @@ require "minitest/autorun"
7
7
 
8
8
  describe "client integration" do
9
9
  Tinify.key = ENV["TINIFY_KEY"]
10
+ Tinify.proxy = ENV["TINIFY_PROXY"]
10
11
 
11
12
  unoptimized_path = File.expand_path("../examples/voormedia.png", __FILE__)
12
13
  optimized = Tinify.from_file(unoptimized_path)
@@ -82,6 +82,18 @@ describe Tinify::Client do
82
82
  headers: { "User-Agent" => "#{Tinify::Client::USER_AGENT} TestApp/0.1" }
83
83
  end
84
84
  end
85
+
86
+ describe "with proxy" do
87
+ subject do
88
+ Tinify::Client.new("key", nil, "http://user:pass@localhost:8080")
89
+ end
90
+
91
+ it "should issue request with proxy authorization" do
92
+ subject.request(:get, "/")
93
+ assert_requested :get, "https://api:key@api.tinify.com",
94
+ headers: { "Proxy-Authorization" => "Basic dXNlcjpwYXNz" }
95
+ end
96
+ end
85
97
  end
86
98
 
87
99
  describe "with timeout" do
@@ -159,7 +171,6 @@ describe Tinify::Client do
159
171
  end
160
172
  end
161
173
 
162
-
163
174
  describe "with bad server response" do
164
175
  before do
165
176
  stub_request(:get, "https://api:key@api.tinify.com").to_return(
@@ -34,6 +34,22 @@ describe Tinify do
34
34
  end
35
35
  end
36
36
 
37
+ describe "proxy" do
38
+ before do
39
+ stub_request(:get, "https://api:abcde@api.tinify.com").to_return(status: 200)
40
+ end
41
+
42
+ it "should reset client with new proxy" do
43
+ Tinify.key = "abcde"
44
+ Tinify.proxy = "http://localhost"
45
+ Tinify.client
46
+ Tinify.proxy = "http://user:pass@localhost:8080"
47
+ Tinify.client.request(:get, "/")
48
+ assert_requested :get, "https://api:abcde@api.tinify.com",
49
+ headers: { "Proxy-Authorization" => "Basic dXNlcjpwYXNz" }
50
+ end
51
+ end
52
+
37
53
  describe "client" do
38
54
  describe "with key" do
39
55
  it "should return client" do
@@ -49,6 +65,16 @@ describe Tinify do
49
65
  end
50
66
  end
51
67
  end
68
+
69
+ describe "with invalid proxy" do
70
+ it "should raise error" do
71
+ assert_raises Tinify::ConnectionError do
72
+ Tinify.key = "abcde"
73
+ Tinify.proxy = "http-bad-url"
74
+ Tinify.client
75
+ end
76
+ end
77
+ end
52
78
  end
53
79
 
54
80
  describe "validate" do
@@ -58,7 +84,22 @@ describe Tinify do
58
84
 
59
85
  stub_request(:post, "https://api:valid@api.tinify.com/shrink").to_return(
60
86
  status: 400,
61
- body: '{"error":"InputMissing","message":"No input"}'
87
+ body: '{"error":"Input missing","message":"No input"}'
88
+ )
89
+ end
90
+
91
+ it "should return true" do
92
+ assert_equal true, Tinify.validate!
93
+ end
94
+ end
95
+
96
+ describe "with limited key" do
97
+ before do
98
+ Tinify.key = "valid"
99
+
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"}'
62
103
  )
63
104
  end
64
105
 
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.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: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '5.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.20'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.20'
83
83
  description: Ruby client for the Tinify API. Tinify compresses your images intelligently.
@@ -88,7 +88,7 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .travis.yml
91
+ - ".travis.yml"
92
92
  - Gemfile
93
93
  - Gemfile.lock
94
94
  - LICENSE
@@ -122,12 +122,12 @@ require_paths:
122
122
  - lib
123
123
  required_ruby_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
- - - ! '>='
125
+ - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ! '>='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []