rest_baby 0.1 → 0.2
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/ChangeLog +13 -0
- data/README.md +2 -2
- data/Rakefile +8 -1
- data/doc/MockRestService.html +351 -0
- data/doc/PinchRestService.html +349 -0
- data/doc/RestBaby/Client.html +936 -0
- data/doc/RestBaby.html +170 -0
- data/doc/_index.html +182 -0
- data/doc/class_list.html +74 -0
- data/doc/css/common.css +1 -0
- data/doc/css/cucumber.css +227 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/feature_list.html +245 -0
- data/doc/featuredirectories_list.html +179 -0
- data/doc/file.README.html +134 -0
- data/doc/file_list.html +76 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +134 -0
- data/doc/js/app.js +214 -0
- data/doc/js/cucumber.js +305 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +169 -0
- data/doc/requirements/features/header_options.html +1020 -0
- data/doc/requirements/features/headers/header_options.html +1020 -0
- data/doc/requirements/features/headers.html +157 -0
- data/doc/requirements/features/print_response.html +969 -0
- data/doc/requirements/features/rest_client.html +835 -0
- data/doc/requirements/features.html +199 -0
- data/doc/requirements/step_transformers.html +1508 -0
- data/doc/requirements/tags/authentication.html +169 -0
- data/doc/requirements/tags/core.html +187 -0
- data/doc/requirements/tags/delete.html +169 -0
- data/doc/requirements/tags/extended.html +223 -0
- data/doc/requirements/tags/get.html +178 -0
- data/doc/requirements/tags/headers.html +169 -0
- data/doc/requirements/tags/post.html +196 -0
- data/doc/requirements/tags/print.html +187 -0
- data/doc/requirements/tags/put.html +169 -0
- data/doc/requirements/tags.html +408 -0
- data/doc/requirements.html +213 -0
- data/doc/step_list.html +825 -0
- data/doc/stepdefinition_list.html +230 -0
- data/doc/tag_list.html +131 -0
- data/doc/top-level-namespace.html +244 -0
- data/features/{header_options.feature → headers/header_options.feature} +0 -0
- data/features/step_definitions/rest_client_steps.rb +5 -4
- data/features/support/env.rb +1 -18
- data/features/support/mock_rest_service.rb +1 -1
- data/lib/rest_baby/version.rb +1 -1
- data/lib/rest_baby.rb +62 -35
- metadata +49 -5
- data/LICENSE +0 -24
data/lib/rest_baby.rb
CHANGED
@@ -4,20 +4,26 @@
|
|
4
4
|
|
5
5
|
Dave McNulla
|
6
6
|
|
7
|
-
== Revision Log
|
8
|
-
|
9
|
-
2013.07.30 initial files for a simple rest client
|
10
|
-
|
11
7
|
=end
|
12
8
|
|
13
9
|
require 'net/http'
|
14
10
|
require 'net/https'
|
15
11
|
require "rest_baby/version"
|
16
12
|
|
13
|
+
##
|
14
|
+
# RestBaby is a small rest client. It encapsulates some of the details for creating and using the rest service.
|
17
15
|
module RestBaby
|
16
|
+
# Sends and receives data to a restful web service
|
18
17
|
class Client
|
19
|
-
attr_accessor :contentType, :uri, :wsresponse, :headers
|
20
18
|
|
19
|
+
##
|
20
|
+
# Creates a new rest client
|
21
|
+
#
|
22
|
+
# * +url+ = url of the rest service
|
23
|
+
# eg. http://myrestservice.com:80/time
|
24
|
+
# * +headers+ = default headers to use.
|
25
|
+
# eg. '{ \"Content-Type\" => \"application/json\"}'
|
26
|
+
# can be multiple headers
|
21
27
|
def initialize(url, headers = {})
|
22
28
|
@uri = URI.parse(url)
|
23
29
|
@headers = headers
|
@@ -25,54 +31,73 @@ module RestBaby
|
|
25
31
|
@password = nil
|
26
32
|
end
|
27
33
|
|
34
|
+
##
|
35
|
+
# Modifies the headers by merging new headers with current headers.
|
36
|
+
#
|
37
|
+
# * +headers+ = new headers to merge with current headers
|
28
38
|
def set_headers(headers)
|
29
39
|
@headers = @headers.merge(headers)
|
30
40
|
end
|
31
41
|
|
42
|
+
##
|
43
|
+
# Modifies the authentication for the rest client
|
44
|
+
#
|
45
|
+
# * +user+ = authorized username
|
46
|
+
# * +password+ = password for the user
|
32
47
|
def set_auth(user, password)
|
33
|
-
new_url = "#{uri.scheme}://#{user}:#{password}@#{uri.host}:#{uri.port}#{uri.path}"
|
48
|
+
new_url = "#{@uri.scheme}://#{user}:#{password}@#{@uri.host}:#{@uri.port}#{@uri.path}"
|
34
49
|
@uri = URI.parse(new_url)
|
35
50
|
end
|
36
51
|
|
37
|
-
|
38
|
-
#
|
39
|
-
#
|
52
|
+
##
|
53
|
+
# Basic web services Get command
|
54
|
+
#
|
55
|
+
# * +url+ = url to send the command to
|
56
|
+
# * +headers+ = header parameters including authorization and Content-Type
|
40
57
|
# The response from the rest server is returned
|
41
|
-
def get(
|
42
|
-
return request(uri, Net::HTTP::Get.new(@uri.request_uri), headers)
|
58
|
+
def get(headers = {})
|
59
|
+
return request(@uri, Net::HTTP::Get.new(@uri.request_uri), headers)
|
43
60
|
end
|
44
61
|
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# *
|
62
|
+
##
|
63
|
+
# Basic web services Post command
|
64
|
+
#
|
65
|
+
# * +url+ = url to send the command to
|
66
|
+
# * +body+ = data to put in the body
|
67
|
+
# * +headers+ = header parameters including authorization and Content-Type
|
49
68
|
# The response from the rest server is returned
|
50
|
-
def post(
|
51
|
-
return request(uri, Net::HTTP::Post.new(@uri.request_uri), body, headers)
|
69
|
+
def post(body = nil, headers = {})
|
70
|
+
return request(@uri, Net::HTTP::Post.new(@uri.request_uri), body, headers)
|
52
71
|
end
|
53
72
|
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
73
|
+
##
|
74
|
+
# Basic web services Delete command
|
75
|
+
#
|
76
|
+
# * +url+ = url to send the command to
|
77
|
+
# * +headers+ = header parameters including authorization and Content-Type
|
57
78
|
# The response from the rest server is returned
|
58
|
-
def delete(
|
59
|
-
return request(uri, Net::HTTP::Delete.new(@uri.request_uri), headers)
|
79
|
+
def delete(headers = {})
|
80
|
+
return request(@uri, Net::HTTP::Delete.new(@uri.request_uri), headers)
|
60
81
|
end
|
61
82
|
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# *
|
83
|
+
##
|
84
|
+
# Basic web services Put command
|
85
|
+
#
|
86
|
+
# * +url+ = url to send the command to
|
87
|
+
# * +body+ = data to put in the body
|
88
|
+
# * +headers+ = header parameters including authorization and Content-Type
|
66
89
|
# The response from the rest server is returned
|
67
|
-
def put(
|
68
|
-
return request(uri, Net::HTTP::Put.new(@uri.request_uri), body, headers)
|
90
|
+
def put(body = nil, headers = {})
|
91
|
+
return request(@uri, Net::HTTP::Put.new(@uri.request_uri), body, headers)
|
69
92
|
end
|
70
93
|
|
71
|
-
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# *
|
75
|
-
# *
|
94
|
+
##
|
95
|
+
# Sending the web services command
|
96
|
+
#
|
97
|
+
# * +url+ = url to send the command to
|
98
|
+
# * +req+ = command to send as Net::HTTP:<command> class
|
99
|
+
# * +body+ = data to put in the body
|
100
|
+
# * +headers+ = header parameters including authorization and Content-Type
|
76
101
|
# The response from the rest server is returned
|
77
102
|
def request(uri, request, body = nil, headers)
|
78
103
|
@headers.merge(headers).each { |key, value| request[key] = value }
|
@@ -92,8 +117,10 @@ module RestBaby
|
|
92
117
|
@wsresponse.code
|
93
118
|
end
|
94
119
|
|
95
|
-
|
96
|
-
#
|
120
|
+
##
|
121
|
+
# Pretty print the web services last response
|
122
|
+
#
|
123
|
+
# The nice looking output is returned as a string
|
97
124
|
def print_last_response
|
98
125
|
output = "CODE = #{@wsresponse.code}\n"
|
99
126
|
output << "MESSAGE = #{@wsresponse.message}\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_baby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave McNulla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,14 +129,57 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ChangeLog
|
132
133
|
- Gemfile
|
133
|
-
- LICENSE
|
134
134
|
- LICENSE.txt
|
135
135
|
- README.md
|
136
136
|
- Rakefile
|
137
137
|
- config/environments/mock.yml
|
138
138
|
- cucumber.yml
|
139
|
-
-
|
139
|
+
- doc/MockRestService.html
|
140
|
+
- doc/PinchRestService.html
|
141
|
+
- doc/RestBaby.html
|
142
|
+
- doc/RestBaby/Client.html
|
143
|
+
- doc/_index.html
|
144
|
+
- doc/class_list.html
|
145
|
+
- doc/css/common.css
|
146
|
+
- doc/css/cucumber.css
|
147
|
+
- doc/css/full_list.css
|
148
|
+
- doc/css/style.css
|
149
|
+
- doc/feature_list.html
|
150
|
+
- doc/featuredirectories_list.html
|
151
|
+
- doc/file.README.html
|
152
|
+
- doc/file_list.html
|
153
|
+
- doc/frames.html
|
154
|
+
- doc/index.html
|
155
|
+
- doc/js/app.js
|
156
|
+
- doc/js/cucumber.js
|
157
|
+
- doc/js/full_list.js
|
158
|
+
- doc/js/jquery.js
|
159
|
+
- doc/method_list.html
|
160
|
+
- doc/requirements.html
|
161
|
+
- doc/requirements/features.html
|
162
|
+
- doc/requirements/features/header_options.html
|
163
|
+
- doc/requirements/features/headers.html
|
164
|
+
- doc/requirements/features/headers/header_options.html
|
165
|
+
- doc/requirements/features/print_response.html
|
166
|
+
- doc/requirements/features/rest_client.html
|
167
|
+
- doc/requirements/step_transformers.html
|
168
|
+
- doc/requirements/tags.html
|
169
|
+
- doc/requirements/tags/authentication.html
|
170
|
+
- doc/requirements/tags/core.html
|
171
|
+
- doc/requirements/tags/delete.html
|
172
|
+
- doc/requirements/tags/extended.html
|
173
|
+
- doc/requirements/tags/get.html
|
174
|
+
- doc/requirements/tags/headers.html
|
175
|
+
- doc/requirements/tags/post.html
|
176
|
+
- doc/requirements/tags/print.html
|
177
|
+
- doc/requirements/tags/put.html
|
178
|
+
- doc/step_list.html
|
179
|
+
- doc/stepdefinition_list.html
|
180
|
+
- doc/tag_list.html
|
181
|
+
- doc/top-level-namespace.html
|
182
|
+
- features/headers/header_options.feature
|
140
183
|
- features/print_response.feature
|
141
184
|
- features/rest_client.feature
|
142
185
|
- features/step_definitions/header_steps.rb
|
@@ -173,7 +216,7 @@ signing_key:
|
|
173
216
|
specification_version: 4
|
174
217
|
summary: This is a small rest client developed for use in testing rest services.
|
175
218
|
test_files:
|
176
|
-
- features/header_options.feature
|
219
|
+
- features/headers/header_options.feature
|
177
220
|
- features/print_response.feature
|
178
221
|
- features/rest_client.feature
|
179
222
|
- features/step_definitions/header_steps.rb
|
@@ -182,3 +225,4 @@ test_files:
|
|
182
225
|
- features/support/mock_rest_service.rb
|
183
226
|
- features/support/pinch_rest_service.rb
|
184
227
|
- features/support/utility.rb
|
228
|
+
has_rdoc:
|
data/LICENSE
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
2
|
-
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
-
distribute this software, either in source code form or as a compiled
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
-
means.
|
7
|
-
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
-
of this software dedicate any and all copyright interest in the
|
10
|
-
software to the public domain. We make this dedication for the benefit
|
11
|
-
of the public at large and to the detriment of our heirs and
|
12
|
-
successors. We intend this dedication to be an overt act of
|
13
|
-
relinquishment in perpetuity of all present and future rights to this
|
14
|
-
software under copyright law.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
24
|
-
For more information, please refer to <http://unlicense.org/>
|