Skip to content

Instantly share code, notes, and snippets.

@perplexes
Created March 8, 2013 18:34
Show Gist options
  • Save perplexes/5118700 to your computer and use it in GitHub Desktop.
Save perplexes/5118700 to your computer and use it in GitHub Desktop.
Post csv to gist with net/http
require 'csv'
csv_string = CSV.generate do |csv|
csv << titles
data.sample(1000).each do |row|
csv << row
end
end; csv_string.size
require 'net/http'
require 'uri'
require 'json'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
url = URI.parse('https://api.github.com/gists')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Post.new(url.path)
req.body = { files: {'works.csv' => {content: csv_string}}, public: false }.to_json; req.body.size
res = http.start{|h| h.request(req)}
jbody = JSON.parse(res.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment