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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec9cd6a42b9a06b46c1b02c746df407e2da081d0
4
- data.tar.gz: 637458a662c8f341512e0e62c2294729d895505f
3
+ metadata.gz: f18c141815d88e2cf3f680ef9a5574921b1e1fe0
4
+ data.tar.gz: 3b63df5a1c0f140e39ce958858e12d5c0d122922
5
5
  SHA512:
6
- metadata.gz: 44b1ed9e6886a095ab54d87934f7c64b99eb71517cee1404262b11e6814cbefe0bfab27c125e9d1a147cddad0be6e9e3d7c24aa6e4e536cc2ada68c181c0eda9
7
- data.tar.gz: 897342499b5591b21b8e84cea75e1a9e6a356ffae0b640ba85aa468dcf7bbc7913b052016d3d29d1187fc3a6f2abfd09130af33e03c96bdc3c432e9b569d226b
6
+ metadata.gz: 148803341b89cd457a1e62f172133a236cd8e3c1aaed9f0c5acebe20a16f7475c0093d1fec6e3f291c6d86a6359bddd23e4046e737f327f02542aa275d38ba3a
7
+ data.tar.gz: 73abd89e69b0cd610ef574eb4204e1d786d8ba0d54100ea2f77134d77079793f3bef0333f9f114128678eadf9a1c9b48ba63581916511ef9a5c53d150b11d088
@@ -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 = "2015-08-06"
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"
@@ -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
- 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 500
69
- raise Lexile::ServerError.new(response, params)
70
- when 502
71
- raise Lexile::Unavailable.new(response, params)
72
- when 503, 504
73
- raise Lexile::RateLimited.new(response, params)
74
- else
75
- raise Lexile::UnknownStatusCode.new(response, params)
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
- password: Lexile.options[:password]}
99
+ password: Lexile.options[:password]}
100
100
  get_args
101
101
  end
102
102
  end
@@ -1,8 +1,9 @@
1
1
  module Lexile
2
- class InvalidCredentials < StandardError; end
3
- class CannotProcessResponse < StandardError; end
2
+ class Error < ::StandardError; end
3
+ class InvalidCredentials < Error; end
4
+ class CannotProcessResponse < Error; end
4
5
 
5
- class HTTPError < StandardError
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
- "#{self.class.to_s} : #{response.code} #{response.body}"
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 RateLimited < HTTPError; end
30
+ class TooManyRequests < HTTPError; end
26
31
  class UnknownStatusCode < HTTPError; end
27
32
  end
@@ -1,3 +1,3 @@
1
1
  module Lexile
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -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::RateLimited},
86
- {status: 504, ex: Lexile::RateLimited},
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
- client.class.stub(:get){ mock = double; mock.stub(:code){test_args[:status]}; mock }
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]
@@ -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){ 259 }
7
- mock_response.stub(:body){"<html><head></head><body>Hello World!</body></html>"}
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 /259/
16
- subject.to_s.should match /Hello World/
15
+ subject.to_s.should match /429/
16
+ subject.to_s.should match /Some Headers/
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lexile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Alvarez