Skip to content

Instantly share code, notes, and snippets.

@unixcharles
Created February 3, 2012 20:38
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 unixcharles/1732361 to your computer and use it in GitHub Desktop.
Save unixcharles/1732361 to your computer and use it in GitHub Desktop.
Batch upload to teambox.com
#!/usr/bin/env ruby -rubygems
@api_token = api_token
@project_id = integer_value_or_permalink
@paths = [ array_of_file_path ]
require 'faraday' # >= 0.8
require 'faraday_middleware'
@conn = Faraday.new(:url => 'https://beta.teambox.com/') do |builder|
# encoders:
builder.request :multipart
builder.request :url_encoded
builder.response :json, :content_type => /\bjson$/
builder.request :oauth2, @api_token
builder.adapter Faraday.default_adapter
end
@paths.each do |path|
mimetype = `file --mime -b #{path}`.gsub(/;.+\n/,"")
file = Faraday::UploadIO.new(path, mimetype)
@payload = { :asset => file, :project_id => @project_id }
response = @conn.post "/api/2/projects/#{@project_id}/uploads", @payload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment