hyperdrive 0.0.7 → 0.0.8

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: 0310c3ea9e2400fb9bb5527017453871e14b37e7
4
- data.tar.gz: 2e6ae40c0d160e91f9c5b71587d9c69c6741b760
3
+ metadata.gz: 6c23aaf5bdede85ba2269ab2a0baed51136d6a23
4
+ data.tar.gz: 3d944c9ca0fc9faada183ffc93d3b02829a05cb7
5
5
  SHA512:
6
- metadata.gz: 197285ed590fd3808b0fdec8f52418ef1bfaf6c55c7fd20dd8e5526450c37ffe4c99b127d8762212d46ca2a389472d7f821f2d0e1b1e082af9ffd73bc1b0458a
7
- data.tar.gz: 9b37a124b0a2da5911ce56b13b64b16f6c76af173c348c78c1cf986227c5580e2e2d6c58d86babf5e2be42708a2f2bc80671400f068f9b52d1a0b19a81e57b12
6
+ metadata.gz: 3ef076c40b1339ce9e2bd3243dc214c0cdb4f6d9340e8a71d98d0e1fa2befa60895b9b4adcc7a4df041f01453fc8ffbb0cc5c279be09ac1e6c9d137a2ed9663a
7
+ data.tar.gz: 4012e028e23f512d418486674755a29e87368c9d71c6f104a0ac815ba5466ef0ca2844d2b3ed1582466e983e9fadedac44493c76d5779c36d17a4d387e48f367
data/.travis.yml CHANGED
@@ -5,6 +5,9 @@ rvm:
5
5
  - 1.9.3
6
6
  - jruby-head
7
7
  - rbx
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: rbx
8
11
  env:
9
12
  global:
10
13
  secure: Tl3oBsBZRI5bMrtNH5mtTDvSTlTxNbsKaAnQ7KQ2KMyiH/eHolOSIbUYB9NB3GRMC6XSyFShRCaYPA/ET36HI+Jw3PFT/XADdiOdFqlk6VyJEUPznNQ1nlp8AsyNn+IexZXIl8DdqmZxGHlY6YKDbQV/U1v+FeW8X5j3TLN1mcw=
@@ -44,7 +44,7 @@ module Hyperdrive
44
44
  if json?
45
45
  MultiJson.dump(body)
46
46
  else
47
- $stderr.puts "can't serialize response automatically"
47
+ env['rack.errors'] << "ENDPOINT: Can't serialize response automatically"
48
48
  end
49
49
  when String
50
50
  body
@@ -53,6 +53,10 @@ module Hyperdrive
53
53
  end
54
54
  end
55
55
 
56
+ def self.error(status, message)
57
+ raise Errors::HTTPError.new(message, status)
58
+ end
59
+
56
60
  def self.status
57
61
  case env['REQUEST_METHOD']
58
62
  when 'POST'
@@ -1,13 +1,10 @@
1
1
  module Hyperdrive
2
2
  module Errors
3
3
  class BadRequest < HTTPError
4
- def message
5
- "The request cannot be fulfilled due to bad syntax."
6
- end
7
-
8
- def http_status_code
9
- 400
4
+ def initialize
5
+ @http_status_code = 400
6
+ @message = 'The request cannot be fulfilled due to bad syntax.'
10
7
  end
11
8
  end
12
9
  end
13
- end
10
+ end
@@ -3,13 +3,12 @@
3
3
  module Hyperdrive
4
4
  module Errors
5
5
  class HTTPError < RuntimeError
6
- def message
7
- 'Unknown Error.'
8
- end
9
-
10
- def http_status_code
11
- 500
6
+ attr_reader :http_status_code, :message
7
+ def initialize(message, http_status_code = 500)
8
+ @message = message
9
+ @http_status_code = http_status_code
12
10
  end
13
11
  end
14
12
  end
15
13
  end
14
+
@@ -1,13 +1,10 @@
1
1
  module Hyperdrive
2
2
  module Errors
3
3
  class InternalServerError < HTTPError
4
- def message
5
- "The server encountered an unexpected condition which prevented it from fulfilling the request."
6
- end
7
-
8
- def http_status_code
9
- 500
4
+ def initialize
5
+ @message = 'The server encountered an unexpected condition which prevented it from fulfilling the request.'
6
+ @http_status_code = 500
10
7
  end
11
8
  end
12
9
  end
13
- end
10
+ end
@@ -3,14 +3,8 @@ module Hyperdrive
3
3
  class MethodNotAllowed < HTTPError
4
4
  def initialize(request_method)
5
5
  @request_method = request_method
6
- end
7
-
8
- def message
9
- "#{@request_method.upcase} requests are not supported by this resource."
10
- end
11
-
12
- def http_status_code
13
- 405
6
+ @message = "#{request_method.upcase} requests are not supported by this resource."
7
+ @http_status_code = 405
14
8
  end
15
9
  end
16
10
  end
@@ -1,18 +1,9 @@
1
1
  module Hyperdrive
2
2
  module Errors
3
3
  class MissingRequiredParam < HTTPError
4
- attr_reader :param, :http_request_method
5
4
  def initialize(param, http_request_method)
6
- @param = param
7
- @http_request_method = http_request_method
8
- end
9
-
10
- def message
11
- "The #{param} param is required by #{http_request_method} requests."
12
- end
13
-
14
- def http_status_code
15
- 400
5
+ @message = "The #{param} param is required by #{http_request_method} requests."
6
+ @http_status_code = 400
16
7
  end
17
8
  end
18
9
  end
@@ -2,15 +2,8 @@ module Hyperdrive
2
2
  module Errors
3
3
  class NotAcceptable < HTTPError
4
4
  def initialize(http_accept)
5
- @http_accept = http_accept
6
- end
7
-
8
- def message
9
- "This resource is not capable of generating content in the format requested by the Accept headers (#{@http_accept})."
10
- end
11
-
12
- def http_status_code
13
- 406
5
+ @message = "This resource is not capable of generating content in the format requested by the Accept headers (#{http_accept})."
6
+ @http_status_code = 406
14
7
  end
15
8
  end
16
9
  end
@@ -1,13 +1,10 @@
1
1
  module Hyperdrive
2
2
  module Errors
3
3
  class NotFound < HTTPError
4
- def message
5
- "The requested resource could not be found."
6
- end
7
-
8
- def http_status_code
9
- 404
4
+ def initialize
5
+ @message = 'The requested resource could not be found.'
6
+ @http_status_code = 404
10
7
  end
11
8
  end
12
9
  end
13
- end
10
+ end
@@ -2,16 +2,9 @@ module Hyperdrive
2
2
  module Errors
3
3
  class NotImplemented < HTTPError
4
4
  def initialize(request_method)
5
- @request_method = request_method
6
- end
7
-
8
- def message
9
- "The server either does not recognise the request method (#{@request_method}), or it lacks the ability to fulfill the request."
10
- end
11
-
12
- def http_status_code
13
- 501
5
+ @message = "The server either does not recognise the request method (#{request_method}), or it lacks the ability to fulfill the request."
6
+ @http_status_code = 501
14
7
  end
15
8
  end
16
9
  end
17
- end
10
+ end
@@ -1,13 +1,10 @@
1
1
  module Hyperdrive
2
2
  module Errors
3
3
  class Unauthorized < HTTPError
4
- def message
5
- "The request requires user authentication."
6
- end
7
-
8
- def http_status_code
9
- 401
4
+ def initialize
5
+ @message = 'The request requires user authentication.'
6
+ @http_status_code = 401
10
7
  end
11
8
  end
12
9
  end
13
- end
10
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Hyperdrive
4
+ module Errors
5
+ class UnknownError < HTTPError
6
+ def initialize
7
+ @http_status_code = 500
8
+ @message = 'Unknown Error.'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@
4
4
  require 'hyperdrive/errors/dsl/unknown_argument'
5
5
 
6
6
  # HTTP Errors
7
- require 'hyperdrive/errors/http_error' # 500 (Catch All)
7
+ require 'hyperdrive/errors/http_error'
8
8
  require 'hyperdrive/errors/bad_request' # 400 (Generic)
9
9
  require 'hyperdrive/errors/internal_server_error' # 500 (Generic)
10
10
  require 'hyperdrive/errors/method_not_allowed' # 405
@@ -13,3 +13,4 @@ require 'hyperdrive/errors/not_acceptable' # 406
13
13
  require 'hyperdrive/errors/not_found' # 404
14
14
  require 'hyperdrive/errors/not_implemented' # 501
15
15
  require 'hyperdrive/errors/unauthorized' # 401
16
+ require 'hyperdrive/errors/unknown_error' # 500 (Catch All)
@@ -19,7 +19,7 @@ module Hyperdrive
19
19
  else
20
20
  env['rack.errors'] << e
21
21
  status = 500
22
- body = json_error(Hyperdrive::Errors::HTTPError.new)
22
+ body = json_error(Hyperdrive::Errors::UnknownError.new)
23
23
  end
24
24
  [status, headers, body]
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Hyperdrive
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -19,4 +19,15 @@ describe Hyperdrive::Endpoint do
19
19
  get '/', {}, default_rack_env(hyperdrive.resources[:thing])
20
20
  last_response.successful?.must_equal true
21
21
  end
22
+
23
+ it "can raise an HTTPError" do
24
+ hyperdrive do
25
+ resource(:thing) do
26
+ request(:get) do
27
+ error(418, "I'M A TEAPOT")
28
+ end
29
+ end
30
+ end
31
+ ->{ get '/', {}, default_rack_env(hyperdrive.resources[:thing]) }.must_raise Hyperdrive::Errors::HTTPError
32
+ end
22
33
  end
@@ -4,14 +4,15 @@ require 'spec_helper'
4
4
 
5
5
  describe Hyperdrive::Errors::HTTPError do
6
6
  before do
7
- @error = Hyperdrive::Errors::HTTPError.new
7
+ @error = Hyperdrive::Errors::HTTPError.new("I'M A TEAPOT", 418)
8
8
  end
9
9
 
10
10
  it "returns a 500 status code" do
11
- @error.http_status_code.must_equal 500
11
+ @error.http_status_code.must_equal 418
12
12
  end
13
13
 
14
14
  it "has a message" do
15
- @error.message.must_match(/Unknown/)
15
+ @error.message.must_match(/TEAPOT/)
16
16
  end
17
17
  end
18
+
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Hyperdrive::Errors::UnknownError do
6
+ before do
7
+ @error = Hyperdrive::Errors::UnknownError.new
8
+ end
9
+
10
+ it "returns a 500 status code" do
11
+ @error.http_status_code.must_equal 500
12
+ end
13
+
14
+ it "has a message" do
15
+ @error.message.must_match(/Unknown/)
16
+ end
17
+ end
@@ -6,7 +6,7 @@ describe Hyperdrive::Middleware::Error do
6
6
  before do
7
7
  get '/'
8
8
  end
9
-
9
+
10
10
  context "Known Error" do
11
11
  def app
12
12
  Rack::Builder.new do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperdrive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - StyleSeek Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linguistics
@@ -142,6 +142,7 @@ files:
142
142
  - lib/hyperdrive/errors/not_found.rb
143
143
  - lib/hyperdrive/errors/not_implemented.rb
144
144
  - lib/hyperdrive/errors/unauthorized.rb
145
+ - lib/hyperdrive/errors/unknown_error.rb
145
146
  - lib/hyperdrive/filter.rb
146
147
  - lib/hyperdrive/hateoas.rb
147
148
  - lib/hyperdrive/middleware.rb
@@ -174,6 +175,7 @@ files:
174
175
  - spec/hyperdrive/errors/not_found_spec.rb
175
176
  - spec/hyperdrive/errors/not_implemented_spec.rb
176
177
  - spec/hyperdrive/errors/unauthorized_spec.rb
178
+ - spec/hyperdrive/errors/unknown_error_spec.rb
177
179
  - spec/hyperdrive/filter_spec.rb
178
180
  - spec/hyperdrive/hateoas_spec.rb
179
181
  - spec/hyperdrive/middleware/accept_spec.rb
@@ -230,6 +232,7 @@ test_files:
230
232
  - spec/hyperdrive/errors/not_found_spec.rb
231
233
  - spec/hyperdrive/errors/not_implemented_spec.rb
232
234
  - spec/hyperdrive/errors/unauthorized_spec.rb
235
+ - spec/hyperdrive/errors/unknown_error_spec.rb
233
236
  - spec/hyperdrive/filter_spec.rb
234
237
  - spec/hyperdrive/hateoas_spec.rb
235
238
  - spec/hyperdrive/middleware/accept_spec.rb