carrierwave-tinypng 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e041d06496ede82e4f91ad61a5856004467c2c0
4
+ data.tar.gz: 89fa57dfb16071cc06edd20dfafbb8c66aaa2d83
5
+ SHA512:
6
+ metadata.gz: 8432b26687de9d32387eb687da03b2ca7459909837a7bdc3a251a12bddc9b987eb8a2e8b80f3c78fab421a51d4503a752ab7455da62ed6c89ce453811e801f1e
7
+ data.tar.gz: 0d967ec3aec624177b1a428e053a69172c6b11c00589572f4a99b2ce424ae886dfb1727f870ab251279967c37c6f69d309f03340dc6335e0eac7387f09c3f9cd
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Carrierwave::Tinypng
2
+
3
+ TinyPNG support for CarrierWave
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'carrierwave-tinypng'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install carrierwave-tinypng
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ CarrierWave::TinyPNG.configure do |config|
25
+ config.key = ENV['TINYPNG_KEY']
26
+ end
27
+ ```
28
+
29
+ ```ruby
30
+ class YourUploader < CarrierWave::Uploader::Base
31
+ include CarrierWave::RMagick
32
+ include CarrierWave::TinyPNG
33
+ process convert: 'png'
34
+ process :tinypng
35
+ end
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/takeyuweb/carrierwave-tinypng/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ tinypng_processing_error: "Failed to process file with TinyPNG. Original Error: %{error} %{message}"
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ tinypng_processing_error: "TinyPNGがファイルを処理できませんでした。エラーメッセージ: %{error} %{message}"
@@ -0,0 +1,49 @@
1
+ require "carrierwave/tinypng/version"
2
+
3
+ require 'net/https'
4
+ require 'uri'
5
+ module CarrierWave
6
+ module TinyPNG
7
+
8
+ def self.configure
9
+ yield configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= CarrierWave::TinyPNG::Configuration.new
14
+ end
15
+
16
+ class Configuration
17
+ attr_accessor :key
18
+ end
19
+
20
+ def tinypng
21
+ cache_stored_file! if !cached?
22
+
23
+ key = CarrierWave::TinyPNG.configuration.key
24
+ input = current_path
25
+ output = current_path
26
+
27
+ uri = URI.parse('https://api.tinypng.com/shrink')
28
+
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+ http.use_ssl = true
31
+
32
+ request = Net::HTTP::Post.new(uri.request_uri)
33
+ request.basic_auth('api', key)
34
+
35
+ response = http.request(request, File.binread(input))
36
+ json = JSON.parse(response.body, :symbolize_names => true) || {}
37
+ if response.code == '201'
38
+ File.binwrite(output, http.get(response['location']).body)
39
+ else
40
+ raise CarrierWave::ProcessingError,
41
+ I18n.translate(:'errors.messages.tinypng_processing_error',
42
+ :error => json[:error],
43
+ :message => json[:message],
44
+ :default => I18n.translate(:'errors.messages.tinypng_processing_error',
45
+ :locale => :en))
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module TinyPNG
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-tinypng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuichi Takeuchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: TinyPNG support for CarrierWave
84
+ email:
85
+ - uzuki05@takeyu-web.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - lib/carrierwave/locale/en.yml
92
+ - lib/carrierwave/locale/ja.yml
93
+ - lib/carrierwave/tinypng.rb
94
+ - lib/carrierwave/tinypng/version.rb
95
+ homepage: https://github.com/takeyuweb/carrierwave-tinypng
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: TinyPNG support for CarrierWave
119
+ test_files: []