lib/vimgolf/cli.rb in vimgolf-0.1.1 vs lib/vimgolf/cli.rb in vimgolf-0.1.2

- old
+ new

@@ -122,11 +122,11 @@ data = JSON.parse(res.body) if data['client'] != Vimgolf::VERSION VimGolf.ui.error "Client version mismatch. Installed: #{Vimgolf::VERSION}, Required: #{data['client']}." VimGolf.ui.error "\t gem install vimgolf" - raise + raise "Bad Version" end File.open(Config.put_path + "/#{id}.#{data['in']['type']}", "w") {|f| f.puts data['in']['data']} File.open(Config.put_path + "/#{id}.output", "w") {|f| f.puts data['out']['data']} @@ -140,18 +140,16 @@ def upload(id) begin url = URI.parse("#{GOLFHOST}/entry.json") http = Net::HTTP.new(url.host, url.port) - res = http.start do |conn| - key = Config.load['key'] - data = "challenge_id=#{id}&entry=#{IO.read(log(id))}&apikey=#{key}" - head = {'Accept' => 'application/json'} - conn.post(url.path, data, head) - end + request = Net::HTTP::Post.new(url.request_uri) + request.set_form_data({"challenge_id" => id, "apikey" => Config.load['key'], "entry" => IO.read(log(id))}) + request["Accept"] = "application/json" + res = http.request(request) JSON.parse(res.body)['status'].to_sym rescue Exception => e debug(e) raise "Uh oh, entry upload has failed, please check your key." @@ -170,6 +168,6 @@ def debug(msg) p [caller.first, msg] if GOLFDEBUG end end -end +end \ No newline at end of file