crashwatcher/upload-gist.rb
# Create a gist on gist.github.com
Create a gist on gist.github.com
Create a gist on gist . github . com
def write(files, private_gist = false, description = nil)
  url = URI.parse(CREATE_URL)
  if PROXY_HOST
    proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
    http  = proxy.new(url.host, url.port)
    else
    http = Net::HTTP.new(url.host, url.port)
  end
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.ca_file = ca_cert
  req = Net::HTTP::Post.new(url.path)
  req.set_content_type("application/json")
  req.body = JSON.generate(data(files, private_gist, description))
  user, password = auth()
  if user && password
    req.basic_auth(user, password)
  end
  response = http.start{|h| h.request(req) }
  case response
    when Net::HTTPCreated
    JSON.parse(response.body)['html_url']
    else
    puts "Creating gist failed: #{response.code} #{response.message}"
    exit(false)
  end
end
def write ( files , private_gist = false , description = nil ) url = URI . parse ( CREATE_URL ) if PROXY_HOST proxy = Net :: HTTP :: Proxy ( PROXY_HOST , PROXY_PORT ) http = proxy . new ( url . host , url . port ) else http = Net :: HTTP . new ( url . host , url . port ) end http . use_ssl = true http . verify_mode = OpenSSL :: SSL :: VERIFY_PEER http . ca_file = ca_cert req = Net :: HTTP :: Post . new ( url . path ) req . set_content_type ( "application/json" ) req . body = JSON . generate ( data ( files , private_gist , description ) ) user , password = auth ( ) if user && password req . basic_auth ( user , password ) end response = http . start { | h | h . request ( req ) } case response when Net :: HTTPCreated JSON . parse ( response . body ) [ 'html_url' ] else puts "Creating gist failed: #{response.code} #{response.message}" exit ( false ) end end
Create a gist on gist.github.com
Create a gist on gist . github . com
files
private_gist
description