rest_shifter 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CHANGES +15 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +92 -0
- data/LICENSE +202 -0
- data/README.md +75 -0
- data/Rakefile +14 -0
- data/bin/rest_shifter +4 -0
- data/lib/rest_shifter/commands/help.rb +22 -0
- data/lib/rest_shifter/commands/main.rb +26 -0
- data/lib/rest_shifter/commands/version.rb +7 -0
- data/lib/rest_shifter/commands.rb +2 -0
- data/lib/rest_shifter/shifter.rb +38 -0
- data/lib/rest_shifter/version.rb +3 -0
- data/lib/rest_shifter.rb +21 -0
- data/rest_shifter.gemspec +37 -0
- data/spec/flavors/notfound_get.flavor +7 -0
- data/spec/flavors/notfound_post.flavor +7 -0
- data/spec/flavors/success_get.flavor +21 -0
- data/spec/flavors/success_post.flavor +7 -0
- data/spec/service_spec.rb +52 -0
- data/spec/spec_helper.rb +19 -0
- metadata +230 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13a959670c52e25b96fccb8353044bde666e0daa
|
4
|
+
data.tar.gz: 161ebf3ca1d3e620651262ced5b6c1ce2615dc8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3d7c8e8abbd522ba5fdc71fdc858776bf0c07e75642d0e7f4279122e72c658de85780a73fc9ec797d6835089f29df91e8eb827e5fac91dae81b5bbc62f74e3f
|
7
|
+
data.tar.gz: 03fb753b4f339f4baa1407d79e50ba76a20ede9794d00bc620e1c0f07e9b0998a629eef87e4359a1b5184b2306c0639f8e03576fee448306b634723076b77338
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247@restshifter
|
data/.travis.yml
ADDED
data/CHANGES
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
** 0.0.3
|
3
|
+
- Algorithm improvements and big renaming:
|
4
|
+
-- Adding a customizable algorithm that will allow to take decisions based on headers for routing
|
5
|
+
- First version that includes cli:
|
6
|
+
-- Renaming to follow recommended gem naming
|
7
|
+
-- First version of the cli with help, verion e fallback to help
|
8
|
+
|
9
|
+
** 0.0.2
|
10
|
+
- First version that inclues:
|
11
|
+
-- Basic request with body, content-type and accept, for both, post and get operations
|
12
|
+
|
13
|
+
** 0.0.1
|
14
|
+
- First version that inclues:
|
15
|
+
-- Basic request with body for get operations
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rest_shifter (0.0.3)
|
5
|
+
icecream
|
6
|
+
sinatra
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
builder (3.2.2)
|
12
|
+
coderay (1.1.0)
|
13
|
+
coveralls (0.7.9)
|
14
|
+
multi_json (~> 1.10)
|
15
|
+
rest-client (~> 1.7)
|
16
|
+
simplecov (~> 0.9.1)
|
17
|
+
term-ansicolor (~> 1.3)
|
18
|
+
thor (~> 0.19.1)
|
19
|
+
cucumber (1.3.19)
|
20
|
+
builder (>= 2.1.2)
|
21
|
+
diff-lcs (>= 1.1.3)
|
22
|
+
gherkin (~> 2.12)
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
24
|
+
multi_test (>= 0.1.2)
|
25
|
+
diff-lcs (1.2.5)
|
26
|
+
docile (1.1.5)
|
27
|
+
gherkin (2.12.2)
|
28
|
+
multi_json (~> 1.3)
|
29
|
+
icecream (0.0.14)
|
30
|
+
method_source (0.8.2)
|
31
|
+
mime-types (2.4.3)
|
32
|
+
multi_json (1.10.1)
|
33
|
+
multi_test (0.1.2)
|
34
|
+
netrc (0.10.2)
|
35
|
+
nyan-cat-formatter (0.11)
|
36
|
+
rspec (>= 2.99, >= 2.14.2, < 4)
|
37
|
+
pry (0.10.1)
|
38
|
+
coderay (~> 1.1.0)
|
39
|
+
method_source (~> 0.8.1)
|
40
|
+
slop (~> 3.4)
|
41
|
+
rack (1.6.0)
|
42
|
+
rack-protection (1.5.3)
|
43
|
+
rack
|
44
|
+
rack-test (0.6.3)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rake (10.4.2)
|
47
|
+
rest-client (1.7.2)
|
48
|
+
mime-types (>= 1.16, < 3.0)
|
49
|
+
netrc (~> 0.7)
|
50
|
+
rspec (3.2.0)
|
51
|
+
rspec-core (~> 3.2.0)
|
52
|
+
rspec-expectations (~> 3.2.0)
|
53
|
+
rspec-mocks (~> 3.2.0)
|
54
|
+
rspec-core (3.2.0)
|
55
|
+
rspec-support (~> 3.2.0)
|
56
|
+
rspec-expectations (3.2.0)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.2.0)
|
59
|
+
rspec-mocks (3.2.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.2.0)
|
62
|
+
rspec-support (3.2.1)
|
63
|
+
simplecov (0.9.1)
|
64
|
+
docile (~> 1.1.0)
|
65
|
+
multi_json (~> 1.0)
|
66
|
+
simplecov-html (~> 0.8.0)
|
67
|
+
simplecov-html (0.8.0)
|
68
|
+
sinatra (1.4.5)
|
69
|
+
rack (~> 1.4)
|
70
|
+
rack-protection (~> 1.4)
|
71
|
+
tilt (~> 1.3, >= 1.3.4)
|
72
|
+
slop (3.6.0)
|
73
|
+
term-ansicolor (1.3.0)
|
74
|
+
tins (~> 1.0)
|
75
|
+
thor (0.19.1)
|
76
|
+
tilt (1.4.1)
|
77
|
+
tins (1.3.4)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
coveralls
|
84
|
+
cucumber
|
85
|
+
nyan-cat-formatter
|
86
|
+
pry
|
87
|
+
rack-test
|
88
|
+
rake
|
89
|
+
rest-client
|
90
|
+
rest_shifter!
|
91
|
+
rspec
|
92
|
+
simplecov
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
202
|
+
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# RestShifter
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/RestShifter.png)](https://rubygems.org/gems/RestShifter)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/camiloribeiro/RestShifter.png)](http://travis-ci.org/camiloribeiro/RestShifter)
|
5
|
+
[![endorse](https://api.coderwall.com/camiloribeiro/endorsecount.png)](https://coderwall.com/camiloribeiro)
|
6
|
+
|
7
|
+
|
8
|
+
/
|
9
|
+
__ // The rest api ShapeShifter!
|
10
|
+
-\= \=\ //
|
11
|
+
--=_\=---//=-- This is a Sinatra app with no predefined routes.
|
12
|
+
-_==/ \/ //\/-- This replaces mocks for integration level tests.
|
13
|
+
==/ /O O\==-- This can be used also to create tests for new feature
|
14
|
+
_ _ _ _ /_/ \ ] /-- before the dependent services are in place
|
15
|
+
/\ ( (- \ / ] ] ]==- This can also be used for Rest prototipation
|
16
|
+
(\ _\_\_\-\__/ \ (,_,)--
|
17
|
+
(\_/ \ \-
|
18
|
+
\/ / ( ( \ ] /) Some of the main features are:
|
19
|
+
/ ( \ \_ \./ ) - Easy to define rest paths with custom routes
|
20
|
+
( \ \ ) \ - Easy to define rest paths with custom responses
|
21
|
+
( /\_ _ _ _ /---/ /\_ \ - Definition of response times and response codes
|
22
|
+
\ / \ / ____/ / \ \ - Suitable to any kind of tests that use Rest
|
23
|
+
( / ) / / /__ ) ( )
|
24
|
+
( ) / __/ '---` / /
|
25
|
+
\ / \ \ _/ / This is still under development, so do not use it.
|
26
|
+
] ] )_\_ /__\/
|
27
|
+
/_\ ]___\
|
28
|
+
(___)
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
The Idea
|
33
|
+
=======
|
34
|
+
|
35
|
+
Are you tired of integrating with services that does not exist yet? Or that are expensive to spin up? Or just want to know what happens whan that service times out or return a ugly error? So you should know RestShifter :)
|
36
|
+
As simples is always better, I've put here a ridiculously easy to run app with no natural behaviour. You just have to create declarative files and start this app.
|
37
|
+
|
38
|
+
ASCII art: http://www.chris.com/ascii/index.php?art=creatures/unicorns
|
39
|
+
|
40
|
+
|
41
|
+
Instructions
|
42
|
+
==========
|
43
|
+
|
44
|
+
Developing
|
45
|
+
----------
|
46
|
+
To develop `RestShifter`, you are going to need [Bundler][1]
|
47
|
+
|
48
|
+
$ git git@github.com:camiloribeiro/RestShifter.git
|
49
|
+
$ cd RestShifter
|
50
|
+
$ bundle install
|
51
|
+
$ rake
|
52
|
+
|
53
|
+
The last step is launching the regression tests and all should be green.
|
54
|
+
|
55
|
+
If you have any problems, please let me know.
|
56
|
+
|
57
|
+
[1]: http://gembundler.com
|
58
|
+
|
59
|
+
Using
|
60
|
+
-----
|
61
|
+
|
62
|
+
Soon.
|
63
|
+
|
64
|
+
LICENSE
|
65
|
+
=======
|
66
|
+
|
67
|
+
Copyright 2015 - Camilo Ribeiro camilo@camiloribeiro.com
|
68
|
+
|
69
|
+
This file is part of RestShifter.
|
70
|
+
|
71
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
72
|
+
|
73
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
74
|
+
|
75
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'coveralls/rake/task'
|
3
|
+
|
4
|
+
Coveralls::RakeTask.new
|
5
|
+
|
6
|
+
task :default => [:spec, 'coveralls:push']
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask .new(:spec) do |task|
|
9
|
+
task.rspec_opts = ["--format documentation"]
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask .new(:nyan) do |task|
|
13
|
+
task.rspec_opts = ["--format NyanCatFormater"]
|
14
|
+
end
|
data/bin/rest_shifter
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class RestShifter::Commands::Help
|
2
|
+
|
3
|
+
def self.run
|
4
|
+
puts <<-HELP
|
5
|
+
Usage: rest_shifter <command> [options*]
|
6
|
+
|
7
|
+
rest_shifter version #{RestShifter::VERSION}: The ShapeShifter Rest Service
|
8
|
+
|
9
|
+
Available commands:
|
10
|
+
|
11
|
+
help Show this help text
|
12
|
+
|
13
|
+
--start, -s: Start service on port 4567
|
14
|
+
|
15
|
+
--version, -v: Print version and exit
|
16
|
+
--help, -h: Show this message
|
17
|
+
|
18
|
+
For more support read our api >> http://rubydoc.info/gems/rest_shifter
|
19
|
+
Have a nice day :)
|
20
|
+
HELP
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class RestShifter::Commands::Main
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def run(args=ARGV)
|
6
|
+
cmd = args.shift
|
7
|
+
|
8
|
+
case cmd
|
9
|
+
when "-h", "--help", NilClass
|
10
|
+
RestShifter::Commands::Help.run
|
11
|
+
exit 0
|
12
|
+
when "-v", "--version", "version"
|
13
|
+
RestShifter::Commands::Version.run
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
|
17
|
+
unless system("restshifter #{cmd}", *args)
|
18
|
+
if $?.exitstatus == 127 # bash 'command not found'
|
19
|
+
puts "Unknown subcommand #{cmd.inspect}"
|
20
|
+
RestShifter::Commands::Help.run
|
21
|
+
exit 127
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'icecream'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
module RestShifter; end
|
7
|
+
|
8
|
+
class Shifter < Sinatra::Base
|
9
|
+
end
|
10
|
+
|
11
|
+
shapes = IceCream::IceCream.new File.join(File.dirname(__FILE__), "../../spec/flavors")
|
12
|
+
|
13
|
+
services = []
|
14
|
+
shapes.all.each do |shape|
|
15
|
+
services << shapes.flavor(shape.to_s.gsub!("@", "").to_sym)
|
16
|
+
end
|
17
|
+
|
18
|
+
gets = services.select { |service| service.method_used == "get" }
|
19
|
+
gets_paths = gets.map { |service| service.path }.uniq
|
20
|
+
|
21
|
+
posts = services.select { |service| service.method_used == "post" }
|
22
|
+
posts_paths = gets.map { |service| service.path }.uniq
|
23
|
+
|
24
|
+
gets.each do |service|
|
25
|
+
get service.path do
|
26
|
+
status service.response_status
|
27
|
+
content_type service.response_content_type
|
28
|
+
service.response_body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
posts.each do |service|
|
33
|
+
post service.path do
|
34
|
+
status service.response_status
|
35
|
+
content_type service.response_content_type
|
36
|
+
service.response_body
|
37
|
+
end
|
38
|
+
end
|
data/lib/rest_shifter.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/version')
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
#common dependencies
|
5
|
+
require 'icecream'
|
6
|
+
require 'sinatra'
|
7
|
+
|
8
|
+
##Modules
|
9
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/shifter.rb')
|
10
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/commands.rb')
|
11
|
+
|
12
|
+
##internal dependences
|
13
|
+
|
14
|
+
## commands
|
15
|
+
require 'rest_shifter/commands'
|
16
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/commands/main')
|
17
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/commands/help')
|
18
|
+
require File.join(File.dirname(__FILE__), './rest_shifter/commands/version')
|
19
|
+
|
20
|
+
module RestShifter
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rest_shifter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rest_shifter"
|
7
|
+
s.version = RestShifter::VERSION
|
8
|
+
s.authors = ["Camilo Ribeiro"]
|
9
|
+
s.email = ["camilo@camiloribeiro.com"]
|
10
|
+
s.homepage = "http://github.com/camiloribeiro/RestShifter"
|
11
|
+
s.license = "Apache 2.0"
|
12
|
+
s.summary = %q{Simple Rest Mock service}
|
13
|
+
s.description = %q{RestShifter is a simple rest service that can shift into any kind of service, allowing you to mock rest services with declarative configuration}
|
14
|
+
|
15
|
+
s.rubyforge_project = "RestShifter"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.default_executable = 'rest_shifter'
|
21
|
+
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.add_development_dependency 'simplecov'
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
s.add_development_dependency 'cucumber'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rest-client'
|
29
|
+
s.add_development_dependency 'rspec'
|
30
|
+
s.add_development_dependency 'coveralls'
|
31
|
+
s.add_development_dependency 'nyan-cat-formatter'
|
32
|
+
s.add_development_dependency 'rack-test'
|
33
|
+
|
34
|
+
s.add_dependency 'icecream'
|
35
|
+
s.add_dependency 'sinatra'
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
method_used = "get"
|
2
|
+
path = "/ok"
|
3
|
+
request_accept = nil
|
4
|
+
request_content_type = nil
|
5
|
+
request_body = nil
|
6
|
+
request_scheme = nil
|
7
|
+
request_port = nil
|
8
|
+
request_request_method = nil
|
9
|
+
request_query_string = nil
|
10
|
+
request_content_length = nil
|
11
|
+
request_media_type = nil
|
12
|
+
request_host = nil
|
13
|
+
request_referrer = nil
|
14
|
+
request_user_agent = nil
|
15
|
+
request_cookies = nil
|
16
|
+
request_url = nil
|
17
|
+
request_path = nil
|
18
|
+
request_ip = nil
|
19
|
+
response_status = "200"
|
20
|
+
response_body = "success"
|
21
|
+
response_content_type = "application/json"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/rest_shifter/shifter.rb')
|
3
|
+
|
4
|
+
describe RestShifter do
|
5
|
+
|
6
|
+
def app
|
7
|
+
Sinatra::Application
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Get Operations" do
|
11
|
+
# Get
|
12
|
+
it "Service should return 200 for get" do
|
13
|
+
get '/ok'
|
14
|
+
expect(last_response.status).to eq(200)
|
15
|
+
expect(last_response.body).to eq("success")
|
16
|
+
expect(last_response.headers['Content-Type']).to eq("application/json")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "Service should return 404 without accept defining routing for get" do
|
20
|
+
get '/notfound'
|
21
|
+
expect(last_response.status).to eq(404)
|
22
|
+
expect(last_response.body).to eq("Not Found")
|
23
|
+
expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
|
24
|
+
end
|
25
|
+
|
26
|
+
# it "Service should return 404 with accept defining routing" do
|
27
|
+
# header 'Accept', "application/foo.company.product.type-version2+json"
|
28
|
+
# get '/notfound'
|
29
|
+
# expect(last_response.status).to eq(404)
|
30
|
+
# expect(last_response.body).to eq("Not Found with accept")
|
31
|
+
# expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version2+json")
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
describe "Post operations" do
|
35
|
+
|
36
|
+
# Post
|
37
|
+
it "Service should return 200 for post" do
|
38
|
+
post '/ok'
|
39
|
+
expect(last_response.status).to eq(200)
|
40
|
+
expect(last_response.body).to eq("success")
|
41
|
+
expect(last_response.headers['Content-Type']).to eq("application/json")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Service should return 404 without accept defining routing for post" do
|
45
|
+
post '/notfound'
|
46
|
+
expect(last_response.status).to eq(404)
|
47
|
+
expect(last_response.body).to eq("Not Found")
|
48
|
+
expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'coveralls'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'rack/test'
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), '../lib/rest_shifter/shifter.rb')
|
7
|
+
ENV['RACK_ENV'] = 'test'
|
8
|
+
|
9
|
+
Coveralls.wear_merged!
|
10
|
+
|
11
|
+
module RSpecMixin
|
12
|
+
include Rack::Test::Methods
|
13
|
+
def app() Sinatra::Application end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.color = true
|
18
|
+
config.include RSpecMixin
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rest_shifter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Camilo Ribeiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simplecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: nyan-cat-formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack-test
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: icecream
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sinatra
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: RestShifter is a simple rest service that can shift into any kind of
|
168
|
+
service, allowing you to mock rest services with declarative configuration
|
169
|
+
email:
|
170
|
+
- camilo@camiloribeiro.com
|
171
|
+
executables:
|
172
|
+
- rest_shifter
|
173
|
+
extensions: []
|
174
|
+
extra_rdoc_files: []
|
175
|
+
files:
|
176
|
+
- .gitignore
|
177
|
+
- .ruby-version
|
178
|
+
- .travis.yml
|
179
|
+
- CHANGES
|
180
|
+
- Gemfile
|
181
|
+
- Gemfile.lock
|
182
|
+
- LICENSE
|
183
|
+
- README.md
|
184
|
+
- Rakefile
|
185
|
+
- bin/rest_shifter
|
186
|
+
- lib/rest_shifter.rb
|
187
|
+
- lib/rest_shifter/commands.rb
|
188
|
+
- lib/rest_shifter/commands/help.rb
|
189
|
+
- lib/rest_shifter/commands/main.rb
|
190
|
+
- lib/rest_shifter/commands/version.rb
|
191
|
+
- lib/rest_shifter/shifter.rb
|
192
|
+
- lib/rest_shifter/version.rb
|
193
|
+
- rest_shifter.gemspec
|
194
|
+
- spec/flavors/notfound_get.flavor
|
195
|
+
- spec/flavors/notfound_post.flavor
|
196
|
+
- spec/flavors/success_get.flavor
|
197
|
+
- spec/flavors/success_post.flavor
|
198
|
+
- spec/service_spec.rb
|
199
|
+
- spec/spec_helper.rb
|
200
|
+
homepage: http://github.com/camiloribeiro/RestShifter
|
201
|
+
licenses:
|
202
|
+
- Apache 2.0
|
203
|
+
metadata: {}
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - '>='
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: '0'
|
218
|
+
requirements: []
|
219
|
+
rubyforge_project: RestShifter
|
220
|
+
rubygems_version: 2.4.4
|
221
|
+
signing_key:
|
222
|
+
specification_version: 4
|
223
|
+
summary: Simple Rest Mock service
|
224
|
+
test_files:
|
225
|
+
- spec/flavors/notfound_get.flavor
|
226
|
+
- spec/flavors/notfound_post.flavor
|
227
|
+
- spec/flavors/success_get.flavor
|
228
|
+
- spec/flavors/success_post.flavor
|
229
|
+
- spec/service_spec.rb
|
230
|
+
- spec/spec_helper.rb
|