rest_baby 0.1
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 +7 -0
- data/Gemfile +8 -0
- data/LICENSE +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +10 -0
- data/config/environments/mock.yml +4 -0
- data/cucumber.yml +4 -0
- data/features/header_options.feature +46 -0
- data/features/print_response.feature +77 -0
- data/features/rest_client.feature +39 -0
- data/features/step_definitions/header_steps.rb +19 -0
- data/features/step_definitions/rest_client_steps.rb +58 -0
- data/features/support/env.rb +29 -0
- data/features/support/mock_rest_service.rb +39 -0
- data/features/support/pinch_rest_service.rb +21 -0
- data/features/support/utility.rb +4 -0
- data/lib/rest_baby/version.rb +3 -0
- data/lib/rest_baby.rb +111 -0
- data/rest_baby.gemspec +30 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7faf8968aab8fa6962624cea4449f422328aa24a
|
4
|
+
data.tar.gz: aeaadaafe56200583e4fda2037ace3e3eeaeade8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 803d7e27d40eda07d016b1371c0a9b18f8b90223c87cda9854a50c10f461494762651cb83ba9f97d2f07ef97e5abbf266ccdcd086c14da83af689f88072b5bfd
|
7
|
+
data.tar.gz: df53b305a494a122506254299b2fb1505743953d8686aa75a6b2ed856313bfbfcb49d294c79c039e2fbddc81d9ef99985698882b86937dd6955a7088b58edccd
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
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/>
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dave McNulla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
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
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# rest_baby
|
2
|
+
|
3
|
+
Small rest client
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dojo_widgets'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dojo_widgets
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
default: FIG_NEWTON_FILE=mock.yml --tags ~@wip --no-source --color --format pretty
|
2
|
+
report: FIG_NEWTON_FILE=mock.yml --no-source --color --format progress --format html --out=features_report.html
|
3
|
+
wip: FIG_NEWTON_FILE=mock.yml --tags @wip --color --format pretty
|
4
|
+
core: FIG_NEWTON_FILE=mock.yml --tags @core --no-source --color --format pretty
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Create a basic rest client that can get, put, post, and delete
|
2
|
+
|
3
|
+
@extended @get @headers
|
4
|
+
Scenario: client uses an Accept header for a GET
|
5
|
+
Given I have a web service
|
6
|
+
And I have "GET" service for "/test" with the following headers
|
7
|
+
| Accept | application/json |
|
8
|
+
And I am a rest client
|
9
|
+
When I have the following header
|
10
|
+
| Accept | application/json |
|
11
|
+
And I "GET" from the web service
|
12
|
+
Then I receive the expected message
|
13
|
+
|
14
|
+
@extended @post @headers
|
15
|
+
Scenario: client uses an Accept and a Content-Type header for a POST
|
16
|
+
Given I have a web service
|
17
|
+
And I have "POST" service for "/test" with the following headers
|
18
|
+
| Content-Type | application/json |
|
19
|
+
| Accept | application/json |
|
20
|
+
And I am a rest client
|
21
|
+
When I have the following header
|
22
|
+
| Content-Type | application/json |
|
23
|
+
| Accept | application/json |
|
24
|
+
And I "POST" to the web service with the following
|
25
|
+
"""
|
26
|
+
{'Question': 'What is the meaning of life?'}
|
27
|
+
"""
|
28
|
+
Then I receive the expected message
|
29
|
+
|
30
|
+
@extended @post @authentication
|
31
|
+
Scenario: client uses basic authentication
|
32
|
+
Given I have a web service
|
33
|
+
And I have "GET" service for "/test"
|
34
|
+
And I am a rest client
|
35
|
+
And I have basic auth for user "test" and password "rest"
|
36
|
+
And I "GET" from the web service
|
37
|
+
Then I receive the expected message
|
38
|
+
|
39
|
+
@extended @post @authentication
|
40
|
+
Scenario: client uses a secure web server
|
41
|
+
Given I have a secure web service
|
42
|
+
And I have "GET" service for "/test"
|
43
|
+
And I am a rest client
|
44
|
+
And I have basic auth for user "test" and password "rest"
|
45
|
+
And I "GET" from the web service
|
46
|
+
Then I receive the expected message
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Feature: Create a basic rest client that can get, put, post, and delete
|
2
|
+
|
3
|
+
@extended @get @print
|
4
|
+
Scenario: client rest Get
|
5
|
+
Given I have a web service
|
6
|
+
And I have "GET" service for "/test" as follows
|
7
|
+
"""
|
8
|
+
{'Answer': 'What did you expect?'}
|
9
|
+
"""
|
10
|
+
And I am a rest client
|
11
|
+
# And I pause
|
12
|
+
When I "GET" from the web service
|
13
|
+
Then I receive the expected message
|
14
|
+
And the response prints like the following
|
15
|
+
"""
|
16
|
+
CODE = 200
|
17
|
+
MESSAGE =
|
18
|
+
BODY = {'Answer': 'What did you expect?'}
|
19
|
+
"""
|
20
|
+
|
21
|
+
|
22
|
+
@put @extended @print
|
23
|
+
Scenario: client rest Put
|
24
|
+
Given I have a web service
|
25
|
+
And I have "PUT" service for "/test" as follows
|
26
|
+
"""
|
27
|
+
{'Answer': 'What did you expect?'}
|
28
|
+
"""
|
29
|
+
And I am a rest client
|
30
|
+
When I "PUT" to the web service with the following
|
31
|
+
"""
|
32
|
+
{'Answer': 'What did you expect?'}
|
33
|
+
"""
|
34
|
+
Then I receive the expected message
|
35
|
+
And the response prints like the following
|
36
|
+
"""
|
37
|
+
CODE = 200
|
38
|
+
MESSAGE =
|
39
|
+
BODY = {'Answer': 'What did you expect?'}
|
40
|
+
"""
|
41
|
+
|
42
|
+
@post @extended @print
|
43
|
+
Scenario: client rest Post
|
44
|
+
Given I have a web service
|
45
|
+
And I have "POST" service for "/test" as follows
|
46
|
+
"""
|
47
|
+
{'Answer': 'What did you expect?'}
|
48
|
+
"""
|
49
|
+
And I am a rest client
|
50
|
+
When I "POST" to the web service with the following
|
51
|
+
"""
|
52
|
+
{'Answer': 'What did you expect?'}
|
53
|
+
"""
|
54
|
+
Then I receive the expected message
|
55
|
+
And the response prints like the following
|
56
|
+
"""
|
57
|
+
CODE = 200
|
58
|
+
MESSAGE =
|
59
|
+
BODY = {'Answer': 'What did you expect?'}
|
60
|
+
"""
|
61
|
+
|
62
|
+
@delete @extended @print
|
63
|
+
Scenario: client rest Delete
|
64
|
+
Given I have a web service
|
65
|
+
And I have "DELETE" service for "/test" as follows
|
66
|
+
"""
|
67
|
+
{'Answer': 'What did you expect?'}
|
68
|
+
"""
|
69
|
+
And I am a rest client
|
70
|
+
When I "DELETE" from the web service
|
71
|
+
Then I receive the expected message
|
72
|
+
And the response prints like the following
|
73
|
+
"""
|
74
|
+
CODE = 200
|
75
|
+
MESSAGE =
|
76
|
+
BODY = {'Answer': 'What did you expect?'}
|
77
|
+
"""
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Create a basic rest client that can get, put, post, and delete
|
2
|
+
|
3
|
+
@core @get
|
4
|
+
Scenario: client rest GET
|
5
|
+
Given I have a web service
|
6
|
+
And I have "GET" service for "/test"
|
7
|
+
And I am a rest client
|
8
|
+
When I "GET" from the web service
|
9
|
+
Then I receive the expected message
|
10
|
+
|
11
|
+
@core @put
|
12
|
+
Scenario: client rest PUT
|
13
|
+
Given I have a web service
|
14
|
+
And I have "PUT" service for "/test"
|
15
|
+
And I am a rest client
|
16
|
+
When I "PUT" to the web service with the following
|
17
|
+
"""
|
18
|
+
{'Question': 'What is the meaning of life?'}
|
19
|
+
"""
|
20
|
+
Then I receive the expected message
|
21
|
+
|
22
|
+
@core @post
|
23
|
+
Scenario: client rest POST
|
24
|
+
Given I have a web service
|
25
|
+
And I have "POST" service for "/test"
|
26
|
+
And I am a rest client
|
27
|
+
When I "POST" to the web service with the following
|
28
|
+
"""
|
29
|
+
{'Question': 'What is the meaning of life?'}
|
30
|
+
"""
|
31
|
+
Then I receive the expected message
|
32
|
+
|
33
|
+
@core @delete
|
34
|
+
Scenario: client rest DELETE
|
35
|
+
Given I have a web service
|
36
|
+
And I have "DELETE" service for "/test"
|
37
|
+
And I am a rest client
|
38
|
+
When I "DELETE" from the web service
|
39
|
+
Then I receive the expected message
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Given(/^I have a secure web service$/) do
|
2
|
+
@protocol = 'https'
|
3
|
+
@server = FigNewton.server
|
4
|
+
@port = FigNewton.port
|
5
|
+
@mockservice = MockRestService.new(@server, @port, @protocol)
|
6
|
+
end
|
7
|
+
|
8
|
+
Given(/^I have "(GET|PUT|POST|DELETE)" service for "(.*?)" with the following headers$/) do |type, path, table|
|
9
|
+
@path = path
|
10
|
+
@mockservice.store_msg(type, path, DEFAULT_MESSAGE, table.rows_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
When(/^I have the following headers?$/) do |table|
|
14
|
+
@restbaby.set_headers(table.rows_hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^I have basic auth for user "(.*?)" and password "(.*?)"$/) do |user, password|
|
18
|
+
@restbaby.set_auth(user, password)
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
DEFAULT_MESSAGE = "{'Answer': 'What did you expect?'}"
|
2
|
+
|
3
|
+
Given(/^I have a web service$/) do
|
4
|
+
@protocol = 'http'
|
5
|
+
@server = FigNewton.server
|
6
|
+
@port = FigNewton.port
|
7
|
+
@mockservice = MockRestService.new(@server, @port, @protocol)
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^I have "(GET|PUT|POST|DELETE)" service for "(.*?)"$/) do |type, path|
|
11
|
+
@path = path
|
12
|
+
@mockservice.store_msg(type, path, DEFAULT_MESSAGE)
|
13
|
+
end
|
14
|
+
|
15
|
+
Given(/^I have "(GET|PUT|POST|DELETE)" service for "(.*?)" as follows$/) do |type, path, message|
|
16
|
+
@path = path
|
17
|
+
@mockservice.store_msg(type, path, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
Given(/^I am a rest client$/) do
|
21
|
+
@restbaby = Client.new("#{@protocol}://#{@server}:#{@port}#{@path}")
|
22
|
+
end
|
23
|
+
|
24
|
+
When(/^I "(GET|DELETE)" from the web service$/) do |type|
|
25
|
+
case type.downcase
|
26
|
+
when 'get'
|
27
|
+
@response = @restbaby.get(@path)
|
28
|
+
when 'delete'
|
29
|
+
@response = @restbaby.delete(@path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
When(/^I "(PUT|POST)" to the web service with the following$/) do |type, message|
|
34
|
+
case type.downcase
|
35
|
+
when 'put'
|
36
|
+
@response = @restbaby.put(@path, message)
|
37
|
+
when 'post'
|
38
|
+
@response = @restbaby.post(@path, message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
When(/^I pause$/) do
|
43
|
+
pause()
|
44
|
+
end
|
45
|
+
|
46
|
+
Then(/^I receive the expected message$/) do
|
47
|
+
expect(@response.code).to eq('200')
|
48
|
+
expect(@response.body).to eq(DEFAULT_MESSAGE)
|
49
|
+
end
|
50
|
+
|
51
|
+
Then(/^I receive the following$/) do |message|
|
52
|
+
expect(@response.code).to eq('200')
|
53
|
+
expect(@response.body).to eq(message)
|
54
|
+
end
|
55
|
+
|
56
|
+
Then(/^the response prints like the following$/) do |response|
|
57
|
+
expect(@restbaby.print_last_response).to eq(response)
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rspec-expectations'
|
2
|
+
require 'fig_newton'
|
3
|
+
require 'pinch_hitter'
|
4
|
+
require 'cucumber/rspec/doubles'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'webmock/cucumber'
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "rest_baby.rb"))
|
8
|
+
require 'logger'
|
9
|
+
|
10
|
+
include RestBaby
|
11
|
+
|
12
|
+
mylog = Logger.new(STDOUT)
|
13
|
+
mylog.level = case FigNewton.log_level.upcase
|
14
|
+
when 'FATAL'
|
15
|
+
Logger::WARN
|
16
|
+
when 'ERROR'
|
17
|
+
Logger::WARN
|
18
|
+
when 'WARN'
|
19
|
+
Logger::WARN
|
20
|
+
when 'INFO'
|
21
|
+
Logger::WARN
|
22
|
+
when 'DEBUG'
|
23
|
+
Logger::DEBUG
|
24
|
+
else
|
25
|
+
Logger::UNKNOWN
|
26
|
+
end
|
27
|
+
|
28
|
+
mylog.info "Using environment in #{ENV['FIG_NEWTON_FILE']}"
|
29
|
+
FigNewton.load(ENV['FIG_NEWTON_FILE'])
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'webmock/cucumber'
|
2
|
+
|
3
|
+
include WebMock
|
4
|
+
|
5
|
+
class MockRestService
|
6
|
+
|
7
|
+
STANDARD_HEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
|
8
|
+
STANDARD = "http"
|
9
|
+
SECURE = "https"
|
10
|
+
|
11
|
+
def initialize(host, port, protocol = STANDARD)
|
12
|
+
@protocol = protocol
|
13
|
+
@host = host
|
14
|
+
@port = port
|
15
|
+
@messages = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def store_msg(type, path, message, headers = {}, user = nil, password = nil)
|
19
|
+
new_headers = STANDARD_HEADERS.merge(headers)
|
20
|
+
auth_string = "#{user}:#{password}@" unless (user.nil? || password.nil?)
|
21
|
+
case type.downcase
|
22
|
+
when "get", "delete"
|
23
|
+
# WebMock.stub_request(type.downcase.to_sym, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}").
|
24
|
+
# with(:headers => new_headers).
|
25
|
+
# to_return({:body => "#{message}", :status => 200}, :headers => {})
|
26
|
+
stub_request(type.downcase.to_sym, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}").
|
27
|
+
with(:headers => new_headers).
|
28
|
+
to_return({:body => "#{message}", :status => 200}, :headers => {})
|
29
|
+
|
30
|
+
when "post", "put"
|
31
|
+
WebMock.stub_request(type.downcase.to_sym, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}").
|
32
|
+
with(:headers => new_headers).
|
33
|
+
to_return(:status => 200, :body => "#{message}", :headers => {})
|
34
|
+
else
|
35
|
+
raise "Unsupported type: #{type}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
include PinchHitter
|
2
|
+
|
3
|
+
class PinchRestService
|
4
|
+
|
5
|
+
def initialize(host, port)
|
6
|
+
@host = host
|
7
|
+
@port = port
|
8
|
+
self.start_service @host, @port
|
9
|
+
self.connect @host, @port
|
10
|
+
self.messages_directory = File.join(File.dirname('.'), "..", "..", 'features', 'messages')
|
11
|
+
end
|
12
|
+
|
13
|
+
def store_msg(path, message)
|
14
|
+
store path, message
|
15
|
+
end
|
16
|
+
|
17
|
+
def close
|
18
|
+
self.stop_service
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/rest_baby.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
== Authors
|
4
|
+
|
5
|
+
Dave McNulla
|
6
|
+
|
7
|
+
== Revision Log
|
8
|
+
|
9
|
+
2013.07.30 initial files for a simple rest client
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'net/http'
|
14
|
+
require 'net/https'
|
15
|
+
require "rest_baby/version"
|
16
|
+
|
17
|
+
module RestBaby
|
18
|
+
class Client
|
19
|
+
attr_accessor :contentType, :uri, :wsresponse, :headers
|
20
|
+
|
21
|
+
def initialize(url, headers = {})
|
22
|
+
@uri = URI.parse(url)
|
23
|
+
@headers = headers
|
24
|
+
@user = nil
|
25
|
+
@password = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_headers(headers)
|
29
|
+
@headers = @headers.merge(headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_auth(user, password)
|
33
|
+
new_url = "#{uri.scheme}://#{user}:#{password}@#{uri.host}:#{uri.port}#{uri.path}"
|
34
|
+
@uri = URI.parse(new_url)
|
35
|
+
end
|
36
|
+
|
37
|
+
#Basic web services Get command
|
38
|
+
# * url = url to send the command to
|
39
|
+
# * headers = header parameters including authorization and Content-Type
|
40
|
+
# The response from the rest server is returned
|
41
|
+
def get(path, headers = {})
|
42
|
+
return request(uri, Net::HTTP::Get.new(@uri.request_uri), headers)
|
43
|
+
end
|
44
|
+
|
45
|
+
#Basic web services Post command
|
46
|
+
# * url = url to send the command to
|
47
|
+
# * body = data to put in the body
|
48
|
+
# * headers = header parameters including authorization and Content-Type
|
49
|
+
# The response from the rest server is returned
|
50
|
+
def post(path, body = nil, headers = {})
|
51
|
+
return request(uri, Net::HTTP::Post.new(@uri.request_uri), body, headers)
|
52
|
+
end
|
53
|
+
|
54
|
+
#Basic web services Delete command
|
55
|
+
# * url = url to send the command to
|
56
|
+
# * headers = header parameters including authorization and Content-Type
|
57
|
+
# The response from the rest server is returned
|
58
|
+
def delete(path, headers = {})
|
59
|
+
return request(uri, Net::HTTP::Delete.new(@uri.request_uri), headers)
|
60
|
+
end
|
61
|
+
|
62
|
+
#Basic web services Put command
|
63
|
+
# * url = url to send the command to
|
64
|
+
# * body = data to put in the body
|
65
|
+
# * headers = header parameters including authorization and Content-Type
|
66
|
+
# The response from the rest server is returned
|
67
|
+
def put(path, body = nil, headers = {})
|
68
|
+
return request(uri, Net::HTTP::Put.new(@uri.request_uri), body, headers)
|
69
|
+
end
|
70
|
+
|
71
|
+
#Sending the web services command
|
72
|
+
# * url = url to send the command to
|
73
|
+
# * req = command to send as Net::HTTP:<command> class
|
74
|
+
# * body = data to put in the body
|
75
|
+
# * headers = header parameters including authorization and Content-Type
|
76
|
+
# The response from the rest server is returned
|
77
|
+
def request(uri, request, body = nil, headers)
|
78
|
+
@headers.merge(headers).each { |key, value| request[key] = value }
|
79
|
+
request.body = body unless body.nil?
|
80
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
81
|
+
http.use_ssl = true if @uri.scheme == 'https'
|
82
|
+
begin
|
83
|
+
@wsresponse = http.request(request)
|
84
|
+
# puts print_last_response
|
85
|
+
return @wsresponse
|
86
|
+
rescue Timeout::Error => e
|
87
|
+
raise e.message
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_code
|
92
|
+
@wsresponse.code
|
93
|
+
end
|
94
|
+
|
95
|
+
# Pretty print the web services response
|
96
|
+
# * response = web service response to print
|
97
|
+
def print_last_response
|
98
|
+
output = "CODE = #{@wsresponse.code}\n"
|
99
|
+
output << "MESSAGE = #{@wsresponse.message}\n"
|
100
|
+
@wsresponse.each { |key, value| output << "#{key} = #{value}\n"}
|
101
|
+
begin
|
102
|
+
output << "BODY = "
|
103
|
+
output << "#{@wsresponse.body}"
|
104
|
+
rescue
|
105
|
+
output << "[Empty]"
|
106
|
+
end
|
107
|
+
return output
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
data/rest_baby.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rest_baby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rest_baby"
|
8
|
+
spec.version = RestBaby::VERSION
|
9
|
+
spec.authors = ["Dave McNulla"]
|
10
|
+
spec.email = ["mcnulla@gmail.com"]
|
11
|
+
spec.description = %q{Rest client}
|
12
|
+
spec.summary = %q{This is a small rest client developed for use in testing rest services.}
|
13
|
+
spec.homepage = "https://github.com/dmcnulla/rest_baby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "cucumber", ">= 1.3.5"
|
24
|
+
spec.add_development_dependency "fig_newton", ">= 0.9"
|
25
|
+
spec.add_development_dependency "json", ">= 1.8.0"
|
26
|
+
spec.add_development_dependency "pinch_hitter", ">= 0.3"
|
27
|
+
spec.add_development_dependency "rspec", ">= 2.14.1"
|
28
|
+
spec.add_development_dependency "webmock", ">= 1.13.0"
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rest_baby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave McNulla
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: 1.3.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fig_newton
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pinch_hitter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.14.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.14.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.13.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.13.0
|
125
|
+
description: Rest client
|
126
|
+
email:
|
127
|
+
- mcnulla@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- config/environments/mock.yml
|
138
|
+
- cucumber.yml
|
139
|
+
- features/header_options.feature
|
140
|
+
- features/print_response.feature
|
141
|
+
- features/rest_client.feature
|
142
|
+
- features/step_definitions/header_steps.rb
|
143
|
+
- features/step_definitions/rest_client_steps.rb
|
144
|
+
- features/support/env.rb
|
145
|
+
- features/support/mock_rest_service.rb
|
146
|
+
- features/support/pinch_rest_service.rb
|
147
|
+
- features/support/utility.rb
|
148
|
+
- lib/rest_baby.rb
|
149
|
+
- lib/rest_baby/version.rb
|
150
|
+
- rest_baby.gemspec
|
151
|
+
homepage: https://github.com/dmcnulla/rest_baby
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.0.3
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: This is a small rest client developed for use in testing rest services.
|
175
|
+
test_files:
|
176
|
+
- features/header_options.feature
|
177
|
+
- features/print_response.feature
|
178
|
+
- features/rest_client.feature
|
179
|
+
- features/step_definitions/header_steps.rb
|
180
|
+
- features/step_definitions/rest_client_steps.rb
|
181
|
+
- features/support/env.rb
|
182
|
+
- features/support/mock_rest_service.rb
|
183
|
+
- features/support/pinch_rest_service.rb
|
184
|
+
- features/support/utility.rb
|