sliver 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20b809608f86609cc795b28a114f3c812dec65e8
4
- data.tar.gz: 4bf292bffbc5d19991d0fa7e29d2ced1005b6732
3
+ metadata.gz: 1f21cd8c5684c1df5a750b1fcde9d8686c201e78
4
+ data.tar.gz: dcbb2635b735629e359ed533049d13f6cc5eec79
5
5
  SHA512:
6
- metadata.gz: 6f33a1f81c5222b877ef334d98f386abc7d1c64bc47d8e97587e533ebfcaefaf7ae0ebb774434ac305b8049d624522121a08c154eb893cb8de13432b3fd7cc96
7
- data.tar.gz: c2496802b022d43a351ef992c38188f61f2f170e8ad52abe1c4f3e562a6012c332f2521fd76c29085ea418f884ce2f449cd4d1b22827b262d1c877cc521cad53
6
+ metadata.gz: 98a1a1a0d96f341afe028cc3125e4b05591688e645fea36457e23c87aa8b2ec0ae0522e271d4863705ad7551da72dc8713389371dbe939e6ba71f6ca0a1168a8
7
+ data.tar.gz: 75de6c573a1299a6ca44317c1701dcb19acc411ac385860475815212547730b6df2fcc5b79434614f7895669892bf0aa1e3c46e3e05cdbe83dfc5dac4cd8288e
data/README.md CHANGED
@@ -11,7 +11,7 @@ Early days of development, so things may change dramatically. Or not. Who knows.
11
11
  Add it to your Gemfile like any other gem, or install it manually.
12
12
 
13
13
  ```ruby
14
- gem 'sliver', '~> 0.0.2'
14
+ gem 'sliver', '~> 0.0.3'
15
15
  ```
16
16
 
17
17
  ## Usage
@@ -30,9 +30,6 @@ the standard Rack response. Each instance of a class that mixes in
30
30
 
31
31
  ```ruby
32
32
  app = Sliver::API.new do |api|
33
- #Endpoints can be namespaced by a path - for example, a version.
34
- api.path = '/v1'
35
-
36
33
  # GET /v1/
37
34
  api.connect :get, '/', lambda { |environment|
38
35
  [200, {}, ['How dare the Premier ignore my invitations?']]
@@ -45,6 +42,18 @@ end
45
42
  class ChangeAction
46
43
  include Sliver::Action
47
44
 
45
+ # You don't *need* to implement this method - the underlying implementation
46
+ # returns false.
47
+ def skip?
48
+ return false unless environment['user'].nil?
49
+
50
+ # In this case, the call method is never invoked.
51
+ response.status = 401
52
+ response.body = ['Unauthorised']
53
+
54
+ true
55
+ end
56
+
48
57
  def call
49
58
  # Change the status:
50
59
  response.status = 404
@@ -6,7 +6,9 @@ module Sliver::Action
6
6
  module ClassMethods
7
7
  def call(environment)
8
8
  response = Sliver::Response.new
9
- new(environment, response).call
9
+
10
+ action = new(environment, response)
11
+ action.call unless action.skip?
10
12
 
11
13
  response.to_a
12
14
  end
@@ -16,6 +18,10 @@ module Sliver::Action
16
18
  @environment, @response = environment, response
17
19
  end
18
20
 
21
+ def skip?
22
+ false
23
+ end
24
+
19
25
  private
20
26
 
21
27
  attr_reader :environment, :response
@@ -1,19 +1,16 @@
1
1
  class Sliver::API
2
2
  NOT_FOUND = lambda { |environment| [404, {}, ['Not Found']] }
3
3
 
4
- attr_accessor :path
5
-
6
4
  def initialize(&block)
7
5
  @endpoints = Hash.new { |hash, key| hash[key] = Sliver::Endpoints.new }
8
- @path = ''
9
6
 
10
7
  block.call self
11
8
  end
12
9
 
13
10
  def call(environment)
14
- method = environment['REQUEST_METHOD']
15
- path_info = environment['PATH_INFO'].gsub(/\A#{path}/, '')
16
- endpoint = endpoints[method].find(path_info) || NOT_FOUND
11
+ method = environment['REQUEST_METHOD']
12
+ path = environment['PATH_INFO']
13
+ endpoint = endpoints[method].find(path) || NOT_FOUND
17
14
 
18
15
  endpoint.call environment
19
16
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'sliver'
4
- spec.version = '0.0.2'
4
+ spec.version = '0.0.3'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = %q{Lightweight, simple Rack APIs}
@@ -28,6 +28,20 @@ class AdditionAction
28
28
  end
29
29
  end
30
30
 
31
+ class SkippedAction
32
+ include Sliver::Action
33
+
34
+ def skip?
35
+ response.status = 400
36
+ response.body = ['Invalid']
37
+ end
38
+
39
+ def call
40
+ response.status = 200
41
+ response.body = ['Success']
42
+ end
43
+ end
44
+
31
45
  describe 'Class-based Sliver API' do
32
46
  include Rack::Test::Methods
33
47
 
@@ -35,6 +49,7 @@ describe 'Class-based Sliver API' do
35
49
  api.connect :get, '/', GetAction
36
50
  api.connect :put, '/echo', EchoAction
37
51
  api.connect :get, '/addition', AdditionAction
52
+ api.connect :get, '/skip', SkippedAction
38
53
  end }
39
54
 
40
55
  it 'constructs responses' do
@@ -56,4 +71,11 @@ describe 'Class-based Sliver API' do
56
71
 
57
72
  expect(last_response.body).to eq('8')
58
73
  end
74
+
75
+ it 'allows standard responses to be skipped' do
76
+ get '/skip'
77
+
78
+ expect(last_response.status).to eq(400)
79
+ expect(last_response.body).to eq('Invalid')
80
+ end
59
81
  end
@@ -55,21 +55,3 @@ describe 'Basic Sliver API' do
55
55
  expect(last_response.body).to eq('removed')
56
56
  end
57
57
  end
58
-
59
- describe 'Basic lambda API with a path prefix' do
60
- include Rack::Test::Methods
61
-
62
- let(:app) { Sliver::API.new do |api|
63
- api.path = '/v1'
64
-
65
- api.connect :get, '/', lambda { |environment|
66
- [200, {'Content-Type' => 'text/plain'}, ['foo']]
67
- }
68
- end }
69
-
70
- it 'responds to GET requests' do
71
- get '/v1/'
72
-
73
- expect(last_response.body).to eq('foo')
74
- end
75
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sliver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -102,4 +102,3 @@ test_files:
102
102
  - spec/acceptance/class_api_spec.rb
103
103
  - spec/acceptance/lambda_api_spec.rb
104
104
  - spec/spec_helper.rb
105
- has_rdoc: