Permalink
Browse files

improve error parsing

Signed-off-by: David A. Cuadrado <krawek@gmail.com>
  • Loading branch information...
dcu committed Jun 15, 2012
1 parent 2592b18 commit ede1fd1f76b4147c362e6499cfc211331166ba3a
Showing with 10 additions and 5 deletions.
  1. +1 −0 lib/authy/api.rb
  2. +6 −2 lib/authy/models/user.rb
  3. +3 −3 spec/authy/api_spec.rb
View
@@ -33,6 +33,7 @@ def self.verify(params)
# options:
# :id user id
+ # :force force sms
def self.request_sms(params)
user_id = params.delete(:id) || params.delete('id')
View
@@ -26,10 +26,14 @@ def parse_body
self[k] = v
end
else
- @errors = body
+ if body.has_key?('errors')
+ @errors = body['errors']
+ else
+ @errors = body
+ end
end
rescue Exception => e
end
end
end
-end
+end
View
@@ -17,7 +17,7 @@
response.should be_kind_of(Authy::Response)
response.ok?.should be_true
- response.body.should == 'valid token'
+ response['token'].should == 'is valid'
end
it "should fail to validate a given token when force=true is given" do
@@ -26,14 +26,14 @@
response.should be_kind_of(Authy::Response)
response.ok?.should be_false
- response.body.should == 'invalid token'
+ response.errors['token'].should == 'is invalid'
end
it "should return the error messages as a hash" do
user = Authy::API.register_user(:email => generate_email, :cellphone => "abc-1234", :country_code => 1)
user.errors.should be_kind_of(Hash)
- user.errors['cellphone'].should == ['must be a valid cellphone number.']
+ user.errors['cellphone'].should == 'must be a valid cellphone number.'
end
it "should request a SMS token" do

0 comments on commit ede1fd1

Please sign in to comment.