wordnik 4.06.02 → 4.06.04

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordnik (4.06.00)
4
+ wordnik (4.06.03)
5
5
  activemodel (>= 3.0.3)
6
6
  addressable (>= 2.2.4)
7
7
  htmlentities (>= 4.2.4)
@@ -12,20 +12,20 @@ PATH
12
12
  GEM
13
13
  remote: http://rubygems.org/
14
14
  specs:
15
- activemodel (3.0.8)
16
- activesupport (= 3.0.8)
15
+ activemodel (3.0.9)
16
+ activesupport (= 3.0.9)
17
17
  builder (~> 2.1.2)
18
18
  i18n (~> 0.5.0)
19
- activesupport (3.0.8)
19
+ activesupport (3.0.9)
20
20
  addressable (2.2.4)
21
21
  builder (2.1.2)
22
22
  crack (0.1.8)
23
23
  diff-lcs (1.1.2)
24
24
  htmlentities (4.3.0)
25
25
  i18n (0.5.0)
26
- json (1.5.1)
26
+ json (1.5.3)
27
27
  mime-types (1.16)
28
- nokogiri (1.4.4)
28
+ nokogiri (1.5.0)
29
29
  rspec (2.5.0)
30
30
  rspec-core (~> 2.5.0)
31
31
  rspec-expectations (~> 2.5.0)
@@ -15,27 +15,32 @@ module Wordnik
15
15
 
16
16
  def initialize(raw)
17
17
  self.raw = raw
18
+
19
+ case self.code
20
+ when 500..510 then raise(ServerError, self.error_message)
21
+ when 299..426 then raise(ClientError, self.error_message)
22
+ end
18
23
  end
19
24
 
20
25
  def code
21
26
  raw.code
22
27
  end
28
+
29
+ def error_message
30
+ body['message']
31
+ rescue
32
+ body
33
+ end
23
34
 
24
35
  # If body is JSON, parse it
25
36
  # TODO: If body is XML, parse it
26
37
  # Otherwise return raw string
27
38
  def body
28
-
29
- if self.code > 399
30
- raise AuthorizationError, raw.inspect
31
- end
32
-
33
39
  begin
34
40
  JSON.parse raw.body
35
41
  rescue
36
42
  raw.body
37
43
  end
38
-
39
44
  end
40
45
 
41
46
  def headers
@@ -1,4 +1,4 @@
1
1
  module Wordnik
2
- VERSION = "4.06.02"
2
+ VERSION = "4.06.04"
3
3
  end
4
4
 
data/lib/wordnik.rb CHANGED
@@ -79,7 +79,7 @@ module Wordnik
79
79
  return if Wordnik.authenticated?
80
80
 
81
81
  if Wordnik.configuration.username.blank? || Wordnik.configuration.password.blank?
82
- raise ConfigurationError, "Username and password are required to authenticate."
82
+ raise ClientError, "Username and password are required to authenticate."
83
83
  end
84
84
 
85
85
  request = Wordnik::Request.new(
@@ -89,21 +89,16 @@ module Wordnik
89
89
  )
90
90
 
91
91
  response_body = request.response.body
92
-
93
- if response_body.is_a?(Hash) && response_body['userId'].present? && response_body['token'].present?
94
- Wordnik.configuration.user_id = response_body['userId']
95
- Wordnik.configuration.auth_token = response_body['token']
96
- else
97
- raise AuthorizationError, request.response.raw.inspect
98
- end
92
+ Wordnik.configuration.user_id = response_body['userId']
93
+ Wordnik.configuration.auth_token = response_body['token']
99
94
  end
100
95
 
101
96
  end
102
97
 
103
98
  end
104
99
 
105
- class AuthorizationError < StandardError
100
+ class ServerError < StandardError
106
101
  end
107
102
 
108
- class ConfigurationError < StandardError
103
+ class ClientError < StandardError
109
104
  end
@@ -34,18 +34,12 @@ describe Wordnik::Response do
34
34
  VCR.use_cassette('unauthorized_response', :record => :new_episodes) do
35
35
  @unauthorized_raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.json/dog/images/flickr")
36
36
  end
37
- @response = Wordnik::Response.new(@unauthorized_raw)
38
- end
39
-
40
- it "sets a 401 status code" do
41
- @response.code.should == 401
42
37
  end
43
38
 
44
- it "raises an error when body is called" do
45
- expect { @response.body }.to raise_error(AuthorizationError)
39
+ it "raises an error when initialized" do
40
+ expect { Wordnik::Response.new(@unauthorized_raw) }.to raise_error(ClientError)
46
41
  end
47
42
 
48
-
49
43
  end
50
44
 
51
45
  describe "format" do
@@ -57,7 +51,7 @@ describe Wordnik::Response do
57
51
 
58
52
  it "recognizes xml" do
59
53
  VCR.use_cassette('xml_response_request', :record => :new_episodes) do
60
- @raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.xml/help")
54
+ @raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.xml")
61
55
  end
62
56
  @response = Wordnik::Response.new(@raw)
63
57
  @response.format.should == :xml
data/spec/wordnik_spec.rb CHANGED
@@ -55,7 +55,7 @@ describe Wordnik do
55
55
  config.password = 'wrong!'
56
56
  config.base_uri = "beta.wordnik.com/v4"
57
57
  end
58
- lambda { Wordnik.authenticate }.should raise_error(AuthorizationError)
58
+ expect { Wordnik.authenticate }.to raise_error(ClientError)
59
59
  Wordnik.authenticated?.should == false
60
60
  end
61
61
 
@@ -67,7 +67,7 @@ describe Wordnik do
67
67
  config.password = nil
68
68
  config.base_uri = "beta.wordnik.com/v4"
69
69
  end
70
- lambda { Wordnik.authenticate }.should raise_error(ConfigurationError, /username and password are required/i)
70
+ expect { Wordnik.authenticate }.to raise_error(ClientError, /username and password are required/i)
71
71
  Wordnik.authenticated?.should == false
72
72
  end
73
73
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wordnik
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 4.06.02
5
+ version: 4.06.04
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zeke Sikelianos
@@ -11,7 +11,8 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-12 00:00:00 Z
14
+ date: 2011-07-12 00:00:00 -07:00
15
+ default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: typhoeus
@@ -174,6 +175,7 @@ files:
174
175
  - spec/spec_helper.rb
175
176
  - spec/wordnik_spec.rb
176
177
  - wordnik.gemspec
178
+ has_rdoc: true
177
179
  homepage: http://developer.wordnik.com
178
180
  licenses: []
179
181
 
@@ -197,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
199
  requirements: []
198
200
 
199
201
  rubyforge_project: wordnik
200
- rubygems_version: 1.8.5
202
+ rubygems_version: 1.5.1
201
203
  signing_key:
202
204
  specification_version: 3
203
205
  summary: A ruby wrapper for the Wordnik API