restfulness 0.2.4 → 0.2.5
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/README.md +41 -21
- data/lib/restfulness/router.rb +10 -2
- data/lib/restfulness/version.rb +1 -1
- data/spec/unit/router_spec.rb +41 -1
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2ec8e38fd8c7293981c340ac6e925b976f4a99
|
4
|
+
data.tar.gz: e74639ca882ffea8494af1f6dc2e0a7c970b5957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc120a4ca69100131aef149de8e0029611c2e1d5ed584a94a3adabbf50e598ab52463088884c6844e5008c375632cb64cb3df7a69afbf7f4b62a38cbe64bdf01
|
7
|
+
data.tar.gz: 19e0694cd4b9f4b609762c70abdd07c9d2df487b65bb4884ccf8097b3c3ae59423cc6a0b4e13f496a7109b84162caa618ba96fade17c5b07a9e26f70cca686ad
|
data/README.md
CHANGED
@@ -59,8 +59,10 @@ Restfulness takes a different approach. The following example attempts to show h
|
|
59
59
|
class TwitterAPI < Restfullness::Application
|
60
60
|
routes do
|
61
61
|
add 'status', StatusResource
|
62
|
-
|
63
|
-
|
62
|
+
scope 'timeline' do
|
63
|
+
add 'public', Timelines::PublicResource
|
64
|
+
add 'home', Timelines::HomeResource
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -70,19 +72,21 @@ class StatusResource < Restfulness::Resource
|
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
module Timelines
|
76
|
+
class PublicResource < Restfulness::Resource
|
77
|
+
def get
|
78
|
+
Status.limit(20)
|
79
|
+
end
|
76
80
|
end
|
77
|
-
end
|
78
81
|
|
79
|
-
# Authentication requires more cowbell, so assume the ApplicationResource is already defined
|
80
|
-
class
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
# Authentication requires more cowbell, so assume the ApplicationResource is already defined
|
83
|
+
class HomeResource < ApplicationResource
|
84
|
+
def authorized?
|
85
|
+
authenticate!
|
86
|
+
end
|
87
|
+
def get
|
88
|
+
current_user.statuses.limit(20)
|
89
|
+
end
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
@@ -156,19 +160,31 @@ The aim of routes in Restfulness are to be stupid simple. These are the basic ru
|
|
156
160
|
* Strings are matched directly.
|
157
161
|
* Symbols match anything, and are accessible as path attributes.
|
158
162
|
* Every route automically gets an :id parameter at the end, that may or may not have a null value.
|
163
|
+
* Scopes save repeating shared route array entries.
|
159
164
|
|
160
165
|
Lets see a few examples:
|
161
166
|
|
162
167
|
```ruby
|
163
168
|
routes do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
scope 'api' do
|
170
|
+
# Simple route to access a project, access with:
|
171
|
+
# * PUT /api/project
|
172
|
+
# * GET /api/project/1234
|
173
|
+
add 'project', ProjectResource
|
174
|
+
|
175
|
+
# Parameters are also supported.
|
176
|
+
# Access the project id using `request.path[:project_id]`
|
177
|
+
add 'project', :project_id, 'status', ProjectStatusResource
|
178
|
+
|
179
|
+
# Scope's can be embedded
|
180
|
+
scope 'journeys' do
|
181
|
+
add 'active', Journeys::ActiveResource
|
182
|
+
add 'terminated', Journeys::TerminatedResource
|
183
|
+
end
|
184
|
+
|
185
|
+
# Add a general purpose list resource *after* scope
|
186
|
+
add 'journeys', Journeys::ListResource
|
187
|
+
end
|
172
188
|
end
|
173
189
|
```
|
174
190
|
|
@@ -589,6 +605,10 @@ Restfulness is still a work in progress but at Cabify we are using it in product
|
|
589
605
|
|
590
606
|
## History
|
591
607
|
|
608
|
+
### 0.2.5 - March 7, 2014
|
609
|
+
|
610
|
+
* Added support for scope in routes. (@samlown)
|
611
|
+
|
592
612
|
### 0.2.4 - February 7, 2014
|
593
613
|
|
594
614
|
* Added I18n support with the help of the http_accept_language gem. (@samlown)
|
data/lib/restfulness/router.rb
CHANGED
@@ -3,15 +3,23 @@ module Restfulness
|
|
3
3
|
|
4
4
|
class Router
|
5
5
|
|
6
|
-
attr_accessor :routes
|
6
|
+
attr_accessor :routes, :current_scope
|
7
7
|
|
8
8
|
def initialize(&block)
|
9
9
|
self.routes = []
|
10
|
+
self.current_scope = []
|
10
11
|
instance_eval(&block) if block_given?
|
11
12
|
end
|
12
13
|
|
13
14
|
def add(*args)
|
14
|
-
routes << Route.new(*args)
|
15
|
+
routes << Route.new(*(current_scope + args))
|
16
|
+
end
|
17
|
+
|
18
|
+
def scope(*args, &block)
|
19
|
+
old_scope = current_scope
|
20
|
+
self.current_scope += args
|
21
|
+
instance_eval(&block) if block_given?
|
22
|
+
self.current_scope = old_scope
|
15
23
|
end
|
16
24
|
|
17
25
|
def route_for(path)
|
data/lib/restfulness/version.rb
CHANGED
data/spec/unit/router_spec.rb
CHANGED
@@ -22,7 +22,6 @@ describe Restfulness::Router do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should prepare routes with instance eval block" do
|
25
|
-
block = lambda {}
|
26
25
|
obj = klass.new do
|
27
26
|
@foo = 'bar'
|
28
27
|
end
|
@@ -42,6 +41,47 @@ describe Restfulness::Router do
|
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
44
|
+
describe "#scope" do
|
45
|
+
it "should append to the current_scope attribute in block and reset" do
|
46
|
+
obj = klass.new
|
47
|
+
subscope = nil # Can't use rspec inside instance eval!
|
48
|
+
obj.scope 'api' do
|
49
|
+
subscope = current_scope
|
50
|
+
end
|
51
|
+
subscope.should eql(['api'])
|
52
|
+
obj.current_scope.should eql([])
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should add scope properties to add call" do
|
56
|
+
obj = klass.new
|
57
|
+
res = resource
|
58
|
+
obj.scope 'api' do
|
59
|
+
add 'projects', res
|
60
|
+
end
|
61
|
+
route = obj.routes.first
|
62
|
+
route.path.should eql(['api', 'projects'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should allow for scopes within scopes" do
|
66
|
+
obj = klass.new
|
67
|
+
res = resource
|
68
|
+
subscope = nil
|
69
|
+
subsubscope = nil
|
70
|
+
obj.scope 'api' do
|
71
|
+
scope 'projects' do
|
72
|
+
add 'active', res
|
73
|
+
subsubscope = current_scope
|
74
|
+
end
|
75
|
+
subscope = current_scope
|
76
|
+
end
|
77
|
+
subsubscope.should eql(['api', 'projects'])
|
78
|
+
subscope.should eql(['api'])
|
79
|
+
obj.current_scope.should eql([])
|
80
|
+
route = obj.routes.first
|
81
|
+
route.path.should eql(['api', 'projects', 'active'])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
45
85
|
describe "#route_for" do
|
46
86
|
let :obj do
|
47
87
|
res = resource
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfulness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Lown
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: http_accept_language
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Simple REST server that focuses on resources instead of routes.
|
@@ -115,8 +115,8 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .travis.yml
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
120
|
- Gemfile
|
121
121
|
- LICENSE.txt
|
122
122
|
- README.md
|
@@ -164,17 +164,17 @@ require_paths:
|
|
164
164
|
- lib
|
165
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
166
|
requirements:
|
167
|
-
- -
|
167
|
+
- - ">="
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - ">="
|
173
173
|
- !ruby/object:Gem::Version
|
174
174
|
version: '0'
|
175
175
|
requirements: []
|
176
176
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.2.2
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Use to create a powerful, yet simple REST API in your application.
|