diff --git a/Gemfile.lock b/Gemfile.lock index a431f3e..8f9107e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,16 @@ PATH remote: . specs: - vimgolf (0.1.0) + vimgolf (0.1.1) + highline json - thor + thor (>= 0.14.6) GEM remote: http://rubygems.org/ specs: diff-lcs (1.1.2) + highline (1.6.1) json (1.4.6) rspec (2.3.0) rspec-core (~> 2.3.0) @@ -24,7 +26,8 @@ PLATFORMS ruby DEPENDENCIES + highline json rspec - thor + thor (>= 0.14.6) vimgolf! diff --git a/lib/vimgolf/cli.rb b/lib/vimgolf/cli.rb index 51869f7..880b31c 100644 --- a/lib/vimgolf/cli.rb +++ b/lib/vimgolf/cli.rb @@ -124,7 +124,7 @@ def download(id) 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']} @@ -142,14 +142,12 @@ 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 @@ -172,4 +170,4 @@ def debug(msg) p [caller.first, msg] if GOLFDEBUG end end -end +end \ No newline at end of file diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index a223e53..bd4afed 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -30,7 +30,7 @@ end it "should return type of challenge on success" do - c.download('4d1a1c36567bac34a9000002').should == "rb" + c.download('4d1a21e88ae121365c00000e').should == "rb" end it "should raise error on invalid upload id" do