Class: Smusher::PunyPng

Inherits:
Object
  • Object
show all
Defined in:
lib/smusher/puny_png.rb

Constant Summary collapse

DEFAULT_API_KEY =
'97b8b70fc59768979e2a0bdaf19df4dfa5536ed4'
@@api_key =
nil

Class Method Summary collapse

Class Method Details

.api_keyObject



7
8
9
# File 'lib/smusher/puny_png.rb', line 7

def self.api_key
  @@api_key ||= (personal_key || DEFAULT_API_KEY)
end

.api_key=(x) ⇒ Object



6
# File 'lib/smusher/puny_png.rb', line 6

def self.api_key=(x); @@api_key = x; end

.converts_gif_to_png?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/smusher/puny_png.rb', line 11

def self.converts_gif_to_png?
  false
end

.optimized_image_data_for(file) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/smusher/puny_png.rb', line 15

def self.optimized_image_data_for(file)
  url = 'http://www.punypng.com/api/optimize'
  response = HTTPClient.post url, { 'img' => File.new(file), 'key' => api_key}
  response = JSON.parse(response.body)
  raise "puny_png: #{response['error']}" if response['error']
  image_url = response['optimized_url']
  raise "no optimized_url found" unless image_url
  open(image_url) { |source| source.read() }
end