rest_baby 0.4 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af729fe4758d51c75c7c37108de7f9376fa015ce
4
- data.tar.gz: abb8b069b9fce12330b212d3741f1a08aa583146
3
+ metadata.gz: 1fb014e9218f045b6869e8220de3f320cfec06f4
4
+ data.tar.gz: 22e183843f1926e3bfbbd295168f2356717fe538
5
5
  SHA512:
6
- metadata.gz: 704878c6592abd0ba51582933a72b5f1d67fbeba317e540aabb5faecc74e2cbd624752e53df83161ee0b597881fe5ab353c76596c16a142d4e8d343175e365c7
7
- data.tar.gz: e267a8ae7a0eae0e28d1bf439eb93315fd7382ca3b1aea04d5f1190bb6ee951ba440a2bd58d071b8c95867038ae06c40b091a226533e939eb9e63156012561bc
6
+ metadata.gz: a31117c14615d8492718866d583f8b3680947ad5c5c906ed77dfb490d197cf40b0f8190f79ffc0cb94a5108ee087f432b48be571f9bc7027c2653232068b8544
7
+ data.tar.gz: 70b78cf5010e2ac75f66623e189c7f37f883e698475bfd7c9f35b473ab73afafde6f79a06ac61a88c0473675c5888c0791182dcad34bbbbf5a14219c5a1c3586
data/ChangeLog CHANGED
@@ -12,10 +12,12 @@
12
12
  * Removed duplicate license file
13
13
  * Removed unnecessary attr_accessor entries from rest_baby.rb
14
14
  * Removed unused parameter from rest_baby client calls to rest services.
15
- === Version 0.3 / 2013-02-13
15
+ === Version 0.3 / 2014-02-13
16
16
  * Updated to use markdown for comments
17
17
  * Revised authentication
18
18
  * Added output optional using HTTP_DEBUG=TRUE or FALSE
19
- === Version 0.4 / 2014-06-11
20
- * Downgraded the version of rspec used due to compatibility issues
21
- * Fixed bug in lib/rest_baby.rb:177 that incorrectly referenced 'body' instead of 'response.body'
19
+ === Version 0.4 / 2014-06-12
20
+ * Fixed unreported/untracked defect
21
+ === Version 0.5 / 2014-07-27
22
+ * Enabled use of query parameters on GET calls
23
+ * Revised tests to replace expect with should
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'cucumber', '>=1.3.5'
4
- gem 'fig_newton', '>=0.10'
5
- gem 'json', '>=1.8.1'
6
- gem 'nokogiri', '1.6.2.1'
7
- gem 'rspec', '>=2.8.0'
8
- gem 'webmock', '>=1.18.0'
3
+ gem 'cucumber'
4
+ gem 'fig_newton'
5
+ gem 'json'
6
+ gem 'nokogiri'
7
+ gem 'rspec'
8
+ gem 'webmock'
@@ -1,6 +1,7 @@
1
1
  Feature: Create a basic rest client that can get, put, post, and delete
2
2
 
3
3
  @extended @get @print
4
+ @print.S1
4
5
  Scenario: client rest Get
5
6
  Given I have a web service
6
7
  And I have "GET" service for "/test" as follows
@@ -8,11 +9,11 @@ Scenario: client rest Get
8
9
  {'Answer': 'What did you expect?'}
9
10
  """
10
11
  And I am a rest client
11
- # And I pause
12
12
  When I "GET" from the web service
13
13
  Then I receive the expected message
14
14
 
15
15
  @put @extended @print
16
+ @print.S2
16
17
  Scenario: client rest Put
17
18
  Given I have a web service
18
19
  And I have "PUT" service for "/test" as follows
@@ -27,6 +28,7 @@ Scenario: client rest Put
27
28
  Then I receive the expected message
28
29
 
29
30
  @post @extended @print
31
+ @print.S3
30
32
  Scenario: client rest Post
31
33
  Given I have a web service
32
34
  And I have "POST" service for "/test" as follows
@@ -41,6 +43,7 @@ Scenario: client rest Post
41
43
  Then I receive the expected message
42
44
 
43
45
  @delete @extended @print
46
+ @print.S4
44
47
  Scenario: client rest Delete
45
48
  Given I have a web service
46
49
  And I have "DELETE" service for "/test" as follows
@@ -1,6 +1,7 @@
1
1
  Feature: Create a basic rest client that can get, put, post, and delete
2
2
 
3
3
  @core @get
4
+ @rest.S1
4
5
  Scenario: client rest GET
5
6
  Given I have a web service
6
7
  And I have "GET" service for "/test"
@@ -9,6 +10,7 @@ Scenario: client rest GET
9
10
  Then I receive the expected message
10
11
 
11
12
  @core @put
13
+ @rest.S2
12
14
  Scenario: client rest PUT
13
15
  Given I have a web service
14
16
  And I have "PUT" service for "/test"
@@ -20,6 +22,7 @@ Scenario: client rest PUT
20
22
  Then I receive the expected message
21
23
 
22
24
  @core @post
25
+ @rest.S3
23
26
  Scenario: client rest POST
24
27
  Given I have a web service
25
28
  And I have "POST" service for "/test"
@@ -31,6 +34,7 @@ Scenario: client rest POST
31
34
  Then I receive the expected message
32
35
 
33
36
  @core @delete
37
+ @rest.S4
34
38
  Scenario: client rest DELETE
35
39
  Given I have a web service
36
40
  And I have "DELETE" service for "/test"
@@ -8,13 +8,30 @@ Given(/^I have a web service$/) do
8
8
  end
9
9
 
10
10
  Given(/^I have "(GET|PUT|POST|DELETE)" service for "(.*?)"$/) do |type, path|
11
- @path = path
12
- @mockservice.store_msg(type, path, DEFAULT_MESSAGE)
11
+ if type=="GET"
12
+ create_get(type, path)
13
+ else
14
+ @path = path
15
+ @mockservice.store_msg(type, path, DEFAULT_MESSAGE)
16
+ end
13
17
  end
14
18
 
15
19
  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)
20
+ if type=="GET"
21
+ create_get(type, path, message)
22
+ else
23
+ @path = path
24
+ @mockservice.store_msg(type, path, message)
25
+ end
26
+ end
27
+
28
+ def create_get(type, path, message = DEFAULT_MESSAGE)
29
+ @path = path.split('?')[0]
30
+ if path.split('?').length==1
31
+ @mockservice.store_msg("GET", @path, message)
32
+ else
33
+ @mockservice.store_get_query(path)
34
+ end
18
35
  end
19
36
 
20
37
  Given(/^I am a rest client$/) do
@@ -39,6 +56,10 @@ When(/^I "(PUT|POST)" to the web service with the following$/) do |type, message
39
56
  end
40
57
  end
41
58
 
59
+ When(/^I "GET" from the web service with the parameters$/) do |table|
60
+ @response = @restbaby.get({}, nil, table.rows_hash)
61
+ end
62
+
42
63
  When(/^I pause$/) do
43
64
  pause()
44
65
  end
@@ -48,7 +69,12 @@ Then(/^I receive the expected message$/) do
48
69
  @response.body.should eq(DEFAULT_MESSAGE)
49
70
  end
50
71
 
51
- Then(/^I receive the following$/) do |message|
72
+ # Then(/^I receive the following$/) do |message|
73
+ # @response.code.should eq('200')
74
+ # @response.body.should eq(message)
75
+ # end
76
+
77
+ Then(/^I receive a message with "(.*?)"$/) do |message|
52
78
  @response.code.should eq('200')
53
79
  @response.body.should eq(message)
54
80
  end
@@ -4,7 +4,8 @@ include WebMock::API
4
4
 
5
5
  class MockRestService
6
6
 
7
- STANDARD_HEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
7
+ # STANDARD_HEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
8
+ STANDARD_HEADERS = {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}
8
9
  STANDARD = "http"
9
10
  SECURE = "https"
10
11
 
@@ -30,6 +31,15 @@ class MockRestService
30
31
  else
31
32
  raise "Unsupported type: #{type}"
32
33
  end
33
- end
34
+ end
34
35
 
36
+ def store_get_query(path, headers = {}, user = nil, password = nil)
37
+ new_headers = STANDARD_HEADERS.merge(headers)
38
+ params = Hash.new
39
+ message = path.split('?').last
40
+ auth_string = "#{user}:#{password}@" unless (user.nil? || password.nil?)
41
+ WebMock.stub_request(:get, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}").
42
+ with(:headers => new_headers).
43
+ to_return({:body => "#{message}", :status => 200}, :headers => {})
44
+ end
35
45
  end
@@ -0,0 +1,13 @@
1
+ Feature: As a rest client I need to use URL parameters in order to send those parameters to a restful service.
2
+
3
+ @parameter
4
+ @parameter.S1
5
+ Scenario: Send parameter to a service.
6
+ Given I have a web service
7
+ And I have "GET" service for "/test?first=1&second=2&third=3"
8
+ And I am a rest client
9
+ When I "GET" from the web service with the parameters
10
+ | first | 1 |
11
+ | second | 2 |
12
+ | third | 3 |
13
+ Then I receive a message with "first=1&second=2&third=3"
@@ -1,3 +1,3 @@
1
1
  module RestBaby
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
data/lib/rest_baby.rb CHANGED
@@ -14,6 +14,9 @@ require 'rest_baby/version'
14
14
  module RestBaby
15
15
  # Sends and receives data to a restful web service
16
16
  class Client
17
+ PARAMETER_STARTER = "?"
18
+ PARAMETER_SEPARATOR = "&"
19
+
17
20
  # The WebService Response from the last call
18
21
  attr_reader :wsresponse
19
22
  # The user (for authentication)
@@ -59,11 +62,13 @@ module RestBaby
59
62
 
60
63
  # Basic web services Get command
61
64
  #
62
- # @param path [String] Path of service to send the command to
63
- # @param headers [String] header parameters including authorization and Content-Type
65
+ # @param headers [Hash] header parameters including authorization and Content-Type
66
+ # @param path [String] Path of service to send the command to
67
+ # @param parameters [Hash] query string that added as part of the URL
64
68
  # @return The response from the rest server is returned
65
- def get(headers = {}, path = '')
66
- uri = URI.parse("#{@url}#{path}")
69
+ def get(headers = {}, path = '', parameters = {})
70
+ full_path = path_with_params(path, parameters)
71
+ uri = URI.parse("#{@url}#{full_path}")
67
72
  return request(uri, Net::HTTP::Get.new(uri.request_uri), nil, headers)
68
73
  end
69
74
 
@@ -114,7 +119,12 @@ module RestBaby
114
119
  end
115
120
 
116
121
  private
117
-
122
+
123
+ def path_with_params(path, params)
124
+ encoded_params = URI.encode_www_form(params)
125
+ [path, encoded_params].join("?")
126
+ end
127
+
118
128
  # Sending the web services command
119
129
  #
120
130
  # @param uri [URI] Uri to send the command to
@@ -140,9 +150,14 @@ module RestBaby
140
150
 
141
151
  # Print the Request
142
152
  def print_request(request, http, uri)
153
+ if uri.query==''
154
+ query = ''
155
+ else
156
+ query = "?#{uri.query}"
157
+ end
143
158
  if @verbose
144
159
  puts ">> REQUEST"
145
- puts "> URL: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}"
160
+ puts "> URL: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}#{query}"
146
161
  puts "> Headers: "
147
162
  request.each { |key, value| puts " > #{key}: #{value}" }
148
163
  # puts "> Basic_Auth #{request.basic_auth}"
@@ -174,7 +189,7 @@ module RestBaby
174
189
  elsif response.header['Content-Type']=='text/csv'
175
190
  puts response.body
176
191
  elsif response.header['Content-Type']=='application/xml'
177
- puts pretty_xml(response.body)
192
+ puts pretty_xml(body)
178
193
  elsif response.body.nil?
179
194
  puts "[Empty]"
180
195
  else
data/rest_baby.gemspec CHANGED
@@ -18,12 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "nokogiri"
22
- spec.add_dependency "json", ">= 1.8.0"
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "cucumber", ">= 1.3.5"
26
- spec.add_development_dependency "fig_newton", ">= 0.9"
27
- spec.add_development_dependency "rspec", "2.8.0"
28
- spec.add_development_dependency "webmock", ">= 1.13.0"
21
+ spec.add_dependency 'nokogiri', '~> 0'
22
+ spec.add_dependency 'json', '~> 1.8', '>= 1.8.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake', '~> 0'
25
+ spec.add_development_dependency 'cucumber', '~> 1.3', '>= 1.3.5'
26
+ spec.add_development_dependency 'fig_newton', '~> 0.9'
27
+ spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
28
+ spec.add_development_dependency 'webmock', '~> 1.13', '>= 1.13.0'
29
+
29
30
  end
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_baby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave McNulla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
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: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
36
  version: 1.8.0
@@ -35,6 +38,9 @@ dependencies:
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: 1.8.0
@@ -56,20 +62,23 @@ dependencies:
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ">="
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ">="
72
+ - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: cucumber
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
73
82
  - - ">="
74
83
  - !ruby/object:Gem::Version
75
84
  version: 1.3.5
@@ -77,6 +86,9 @@ dependencies:
77
86
  prerelease: false
78
87
  version_requirements: !ruby/object:Gem::Requirement
79
88
  requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.3'
80
92
  - - ">="
81
93
  - !ruby/object:Gem::Version
82
94
  version: 1.3.5
@@ -84,34 +96,43 @@ dependencies:
84
96
  name: fig_newton
85
97
  requirement: !ruby/object:Gem::Requirement
86
98
  requirements:
87
- - - ">="
99
+ - - "~>"
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0.9'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
93
105
  requirements:
94
- - - ">="
106
+ - - "~>"
95
107
  - !ruby/object:Gem::Version
96
108
  version: '0.9'
97
109
  - !ruby/object:Gem::Dependency
98
110
  name: rspec
99
111
  requirement: !ruby/object:Gem::Requirement
100
112
  requirements:
101
- - - '='
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '2.14'
116
+ - - ">="
102
117
  - !ruby/object:Gem::Version
103
- version: 2.8.0
118
+ version: 2.14.1
104
119
  type: :development
105
120
  prerelease: false
106
121
  version_requirements: !ruby/object:Gem::Requirement
107
122
  requirements:
108
- - - '='
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.14'
126
+ - - ">="
109
127
  - !ruby/object:Gem::Version
110
- version: 2.8.0
128
+ version: 2.14.1
111
129
  - !ruby/object:Gem::Dependency
112
130
  name: webmock
113
131
  requirement: !ruby/object:Gem::Requirement
114
132
  requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '1.13'
115
136
  - - ">="
116
137
  - !ruby/object:Gem::Version
117
138
  version: 1.13.0
@@ -119,6 +140,9 @@ dependencies:
119
140
  prerelease: false
120
141
  version_requirements: !ruby/object:Gem::Requirement
121
142
  requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.13'
122
146
  - - ">="
123
147
  - !ruby/object:Gem::Version
124
148
  version: 1.13.0
@@ -186,6 +210,7 @@ files:
186
210
  - features/support/env.rb
187
211
  - features/support/mock_rest_service.rb
188
212
  - features/support/utility.rb
213
+ - features/url_parameter.feature
189
214
  - lib/rest_baby.rb
190
215
  - lib/rest_baby/version.rb
191
216
  - rest_baby.gemspec
@@ -222,4 +247,5 @@ test_files:
222
247
  - features/support/env.rb
223
248
  - features/support/mock_rest_service.rb
224
249
  - features/support/utility.rb
250
+ - features/url_parameter.feature
225
251
  has_rdoc: