Skip to content

Instantly share code, notes, and snippets.

@judismith
Created August 21, 2012 03:00
Show Gist options
  • Save judismith/3411107 to your computer and use it in GitHub Desktop.
Save judismith/3411107 to your computer and use it in GitHub Desktop.
Ruby script to create projects through the Basecamp Next API from file
require 'net/https'
require 'uri'
require 'rubygems'
require 'json/pure'
# replace 9999999 with your instance id
@path = '/9999999/api/v1/projects.json'
@user = 'username'
@pass = 'password'
file = File.new("tmp.txt", "r")
while (@line = file.gets("\r"))
puts @line.inspect
@payload = {
"name" => @line.gsub("\r", '')
}.to_json
uri = URI.parse('https://basecamp.com')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Post.new(@path)
req.add_field('Content-Type', 'application/json')
req.add_field('User-Agent', 'MyApp (you@you.com)')
req.basic_auth @user, @pass
req.body = @payload
resp, data = http.request(req)
puts resp.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment