smusher 0.4.2 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -36,6 +36,13 @@ Example
36
36
  reverted!
37
37
  ...
38
38
 
39
+ ### PunyPng - usage limit
40
+ The default `Smusher::PunyPng.api_key` is used by all users and
41
+ could already be full when you try to smush some images.
42
+
43
+ Create a .puny_png_api_key in your home directory with your own
44
+ api key from [PunyPng](http://www.gracepointafterfive.com/punypng).
45
+
39
46
  Protection
40
47
  ==========
41
48
  Any image that returns a failure code, is larger than before,
@@ -52,6 +59,7 @@ reduce images and minify css + js -> try [reduce](http://github.com/grosser/redu
52
59
  Authors
53
60
  ======
54
61
  ###Contributors
62
+ - [ahaller](http://ahax.de/)
55
63
  - [retr0h](http://geminstallthat.wordpress.com/)
56
64
 
57
65
  [Michael Grosser](http://pragmatig.wordpress.com)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.4
data/lib/smusher.rb CHANGED
@@ -21,7 +21,7 @@ module Smusher
21
21
  service = options[:service] || 'SmushIt'
22
22
  service = eval(service)
23
23
 
24
- files.each do |file|
24
+ Array(files).each do |file|
25
25
  check_options(options)
26
26
  puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero?
27
27
  success = false
@@ -1,17 +1,32 @@
1
1
  module Smusher
2
2
  class PunyPng
3
+ DEFAULT_API_KEY = '97b8b70fc59768979e2a0bdaf19df4dfa5536ed4'
4
+
5
+ @@api_key = nil
6
+ def self.api_key=(x); @@api_key = x; end
7
+ def self.api_key
8
+ @@api_key ||= (personal_key || DEFAULT_API_KEY)
9
+ end
10
+
3
11
  def self.converts_gif_to_png?
4
12
  false
5
13
  end
6
14
 
7
15
  def self.optimized_image_data_for(file)
8
- url = 'http://www.gracepointafterfive.com/punypng_staging/api/optimize'
9
- response = HTTPClient.post url, { 'img' => File.new(file), 'key' => 'd1b72ab4813da6b69e1d6018303ac690c014599d'}
16
+ url = 'http://www.gracepointafterfive.com/punypng/api/optimize'
17
+ response = HTTPClient.post url, { 'img' => File.new(file), 'key' => api_key}
10
18
  response = JSON.parse(response.body.content)
11
19
  raise "puny_png: #{response['error']}" if response['error']
12
20
  image_url = response['optimized_url']
13
21
  raise "no optimized_url found" unless image_url
14
22
  open(image_url) { |source| source.read() }
15
23
  end
24
+
25
+ private
26
+
27
+ def self.personal_key
28
+ key = `cat ~/.puny_png_api_key`.strip
29
+ key.empty? ? nil : key
30
+ end
16
31
  end
17
32
  end
data/smusher.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{smusher}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2009-11-22}
12
+ s.date = %q{2010-03-23}
13
13
  s.default_executable = %q{smusher}
14
14
  s.email = %q{grosser.michael@gmail.com}
15
15
  s.executables = ["smusher"]
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.homepage = %q{http://github.com/grosser/smusher}
48
48
  s.rdoc_options = ["--charset=UTF-8"]
49
49
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.5}
50
+ s.rubygems_version = %q{1.3.6}
51
51
  s.summary = %q{Automatic Lossless Reduction Of All Your Images}
52
52
  s.test_files = [
53
53
  "spec/spec_helper.rb",
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
- # ---- requirements
2
1
  require 'rubygems'
3
- require 'spec'
4
2
 
5
3
  $LOAD_PATH << 'lib'
6
4
  require 'smusher'
7
5
 
6
+ # separate key for testing
7
+ Smusher::PunyPng.api_key = '3cbb0102ca6d000370f2d5b34ca0125d67b801dc'
8
+
8
9
  ROOT = File.expand_path(File.dirname(__FILE__))
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 4
9
+ version: 0.4.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Michael Grosser
@@ -9,39 +14,45 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-22 00:00:00 +01:00
17
+ date: 2010-03-23 00:00:00 +01:00
13
18
  default_executable: smusher
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rake
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :runtime
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
33
41
  version: "0"
34
- version:
42
+ type: :runtime
43
+ version_requirements: *id002
35
44
  - !ruby/object:Gem::Dependency
36
45
  name: httpclient
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ">="
42
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
43
53
  version: "0"
44
- version:
54
+ type: :runtime
55
+ version_requirements: *id003
45
56
  description:
46
57
  email: grosser.michael@gmail.com
47
58
  executables:
@@ -90,18 +101,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
101
  requirements:
91
102
  - - ">="
92
103
  - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
93
106
  version: "0"
94
- version:
95
107
  required_rubygems_version: !ruby/object:Gem::Requirement
96
108
  requirements:
97
109
  - - ">="
98
110
  - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
99
113
  version: "0"
100
- version:
101
114
  requirements: []
102
115
 
103
116
  rubyforge_project:
104
- rubygems_version: 1.3.5
117
+ rubygems_version: 1.3.6
105
118
  signing_key:
106
119
  specification_version: 3
107
120
  summary: Automatic Lossless Reduction Of All Your Images