gds-api-adapters 59.0.0 → 59.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea4856342a5a29a9b5bdfd101a1df68c4685673ef36a4841b9b52628dd33e94e
4
- data.tar.gz: 51c94fbec84e8403b08559b1c6bc8feab2322b24ebbfee19d333607e0f8e9bd7
3
+ metadata.gz: 5545c2f65d5f31f2aaf737590b5204ee385ec783ad553d09515ac0b7e3d73929
4
+ data.tar.gz: 850f74dc5f709157bad18d79308edd76ae3323b8e33d867ebfda9f075eb82b65
5
5
  SHA512:
6
- metadata.gz: 69021b367b2910f54b7c03cb09dc39c46c5f2e430539631f6f75b9a53bf77a38ff8f2e9c36eab0cb959bfde1cada2be5b04a9c5bea6ad484cb0de89a3b1e73fe
7
- data.tar.gz: d93067152fb831d8526435825f9cc30f430e67d3f4f29d67e5328825e8f41a99b05cc51f812ad43426a8fdab3f668a57926862b2236a27b9fa8a1ee535118361
6
+ metadata.gz: ce46e8885c9e7b37cffa51ff0a3666270e825ccc073c17659d23d85ed15598f190eb8b016f599aec26275c829062106e3d7500b76f74a0b88bfa194d76568901
7
+ data.tar.gz: af840ab6b6d7053d2e746bdfe64fc5a00daeba7105d7bbabf771ba54c74e539579cd95d3de2131936d06113063865644f096a858cd4a0ca352e270f9f6791721
data/Rakefile CHANGED
@@ -37,5 +37,5 @@ end
37
37
 
38
38
  desc "Run the linter against changed files"
39
39
  task :lint do
40
- sh "bundle exec govuk-lint-ruby --diff --cached --format clang"
40
+ sh "bundle exec govuk-lint-ruby --format clang lib test"
41
41
  end
data/lib/gds_api/base.rb CHANGED
@@ -41,6 +41,7 @@ class GdsApi::Base
41
41
  def initialize(endpoint_url, options = {})
42
42
  options[:endpoint_url] = endpoint_url
43
43
  raise InvalidAPIURL unless endpoint_url =~ URI::RFC3986_Parser::RFC3986_URI
44
+
44
45
  base_options = { logger: GdsApi::Base.logger }
45
46
  default_options = base_options.merge(GdsApi::Base.default_options || {})
46
47
  @options = default_options.merge(options)
@@ -65,6 +65,7 @@ private
65
65
  def redirect_for_path(path)
66
66
  redirects_by_segments.find do |r|
67
67
  next true if r["path"] == path
68
+
68
69
  route_prefix_match?(r["path"], path) if r["type"] == "prefix"
69
70
  end
70
71
  end
@@ -3,7 +3,7 @@ require_relative 'base'
3
3
  class GdsApi::Imminence < GdsApi::Base
4
4
  def api_url(type, params)
5
5
  vals = %i[limit lat lng postcode].select { |p| params.include? p }
6
- querystring = URI.encode_www_form vals.map { |p| [p, params[p]] }
6
+ querystring = URI.encode_www_form(vals.map { |p| [p, params[p]] })
7
7
  "#{@endpoint}/places/#{type}.json?#{querystring}"
8
8
  end
9
9
 
@@ -12,7 +12,7 @@ module GdsApi
12
12
  attr_accessor :logger, :options
13
13
 
14
14
  def initialize(options = {})
15
- if options[:disable_timeout] || options[:timeout].to_i < 0
15
+ if options[:disable_timeout] || options[:timeout].to_i.negative?
16
16
  raise "It is no longer possible to disable the timeout."
17
17
  end
18
18
 
@@ -101,10 +101,10 @@ module GdsApi
101
101
  rescue RestClient::Exception => e
102
102
  # Attempt to parse the body as JSON if possible
103
103
  error_details = begin
104
- e.http_body ? JSON.parse(e.http_body) : nil
105
- rescue JSON::ParserError
106
- nil
107
- end
104
+ e.http_body ? JSON.parse(e.http_body) : nil
105
+ rescue JSON::ParserError
106
+ nil
107
+ end
108
108
  raise build_specific_http_error(e, url, error_details, params)
109
109
  end
110
110
 
@@ -174,7 +174,7 @@ module GdsApi
174
174
  method_params = with_ssl_options(method_params)
175
175
  end
176
176
 
177
- return ::RestClient::Request.execute(method_params)
177
+ ::RestClient::Request.execute(method_params)
178
178
  rescue Errno::ECONNREFUSED => e
179
179
  logger.error loggable.merge(status: 'refused', error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
180
180
  raise GdsApi::EndpointNotFound.new("Could not connect to #{url}")
@@ -7,6 +7,7 @@ class GdsApi::LicenceApplication < GdsApi::Base
7
7
 
8
8
  def details_for_licence(id, snac_code = nil)
9
9
  return nil if id.nil?
10
+
10
11
  get_json(build_licence_url(id, snac_code))
11
12
  end
12
13
 
@@ -31,6 +31,7 @@ module GdsApi
31
31
 
32
32
  def add_document(id, document, index_name)
33
33
  raise(InvalidIndex, index_name) unless index_name == 'metasearch'
34
+
34
35
  post_json(
35
36
  "#{base_url}/v2/metasearch/documents",
36
37
  document.merge(
@@ -41,6 +42,7 @@ module GdsApi
41
42
 
42
43
  def delete_document(id, index_name)
43
44
  raise(InvalidIndex, index_name) unless index_name == 'metasearch'
45
+
44
46
  delete_json("#{base_url}/v2/metasearch/documents/#{id}")
45
47
  end
46
48
  end
@@ -114,6 +116,7 @@ module GdsApi
114
116
  # @deprecated Only in use by Whitehall. Use the `#search` method.
115
117
  def advanced_search(args)
116
118
  raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
119
+
117
120
  request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
118
121
  get_json(request_path)
119
122
  end
@@ -51,9 +51,8 @@ class GdsApi::SupportApi < GdsApi::Base
51
51
  post_json("#{endpoint}/anonymous-feedback/content_improvement", params)
52
52
  end
53
53
 
54
- def anonymous_feedback(options = {})
55
- uri = "#{endpoint}/anonymous-feedback" + query_string(options)
56
- get_json(uri)
54
+ def anonymous_feedback(params = {})
55
+ post_json("#{endpoint}/anonymous-feedback", params)
57
56
  end
58
57
 
59
58
  def organisation_summary(organisation_slug, options = {})
@@ -1,4 +1,3 @@
1
-
2
1
  module GdsApi
3
2
  module TestHelpers
4
3
  module ContentItemHelpers
@@ -52,7 +52,8 @@ module GdsApi
52
52
 
53
53
  stub_request(:get, links[:self]).
54
54
  to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
55
- if i == 0
55
+
56
+ if i.zero?
56
57
  # First page exists at URL with and without page param
57
58
  stub_request(:get, links[:self].sub(/\?page=1/, '')).
58
59
  to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
@@ -123,6 +123,7 @@ module GdsApi
123
123
  case expected_value
124
124
  when Hash
125
125
  return false unless actual_value.is_a?(Hash)
126
+
126
127
  expected_value.all? do |expected_sub_key, expected_sub_value|
127
128
  actual_value.has_key?(expected_sub_key.to_s) &&
128
129
  values_match_recursively(expected_sub_value, actual_value[expected_sub_key.to_s])
@@ -130,6 +131,7 @@ module GdsApi
130
131
  when Array
131
132
  return false unless actual_value.is_a?(Array)
132
133
  return false unless actual_value.size == expected_value.size
134
+
133
135
  expected_value.each.with_index.all? do |expected_sub_value, i|
134
136
  values_match_recursively(expected_sub_value, actual_value[i])
135
137
  end
@@ -609,6 +609,7 @@ module GdsApi
609
609
 
610
610
  results = editions.map do |edition|
611
611
  next edition unless params[:fields]
612
+
612
613
  edition.select { |k| params[:fields].include?(k) }
613
614
  end
614
615
 
@@ -43,12 +43,14 @@ module GdsApi
43
43
  end
44
44
 
45
45
  def stub_route_registration(path, type, backend_id)
46
- route = { route: {
47
- incoming_path: path,
48
- route_type: type,
49
- handler: 'backend',
50
- backend_id: backend_id }
51
- }
46
+ route = {
47
+ route: {
48
+ incoming_path: path,
49
+ route_type: type,
50
+ handler: 'backend',
51
+ backend_id: backend_id
52
+ }
53
+ }
52
54
 
53
55
  register_stub = stub_route_put(route)
54
56
  commit_stub = stub_router_commit
@@ -56,14 +58,16 @@ module GdsApi
56
58
  end
57
59
 
58
60
  def stub_redirect_registration(path, type, destination, redirect_type, segments_mode = nil)
59
- redirect = { route: {
60
- incoming_path: path,
61
- route_type: type,
62
- handler: 'redirect',
63
- redirect_to: destination,
64
- redirect_type: redirect_type,
65
- segments_mode: segments_mode }
66
- }
61
+ redirect = {
62
+ route: {
63
+ incoming_path: path,
64
+ route_type: type,
65
+ handler: 'redirect',
66
+ redirect_to: destination,
67
+ redirect_type: redirect_type,
68
+ segments_mode: segments_mode,
69
+ }
70
+ }
67
71
 
68
72
  register_stub = stub_route_put(redirect)
69
73
  commit_stub = stub_router_commit
@@ -71,11 +75,13 @@ module GdsApi
71
75
  end
72
76
 
73
77
  def stub_gone_route_registration(path, type)
74
- route = { route: {
75
- incoming_path: path,
76
- route_type: type,
77
- handler: 'gone' }
78
- }
78
+ route = {
79
+ route: {
80
+ incoming_path: path,
81
+ route_type: type,
82
+ handler: 'gone',
83
+ }
84
+ }
79
85
 
80
86
  register_stub = stub_route_put(route)
81
87
  commit_stub = stub_router_commit
@@ -60,6 +60,7 @@ module GdsApi
60
60
  if id =~ %r{^/}
61
61
  raise ArgumentError, 'Rummager id must not start with a slash'
62
62
  end
63
+
63
64
  if index
64
65
  assert_requested(
65
66
  :delete,
@@ -133,8 +134,8 @@ module GdsApi
133
134
  def search_results_found
134
135
  File.read(
135
136
  File.expand_path(
136
- "../../../../test/fixtures/services_and_info_fixture.json",
137
- __FILE__
137
+ "../../../test/fixtures/services_and_info_fixture.json",
138
+ __dir__
138
139
  )
139
140
  )
140
141
  end
@@ -142,8 +143,8 @@ module GdsApi
142
143
  def no_search_results_found
143
144
  File.read(
144
145
  File.expand_path(
145
- "../../../../test/fixtures/no_services_and_info_data_found_fixture.json",
146
- __FILE__
146
+ "../../../test/fixtures/no_services_and_info_data_found_fixture.json",
147
+ __dir__
147
148
  )
148
149
  )
149
150
  end
@@ -151,8 +152,8 @@ module GdsApi
151
152
  def sub_sector_organisations_results
152
153
  File.read(
153
154
  File.expand_path(
154
- "../../../../test/fixtures/sub_sector_organisations.json",
155
- __FILE__
155
+ "../../../test/fixtures/sub_sector_organisations.json",
156
+ __dir__
156
157
  )
157
158
  )
158
159
  end
@@ -160,8 +161,8 @@ module GdsApi
160
161
  def new_policies_results
161
162
  File.read(
162
163
  File.expand_path(
163
- "../../../../test/fixtures/new_policies_for_dwp.json",
164
- __FILE__
164
+ "../../../test/fixtures/new_policies_for_dwp.json",
165
+ __dir__
165
166
  )
166
167
  )
167
168
  end
@@ -169,8 +170,8 @@ module GdsApi
169
170
  def old_policies_results
170
171
  File.read(
171
172
  File.expand_path(
172
- "../../../../test/fixtures/old_policies_for_dwp.json",
173
- __FILE__
173
+ "../../../test/fixtures/old_policies_for_dwp.json",
174
+ __dir__
174
175
  )
175
176
  )
176
177
  end
@@ -79,9 +79,9 @@ module GdsApi
79
79
  end
80
80
 
81
81
  def stub_support_api_anonymous_feedback(params, response_body = {})
82
- stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback").
83
- with(query: params).
84
- to_return(status: 200, body: response_body.to_json)
82
+ stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback")
83
+ .with(body: params)
84
+ .to_return(status: 200, body: response_body.to_json)
85
85
  end
86
86
 
87
87
  def stub_support_api_anonymous_feedback_organisation_summary(slug, ordering = nil, response_body = {})
@@ -30,7 +30,7 @@ module GdsApi
30
30
 
31
31
  links = { self: "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 1}" }
32
32
  links[:next] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 2}" if pages[i + 1]
33
- links[:previous] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i}" unless i == 0
33
+ links[:previous] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i}" unless i.zero?
34
34
  page_details["_response_info"]["links"] = []
35
35
  link_headers = []
36
36
  links.each do |rel, href|
@@ -40,7 +40,8 @@ module GdsApi
40
40
 
41
41
  stub_request(:get, links[:self]).
42
42
  to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
43
- if i == 0
43
+
44
+ if i.zero?
44
45
  # First page exists at URL with and without page param
45
46
  stub_request(:get, links[:self].sub(/\?page=1/, '')).
46
47
  to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '59.0.0'.freeze
2
+ VERSION = '59.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 59.0.0
4
+ version: 59.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-01 00:00:00.000000000 Z
11
+ date: 2019-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '3.7'
131
+ version: '3.11'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '3.7'
138
+ version: '3.11'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: minitest
141
141
  requirement: !ruby/object:Gem::Requirement