Skip to content

Instantly share code, notes, and snippets.

@ssuda
Created October 17, 2012 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssuda/3907327 to your computer and use it in GitHub Desktop.
Save ssuda/3907327 to your computer and use it in GitHub Desktop.
zipplease sample in Ruby on Rails
=begin
#routes.rb
post "demo/flicker"
#Gemfile
gem 'uuid'
gem 'rest-client'
#Sample request
curl -X POST -H 'Content-Type:application/json' -d '["http://sample.org/1", "http://sample.org/2"]' -H 'Accept:application/json' http://localhost:3000/demo/flicker
=end
class DemoController < ApplicationController
respond_to :json
@@uuid = UUID.new
def flicker
images = params['_json']
# Create the JSON payload to send to ZipPlease
zipRequest = {
:accountKey => "6B5qClA0SG2er7x7PmZTK4QU", # Not real.
:accountSecret => "jHxRb2y3CevJyROL96hYKcE0oAI", # Get your own.
:zipName => "zipPleaseFlickrDemo_" + @@uuid.generate + ".zip",
:files => images,
:compress => false # already jpegs
}
response = RestClient.post 'http://www.zipplease.com/api/zips', zipRequest.to_json, :content_type => :json, :accept => :json
render :json => response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment