Permalink
Browse files

Uploading programs now shows errors. Fixes #72.

This was a silly silly oversight that I regeret. Programs always said that the upload worked, even when it didn't. Now it does, in conjunction with commit 2f400529685962bd37e5 on the website.
  • Loading branch information...
1 parent a9fbd42 commit a6bd35e1056300f103015f1bb455244248185586 @steveklabnik steveklabnik committed Jan 18, 2011
Showing with 12 additions and 5 deletions.
  1. +7 −2 app/ui/editor/editor.rb
  2. +4 −2 lib/web/hacker.rb
  3. +1 −1 lib/web/yaml.rb
@@ -232,8 +232,13 @@ def @t.hit_sloppy(x, y)
@save_to_cloud_button =
glossb "Upload", :width => 70, :top => 2, :left => 0 do
hacker = Hacker.new :username => HH::PREFS['username'], :password => HH::PREFS['password']
- hacker.save_program_to_the_cloud script[:name].to_slug, @str
- alert("Uploaded!")
+ hacker.save_program_to_the_cloud(script[:name].to_slug, @str) do |response|
+ if response.status == 200
+ alert("Uploaded!")
+ else
+ alert("There was a problem, sorry!")
+ end
+ end
end
glossb "Run", :width => 52, :top => 2, :left => 130 do
eval(@str, HH.anonymous_binding)
View
@@ -29,9 +29,11 @@ def program_list &blk
http('GET', "/programs/#{@name}.json", :username => @name, :password => @password, &blk)
end
- def save_program_to_the_cloud name, code
+ def save_program_to_the_cloud name, code, &blk
url = "/programs/#{@name}/#{name}.json"
- http('PUT', url, {:creator_username => @name, :title => name, :code => code, :username => @name, :password => @password}) {|u| true }
+ http('PUT', url, {:creator_username => @name, :title => name, :code => code, :username => @name, :password => @password}) do |result|
+ blk[result.response]
+ end
end
end
View
@@ -33,7 +33,7 @@ def http(meth, path, params = nil, &blk)
# end
headers['Authorization'] = 'Basic ' + ["#{HH::PREFS['username']}:#{HH::PREFS['password']}"].pack("m").strip
HH::APP.download url, :method => meth, :body => body, :headers => headers do |dl|
- blk[YAML.load(dl.response.body)] if blk
+ blk[dl] if blk
end
end

0 comments on commit a6bd35e

Please sign in to comment.