parliament-ruby 0.8.0 → 0.9.0
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/.ruby-version +1 -1
- data/Makefile +4 -0
- data/gocd/pdswebops.yaml +59 -0
- data/gocd/web1devci.yaml +65 -0
- data/lib/parliament/request/base_request.rb +50 -4
- data/lib/parliament/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd8ab1c11e6470f8abfe331460e88a27dbb744e
|
4
|
+
data.tar.gz: 38b07e70b348261edca867875f58046e00e750ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc5d91fd689c2586d0e48255a09804f0b099268b2cced988294e2fc01fd7989c06fdc0a90ab1e75719442d8637b653956adc9b56f67de26185f4072d10253ed
|
7
|
+
data.tar.gz: 74298480dd4af4d1d69716b7067a5f2d1110ec20659fafb1394b109ca7daffe2b10f24be811fcd97004db2bd5a2e17611efe04295fb85fb4d73e2aa8e80a31dc
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/Makefile
CHANGED
@@ -10,6 +10,10 @@ REL_TAG=$(shell curl -s $(LATEST_REL) | jq -r '.[0].tag_name')
|
|
10
10
|
checkout_to_release:
|
11
11
|
git checkout -b release $(REL_TAG)
|
12
12
|
|
13
|
+
checkout_to_pull_request:
|
14
|
+
git fetch origin refs/pull/$(PULL_REQUEST_NUMBER)/merge
|
15
|
+
git checkout $(shell git show-ref –s refs/pull/$(PULL_REQUEST_NUMBER)/merge)
|
16
|
+
|
13
17
|
gemset:
|
14
18
|
rvm gemset create parliament-ruby
|
15
19
|
rvm --force gemset empty parliament-ruby
|
data/gocd/pdswebops.yaml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
pipelines:
|
2
|
+
parliament-ruby:
|
3
|
+
group: parliament-ruby
|
4
|
+
label_template: "${COUNT}"
|
5
|
+
materials:
|
6
|
+
parliament-ruby-git:
|
7
|
+
git: https://github.com/jammycakes/ukpds.parliament-ruby.git
|
8
|
+
branch: master
|
9
|
+
auto_update: true
|
10
|
+
stages:
|
11
|
+
- release:
|
12
|
+
jobs:
|
13
|
+
release:
|
14
|
+
tasks:
|
15
|
+
- exec:
|
16
|
+
run_if: passed
|
17
|
+
command: make
|
18
|
+
arguments:
|
19
|
+
- release
|
20
|
+
|
21
|
+
parliament-ruby-PR:
|
22
|
+
group: parliament-ruby
|
23
|
+
label_template: "${COUNT}"
|
24
|
+
materials:
|
25
|
+
parliament-ruby-pr-git:
|
26
|
+
git: https://github.com/jammycakes/ukpds.parliament-ruby.git
|
27
|
+
branch: master
|
28
|
+
auto_update: true
|
29
|
+
environment_variables:
|
30
|
+
PULL_REQUEST_NUMBER:
|
31
|
+
PULL_REQUEST_HEAD_SHA1:
|
32
|
+
PULL_REQUEST_MERGE_SHA1:
|
33
|
+
stages:
|
34
|
+
- build:
|
35
|
+
approval: manual
|
36
|
+
jobs:
|
37
|
+
build:
|
38
|
+
tasks:
|
39
|
+
- exec:
|
40
|
+
run_if: passed
|
41
|
+
command: make
|
42
|
+
arguments:
|
43
|
+
- checkout_to_pull_request
|
44
|
+
- exec:
|
45
|
+
run_if: passed
|
46
|
+
command: make
|
47
|
+
arguments:
|
48
|
+
- build
|
49
|
+
- exec:
|
50
|
+
run_if: passed
|
51
|
+
command: make
|
52
|
+
arguments:
|
53
|
+
- test
|
54
|
+
|
55
|
+
environments:
|
56
|
+
Web.DEVCI:
|
57
|
+
pipelines:
|
58
|
+
- parliament-ruby
|
59
|
+
- parliament-ruby-PR
|
data/gocd/web1devci.yaml
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
pipelines:
|
2
|
+
GEM-parliament-ruby:
|
3
|
+
group: GEM-parliament-ruby
|
4
|
+
label_template: "${COUNT}"
|
5
|
+
materials:
|
6
|
+
parliament-ruby-git:
|
7
|
+
git: https://github.com/ukparliament/parliament-ruby.git
|
8
|
+
branch: master
|
9
|
+
auto_update: true
|
10
|
+
stages:
|
11
|
+
- release:
|
12
|
+
approval: manual
|
13
|
+
jobs:
|
14
|
+
release:
|
15
|
+
tasks:
|
16
|
+
- exec:
|
17
|
+
run_if: passed
|
18
|
+
command: make
|
19
|
+
arguments:
|
20
|
+
- checkout_to_release
|
21
|
+
- exec:
|
22
|
+
run_if: passed
|
23
|
+
command: make
|
24
|
+
arguments:
|
25
|
+
- release
|
26
|
+
|
27
|
+
GEM-parliament-ruby-PR:
|
28
|
+
group: GEM-parliament-ruby
|
29
|
+
label_template: "${COUNT}"
|
30
|
+
materials:
|
31
|
+
parliament-ruby-pr-git:
|
32
|
+
git: https://github.com/ukparliament/parliament-ruby.git
|
33
|
+
branch: master
|
34
|
+
auto_update: true
|
35
|
+
environment_variables:
|
36
|
+
PULL_REQUEST_NUMBER:
|
37
|
+
PULL_REQUEST_HEAD_SHA1:
|
38
|
+
PULL_REQUEST_MERGE_SHA1:
|
39
|
+
stages:
|
40
|
+
- test:
|
41
|
+
approval: manual
|
42
|
+
jobs:
|
43
|
+
test:
|
44
|
+
tasks:
|
45
|
+
- exec:
|
46
|
+
run_if: passed
|
47
|
+
command: make
|
48
|
+
arguments:
|
49
|
+
- checkout_to_pull_request
|
50
|
+
- exec:
|
51
|
+
run_if: passed
|
52
|
+
command: make
|
53
|
+
arguments:
|
54
|
+
- build
|
55
|
+
- exec:
|
56
|
+
run_if: passed
|
57
|
+
command: make
|
58
|
+
arguments:
|
59
|
+
- test
|
60
|
+
|
61
|
+
environments:
|
62
|
+
Web.DEVCI:
|
63
|
+
pipelines:
|
64
|
+
- GEM-parliament-ruby
|
65
|
+
- GEM-parliament-ruby-PR
|
@@ -106,6 +106,52 @@ module Parliament
|
|
106
106
|
build_response(net_response)
|
107
107
|
end
|
108
108
|
|
109
|
+
# Makes an HTTP POST request and process results into a response.
|
110
|
+
#
|
111
|
+
# @example HTTP POST request
|
112
|
+
# request = Parliament::Request::BaseRequest.new(base_url: 'http://example.com/people/123', headers: {'Content': 'application/json', 'Accept': 'application/json'})
|
113
|
+
#
|
114
|
+
# # url: http://example.com/people/123
|
115
|
+
#
|
116
|
+
# response = request.post(body: {}.to_json) #=> #<Parliament::Response::BaseResponse ...>
|
117
|
+
#
|
118
|
+
# @example HTTP POST request with URI encoded form values
|
119
|
+
# request = Parliament::Request::BaseRequest.new(base_url: 'http://example.com/people/current', headers: {'Content': 'application/json', 'Accept': 'application/json'})
|
120
|
+
#
|
121
|
+
# # url: http://example.com/people/current?limit=10&page=4&lang=en-gb
|
122
|
+
#
|
123
|
+
# response = request.post({ limit: 10, page: 4, lang: 'en-gb' }, body: {}.to_json) #=> #<Parliament::Response::BaseResponse ...>
|
124
|
+
#
|
125
|
+
# @raise [Parliament::ServerError] when the server responds with a 5xx status code.
|
126
|
+
# @raise [Parliament::ClientError] when the server responds with a 4xx status code.
|
127
|
+
# @raise [Parliament::NoContentResponseError] when the response body is empty.
|
128
|
+
#
|
129
|
+
# @param [Hash] params (optional) additional URI encoded form values to be added to the URI.
|
130
|
+
# @param [String] body (optional) body of the post request.
|
131
|
+
#
|
132
|
+
# @return [Parliament::Response::BaseResponse] a Parliament::Response::BaseResponse object containing all of the data returned from the URL.
|
133
|
+
def post(params: nil, body: nil)
|
134
|
+
@query_params = @query_params.merge(params) unless params.nil?
|
135
|
+
|
136
|
+
endpoint_uri = URI.parse(query_url)
|
137
|
+
endpoint_uri.query = URI.encode_www_form(@query_params.to_a) unless @query_params.empty?
|
138
|
+
|
139
|
+
http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
|
140
|
+
http.use_ssl = true if endpoint_uri.scheme == 'https'
|
141
|
+
|
142
|
+
net_response = http.start do |h|
|
143
|
+
api_request = Net::HTTP::Post.new(endpoint_uri.request_uri)
|
144
|
+
add_headers(api_request)
|
145
|
+
api_request.body = body unless body.nil?
|
146
|
+
|
147
|
+
h.request api_request
|
148
|
+
end
|
149
|
+
|
150
|
+
handle_errors(net_response)
|
151
|
+
|
152
|
+
build_response(net_response)
|
153
|
+
end
|
154
|
+
|
109
155
|
private
|
110
156
|
|
111
157
|
# @attr [String] base_url the base url of our api. (expected: http://example.com - without the trailing slash).
|
@@ -133,17 +179,17 @@ module Parliament
|
|
133
179
|
end
|
134
180
|
end
|
135
181
|
|
136
|
-
def handle_errors(
|
137
|
-
case
|
182
|
+
def handle_errors(net_response)
|
183
|
+
case net_response
|
138
184
|
when Net::HTTPOK # 2xx Status
|
139
|
-
exception_class = Parliament::NoContentResponseError if
|
185
|
+
exception_class = Parliament::NoContentResponseError if net_response['Content-Length'] == '0'
|
140
186
|
when Net::HTTPClientError # 4xx Status
|
141
187
|
exception_class = Parliament::ClientError
|
142
188
|
when Net::HTTPServerError # 5xx Status
|
143
189
|
exception_class = Parliament::ServerError
|
144
190
|
end
|
145
191
|
|
146
|
-
raise exception_class.new(query_url,
|
192
|
+
raise exception_class.new(query_url, net_response) if exception_class
|
147
193
|
end
|
148
194
|
end
|
149
195
|
end
|
data/lib/parliament/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parliament-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Rayner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,8 @@ files:
|
|
157
157
|
- Rakefile
|
158
158
|
- bin/console
|
159
159
|
- bin/setup
|
160
|
+
- gocd/pdswebops.yaml
|
161
|
+
- gocd/web1devci.yaml
|
160
162
|
- lib/parliament.rb
|
161
163
|
- lib/parliament/builder.rb
|
162
164
|
- lib/parliament/builder/base_response_builder.rb
|