Class: EditableImage::Picnik

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

Constant Summary collapse

PICNIK_API_PARAMETERS =
%w(
  apikey sig expires locale import returntype title export export_agent
  export_field export_method export_title redirect imageid original_thumb
  replace thumbs out_format out_quality out_maxsize out_maxwidth out_maxheight
  exclude host_name default_in default_out page close_target expand_button
)

Class Method Summary collapse

Class Method Details

.url(full_filename, parameters) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/picnik/picnik.rb', line 11

def self.url(full_filename, parameters)
  raise EditableImage::InvalidParametersError unless api_key_in?(parameters)
  url = ''
  File.open(full_filename) do |file|
    raise EditableImage::InvalidFileTypeError unless image?(full_filename)
    http = Net::HTTP.new('www.picnik.com')
    http.start do |http|
      request = Net::HTTP::Post.new('/service/')
      request.multipart_params = request_parameters(file, parameters)
      response = http.request(request)
      url = response.body
    end
  end
  url
rescue EditableImage::InvalidFileTypeError => e
  raise e, "File must be an image."
rescue EditableImage::InvalidParametersError => e
  raise e, "Parameters must include the apikey."
rescue Errno::ENOENT => e
  raise EditableImage::InvalidFilenameError.new, e.message
end