lexile 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lexile.gemspec +1 -1
- data/lib/lexile/api/client.rb +23 -23
- data/lib/lexile/errors.rb +10 -5
- data/lib/lexile/version.rb +1 -1
- data/spec/lexile/api/client_spec.rb +7 -3
- data/spec/lexile/errors_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f18c141815d88e2cf3f680ef9a5574921b1e1fe0
|
4
|
+
data.tar.gz: 3b63df5a1c0f140e39ce958858e12d5c0d122922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148803341b89cd457a1e62f172133a236cd8e3c1aaed9f0c5acebe20a16f7475c0093d1fec6e3f291c6d86a6359bddd23e4046e737f327f02542aa275d38ba3a
|
7
|
+
data.tar.gz: 73abd89e69b0cd610ef574eb4204e1d786d8ba0d54100ea2f77134d77079793f3bef0333f9f114128678eadf9a1c9b48ba63581916511ef9a5c53d150b11d088
|
data/lexile.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
|
10
10
|
spec.authors = ["Mauricio Alvarez"]
|
11
11
|
spec.email = ["mauricio@curriculet.com"]
|
12
|
-
spec.date =
|
12
|
+
spec.date = Date.today
|
13
13
|
spec.description = "A gem for the Lexile® database API "
|
14
14
|
spec.summary = "A gem to find a book's Lexile DB entry by name or ISBN13"
|
15
15
|
spec.homepage = "https://github.com/curriculet/lexile"
|
data/lib/lexile/api/client.rb
CHANGED
@@ -21,7 +21,7 @@ module Lexile
|
|
21
21
|
|
22
22
|
if configuration.is_a?(Module) && configuration.to_s == 'Lexile'
|
23
23
|
config = configuration
|
24
|
-
else
|
24
|
+
else
|
25
25
|
if configuration.is_a?(Hash)
|
26
26
|
config = Hashie::Mash.new( configuration )
|
27
27
|
config.api_url = [config.endpoint,config.api_version].join('/')
|
@@ -47,32 +47,32 @@ module Lexile
|
|
47
47
|
# @return [String]. The raw response body (JSON is expected) Raises appropriate exception if it fails
|
48
48
|
# @raise Lexile::HTTPError when any HTTP error response is received
|
49
49
|
def get( path, params={}, headers={})
|
50
|
-
|
50
|
+
|
51
51
|
get_args = build_get_args( params, headers)
|
52
|
-
|
53
|
-
yield get_args if block_given?
|
54
|
-
|
52
|
+
|
53
|
+
yield get_args if block_given?
|
54
|
+
|
55
55
|
#puts "CALLING API: #{Lexile.api_url}#{path} ===#{get_args}"
|
56
56
|
response = self.class.get( path, get_args)
|
57
57
|
|
58
58
|
case response.code
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
59
|
+
when 200..201
|
60
|
+
response
|
61
|
+
JSON.parse( response.body )
|
62
|
+
when 400
|
63
|
+
raise Lexile::BadRequest.new(response, params)
|
64
|
+
when 401
|
65
|
+
raise Lexile::AuthenticationFailed.new(response, params)
|
66
|
+
when 404
|
67
|
+
raise Lexile::NotFound.new(response, params)
|
68
|
+
when 429
|
69
|
+
raise Lexile::TooManyRequests.new(response, params)
|
70
|
+
when 500
|
71
|
+
raise Lexile::ServerError.new(response, params)
|
72
|
+
when 502, 503, 504
|
73
|
+
raise Lexile::Unavailable.new(response, params)
|
74
|
+
else
|
75
|
+
raise Lexile::UnknownStatusCode.new(response, params)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -96,7 +96,7 @@ module Lexile
|
|
96
96
|
get_args[:query] = query
|
97
97
|
get_args[:headers] = headers
|
98
98
|
get_args[:basic_auth] = { username: Lexile.options[:username],
|
99
|
-
|
99
|
+
password: Lexile.options[:password]}
|
100
100
|
get_args
|
101
101
|
end
|
102
102
|
end
|
data/lib/lexile/errors.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Lexile
|
2
|
-
class
|
3
|
-
class
|
2
|
+
class Error < ::StandardError; end
|
3
|
+
class InvalidCredentials < Error; end
|
4
|
+
class CannotProcessResponse < Error; end
|
4
5
|
|
5
|
-
class HTTPError <
|
6
|
+
class HTTPError < Error
|
6
7
|
attr_reader :response
|
7
8
|
attr_reader :params
|
8
9
|
|
@@ -12,8 +13,12 @@ module Lexile
|
|
12
13
|
super(response)
|
13
14
|
end
|
14
15
|
|
16
|
+
def composed_message
|
17
|
+
"#{self.class.to_s} request_params: #{@params} response_status_code: #{@response.code} response_headers:#{@response.headers}"
|
18
|
+
end
|
19
|
+
|
15
20
|
def to_s
|
16
|
-
|
21
|
+
composed_message
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
@@ -22,6 +27,6 @@ module Lexile
|
|
22
27
|
class BadRequest < HTTPError; end
|
23
28
|
class ServerError < HTTPError; end
|
24
29
|
class AuthenticationFailed < HTTPError; end
|
25
|
-
class
|
30
|
+
class TooManyRequests < HTTPError; end
|
26
31
|
class UnknownStatusCode < HTTPError; end
|
27
32
|
end
|
data/lib/lexile/version.rb
CHANGED
@@ -80,14 +80,18 @@ describe Lexile::API::Client do
|
|
80
80
|
{status: 400, ex: Lexile::BadRequest },
|
81
81
|
{status: 401, ex: Lexile::AuthenticationFailed},
|
82
82
|
{status: 404, ex: Lexile::NotFound},
|
83
|
+
{status: 429, ex: Lexile::TooManyRequests},
|
83
84
|
{status: 500, ex: Lexile::ServerError},
|
84
85
|
{status: 502, ex: Lexile::Unavailable},
|
85
|
-
{status: 503, ex: Lexile::
|
86
|
-
{status: 504, ex: Lexile::
|
86
|
+
{status: 503, ex: Lexile::Unavailable},
|
87
|
+
{status: 504, ex: Lexile::Unavailable},
|
87
88
|
{status: 999, ex: Lexile::UnknownStatusCode}
|
88
89
|
].each do |test_args|
|
89
90
|
it "should raise #{test_args[:ex].name} when status code is #{test_args[:status]}" do
|
90
|
-
|
91
|
+
mock = double
|
92
|
+
mock.stub(:code){test_args[:status]}
|
93
|
+
mock.stub(:headers){ "Some Headers From The Request"}
|
94
|
+
client.class.stub(:get){ mock }
|
91
95
|
expect{
|
92
96
|
client.get("/something")
|
93
97
|
}.to raise_error test_args[:ex]
|
data/spec/lexile/errors_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Lexile::HTTPError do
|
4
4
|
let(:response){
|
5
5
|
mock_response = double()
|
6
|
-
mock_response.stub(:code){
|
7
|
-
mock_response.stub(:
|
6
|
+
mock_response.stub(:code){ 429 }
|
7
|
+
mock_response.stub(:headers){ "Some Headers" }
|
8
8
|
mock_response
|
9
9
|
}
|
10
10
|
|
@@ -12,7 +12,7 @@ describe Lexile::HTTPError do
|
|
12
12
|
|
13
13
|
it "should format correctly as a string" do
|
14
14
|
subject.to_s.should match /Lexile::HTTPError/
|
15
|
-
subject.to_s.should match /
|
16
|
-
subject.to_s.should match /
|
15
|
+
subject.to_s.should match /429/
|
16
|
+
subject.to_s.should match /Some Headers/
|
17
17
|
end
|
18
18
|
end
|