Skip to content

Commit

Permalink
Fix to client
Browse files Browse the repository at this point in the history
  • Loading branch information
jhollinger committed Sep 16, 2012
1 parent e70b4d8 commit 0d164d4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
8 changes: 0 additions & 8 deletions lib/etherpad-lite.rb
@@ -1,11 +1,3 @@
require 'uri'
require 'json'
require 'delegate'

require 'rest_client'

require 'etherpad-lite/version'
require 'etherpad-lite/exception'
require 'etherpad-lite/client'
require 'etherpad-lite/api'
require 'etherpad-lite/models'
2 changes: 1 addition & 1 deletion lib/etherpad-lite/api.rb
Expand Up @@ -14,7 +14,7 @@ class API
def initialize(version, client)
@version = version.to_s
@client = client
raise EtherpadLiteException, "API version #{@version} is not supported" unless VERSIONS.include? @version
raise Error, "API version #{@version} is not supported" unless VERSIONS.include? @version
end

# Groups
Expand Down
15 changes: 13 additions & 2 deletions lib/etherpad-lite/client.rb
@@ -1,3 +1,11 @@
require 'uri'
require 'json'
require 'delegate'

require 'rest_client'

require 'etherpad-lite/api'

# Provides two interfaces to an EtherpadLite server's API; one low-level and one high.
#
# Low level:
Expand All @@ -15,6 +23,9 @@
# => 'Pad text'
# pad.text = 'new pad text'
module EtherpadLite
# An error returned by the server
Error = Class.new(StandardError)

# Returns a new EtherpadLite::Client.
#
# client = EtherpadLite.client('https://etherpad.yoursite.com[https://etherpad.yoursite.com]', 'your api key')
Expand Down Expand Up @@ -74,8 +85,8 @@ def handle(response)
response = JSON.parse(response, :symbolize_names => true)
case response[:code]
when CODE_OK then response[:data]
when CODE_INVALID_PARAMETERS, CODE_INVALID_API_KEY, CODE_INVALID_METHOD then raise EtherpadLiteException, response[:message]
else raise EtherpadLiteException, "An unknown error ocurrced while handling the API response: #{response.to_s}"
when CODE_INVALID_PARAMETERS, CODE_INVALID_API_KEY, CODE_INVALID_METHOD then raise Error, response[:message]
else raise Error, "An unknown error ocurrced while handling the API response: #{response.to_s}"
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/etherpad-lite/exception.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/etherpad-lite/models/padded.rb
Expand Up @@ -8,7 +8,7 @@ def pad(id, options={})
begin
Pad.create(instance, id, options)
# Pad alreaded exists
rescue EtherpadLiteException
rescue Error
Pad.new(instance, id, options)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/pad_spec.rb
Expand Up @@ -9,7 +9,7 @@
pad = @eth.get_pad 'a non-existant pad'
begin
txt = pad.text
rescue EtherpadLiteException => e
rescue EtherpadLite::Error => e
end
e.message.should == 'padID does not exist'
end
Expand All @@ -22,7 +22,7 @@
it "should blow up when creating a Pad that already exists" do
begin
pad = @eth.create_pad 'my new pad', :text => 'The initial text'
rescue EtherpadLiteException => e
rescue EtherpadLite::Error => e
end
e.message.should == 'padID does already exist'
end
Expand Down Expand Up @@ -108,7 +108,7 @@
err_msg = nil
begin
@eth.client.send(:get, 'setText', :padID => 'brand new pad3')
rescue EtherpadLiteException => e
rescue EtherpadLite::Error => e
err_msg = e.message
end
err_msg.should == 'text is no string'
Expand Down

0 comments on commit 0d164d4

Please sign in to comment.