Skip to content

Commit

Permalink
*facepalm* properly encode uploaded data
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Dec 29, 2010
1 parent 5651f70 commit cd3e865
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 6 additions & 3 deletions 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)
Expand All @@ -24,7 +26,8 @@ PLATFORMS
ruby

DEPENDENCIES
highline
json
rspec
thor
thor (>= 0.14.6)
vimgolf!
14 changes: 6 additions & 8 deletions lib/vimgolf/cli.rb
Expand Up @@ -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']}
Expand All @@ -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
Expand All @@ -172,4 +170,4 @@ def debug(msg)
p [caller.first, msg] if GOLFDEBUG
end
end
end
end
2 changes: 1 addition & 1 deletion spec/cli_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit cd3e865

Please sign in to comment.