Skip to content

Instantly share code, notes, and snippets.

@amhed
Created September 8, 2013 01:09
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 amhed/6481010 to your computer and use it in GitHub Desktop.
Save amhed/6481010 to your computer and use it in GitHub Desktop.
Ejemplo de como subir un attachment a Basecamp desde Ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
#HTTP Request Objects
uri = URI.parse('https://basecamp.com/1823619/api/v1/projects/320356/attachments.json') #ruta de subir attachments en Basecamp
@https = Net::HTTP.new(uri.host,uri.port)
@https.use_ssl = true
req = Net::HTTP::Post.new(uri.path)
#Autenticacion
req.basic_auth 'aherrera@softworks.do', 'mipassword' #change this for your password
#Archivo que quiero subir
binary_file = File.open('/Users/Amhed/Downloads/Revision 6 Sept/broken line.png', 'rb') {|file| file.read }
#HTTP Headers
req.add_field('User-Agent', 'Softworks') #Esto es necesario pa que funcione la llamada
req.add_field('Content-Type', 'image/png') #Este es el tipo que lleva
req.add_field('Content-Length', binary_file.length)
#Envio del request
req = create_request_object(@attachments_url, 'image/png', binary_file.length)
req.body = binary_content
res = @https.request(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment