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
|