Skip to content

Commit

Permalink
Merge pull request #1235 from alphagov/upgrade-ruby-version
Browse files Browse the repository at this point in the history
Update minimum required Ruby version
  • Loading branch information
callumknights authored Feb 19, 2024
2 parents 97a9bd5 + 32e37a4 commit 52777e7
Show file tree
Hide file tree
Showing 33 changed files with 296 additions and 292 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: ['3.0', 3.1, 3.2]
ruby: [3.1, 3.2, 3.3]
runs-on: ubuntu-latest
env:
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.1.4
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

* Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
* Add support for Ruby 3.3.

# 93.0.0
* BREAKING: removed Support app `create_foi_request` method.
* Note: This is no longer used by any apps, so should not be breaking in practice.
Expand Down
2 changes: 1 addition & 1 deletion gds-api-adapters.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/alphagov/gds-api-adapters"
s.description = "A set of adapters providing easy access to the GDS GOV.UK APIs"

s.required_ruby_version = ">= 3.0"
s.required_ruby_version = ">= 3.1.4"
s.files = Dir.glob("lib/**/*") + Dir.glob("test/fixtures/**/*") + %w[README.md Rakefile]
s.require_path = "lib"
s.add_dependency "addressable"
Expand Down
16 changes: 8 additions & 8 deletions lib/gds_api/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class GdsApi::AccountApi < GdsApi::Base
def get_sign_in_url(redirect_path: nil, mfa: false)
querystring = nested_query_string(
{
redirect_path: redirect_path,
mfa: mfa,
redirect_path:,
mfa:,
}.compact,
)
get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}")
Expand All @@ -31,7 +31,7 @@ def get_sign_in_url(redirect_path: nil, mfa: false)
#
# @return [Hash] The value for the govuk_account_session header, the path to redirect the user to, and the GA client ID (if there is one)
def validate_auth_response(code:, state:)
post_json("#{endpoint}/api/oauth2/callback", code: code, state: state)
post_json("#{endpoint}/api/oauth2/callback", code:, state:)
end

# Get an OIDC end-session URL to redirect the user to
Expand Down Expand Up @@ -59,7 +59,7 @@ def get_user(govuk_account_session:)
#
# @return [Hash] One field, "match", indicating whether the session matches the given email address
def match_user_by_email(email:, govuk_account_session: nil)
querystring = nested_query_string({ email: email })
querystring = nested_query_string({ email: })
get_json("#{endpoint}/api/user/match-by-email?#{querystring}", auth_headers(govuk_account_session))
end

Expand All @@ -79,8 +79,8 @@ def delete_user_by_subject_identifier(subject_identifier:)
# @return [Hash] The user's subject identifier and email attributes
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil)
params = {
email: email,
email_verified: email_verified,
email:,
email_verified:,
}.compact

patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
Expand All @@ -93,7 +93,7 @@ def update_user_by_subject_identifier(subject_identifier:, email: nil, email_ver
#
# @return [Hash] The attribute values (if present), and a new session header
def get_attributes(attributes:, govuk_account_session:)
querystring = nested_query_string({ attributes: attributes }.compact)
querystring = nested_query_string({ attributes: }.compact)
get_json("#{endpoint}/api/attributes?#{querystring}", auth_headers(govuk_account_session))
end

Expand All @@ -104,7 +104,7 @@ def get_attributes(attributes:, govuk_account_session:)
#
# @return [Hash] A new session header
def set_attributes(attributes:, govuk_account_session:)
patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session))
patch_json("#{endpoint}/api/attributes", { attributes: }, auth_headers(govuk_account_session))
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/gds_api/asset_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GdsApi::AssetManager < GdsApi::Base
# response = asset_manager.create_asset(file: params[:file])
# response['content_type'] #=> "image/jpeg"
def create_asset(asset)
post_multipart("#{base_url}/assets", asset: asset)
post_multipart("#{base_url}/assets", asset:)
end

# Updates an asset given a hash with one +file+ attribute
Expand Down Expand Up @@ -76,7 +76,7 @@ def create_asset(asset)
# uuid = '594602dd-75b3-4e6f-b5d1-cacf8c4d4164'
# asset_manager.update_asset(uuid, file: File.new('image.jpg', 'r'))
def update_asset(id, asset)
put_multipart("#{base_url}/assets/#{id}", asset: asset)
put_multipart("#{base_url}/assets/#{id}", asset:)
end

# Fetches an asset's metadata given the id
Expand Down
34 changes: 17 additions & 17 deletions lib/gds_api/email_alert_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def unsubscribe_subscriber(id)
def subscribe(subscriber_list_id:, address:, frequency: "immediately", skip_confirmation_email: false)
post_json(
"#{endpoint}/subscriptions",
subscriber_list_id: subscriber_list_id,
address: address,
frequency: frequency,
skip_confirmation_email: skip_confirmation_email,
subscriber_list_id:,
address:,
frequency:,
skip_confirmation_email:,
)
end

Expand Down Expand Up @@ -166,7 +166,7 @@ def get_subscriptions(id:, order: nil)
def change_subscriber(id:, new_address:, on_conflict: nil)
patch_json(
"#{endpoint}/subscribers/#{uri_encode(id)}",
{ new_address: new_address, on_conflict: on_conflict }.compact,
{ new_address:, on_conflict: }.compact,
)
end

Expand All @@ -179,7 +179,7 @@ def change_subscriber(id:, new_address:, on_conflict: nil)
def change_subscription(id:, frequency:)
patch_json(
"#{endpoint}/subscriptions/#{uri_encode(id)}",
frequency: frequency,
frequency:,
)
end

Expand All @@ -191,7 +191,7 @@ def change_subscription(id:, frequency:)
def authenticate_subscriber_by_govuk_account(govuk_account_session:)
post_json(
"#{endpoint}/subscribers/govuk-account",
govuk_account_session: govuk_account_session,
govuk_account_session:,
)
end

Expand All @@ -206,7 +206,7 @@ def authenticate_subscriber_by_govuk_account(govuk_account_session:)
def link_subscriber_to_govuk_account(govuk_account_session:)
post_json(
"#{endpoint}/subscribers/govuk-account/link",
govuk_account_session: govuk_account_session,
govuk_account_session:,
)
end

Expand All @@ -231,8 +231,8 @@ def find_subscriber_by_govuk_account(govuk_account_id:)
def send_subscriber_verification_email(address:, destination:)
post_json(
"#{endpoint}/subscribers/auth-token",
address: address,
destination: destination,
address:,
destination:,
)
end

Expand All @@ -247,9 +247,9 @@ def send_subscriber_verification_email(address:, destination:)
def send_subscription_verification_email(address:, frequency:, topic_id:)
post_json(
"#{endpoint}/subscriptions/auth-token",
address: address,
frequency: frequency,
topic_id: topic_id,
address:,
frequency:,
topic_id:,
)
end

Expand All @@ -264,8 +264,8 @@ def bulk_unsubscribe(slug:, govuk_request_id: nil, body: nil, sender_message_id:
post_json(
"#{endpoint}/subscriber-lists/#{slug}/bulk-unsubscribe",
{
body: body,
sender_message_id: sender_message_id,
body:,
sender_message_id:,
}.compact,
{
"Govuk-Request-Id" => govuk_request_id,
Expand All @@ -281,8 +281,8 @@ def bulk_unsubscribe(slug:, govuk_request_id: nil, body: nil, sender_message_id:
def bulk_migrate(from_slug:, to_slug:)
post_json(
"#{endpoint}/subscriber-lists/bulk-migrate",
from_slug: from_slug,
to_slug: to_slug,
from_slug:,
to_slug:,
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/gds_api/imminence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ def api_url(type, params)
end

def places(type, lat, lon, limit = 5)
url = api_url(type, lat: lat, lng: lon, limit: limit)
url = api_url(type, lat:, lng: lon, limit:)
get_json(url)
end

def places_for_postcode(type, postcode, limit = 5, local_authority_slug = nil)
options = { postcode: postcode, limit: limit }
options.merge!(local_authority_slug: local_authority_slug) if local_authority_slug
options = { postcode:, limit: }
options.merge!(local_authority_slug:) if local_authority_slug
url = api_url(type, options)
get_json(url) || []
end
Expand Down
4 changes: 2 additions & 2 deletions lib/gds_api/json_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def do_request(method, url, params = nil, additional_headers = {})
logger.debug start_logging.to_json

method_params = {
method: method,
url: url,
method:,
url:,
}

method_params[:payload] = params
Expand Down
14 changes: 7 additions & 7 deletions lib/gds_api/link_checker_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class GdsApi::LinkCheckerApi < GdsApi::Base
# @raise [HTTPErrorResponse] if the request returns an error
def check(uri, synchronous: nil, checked_within: nil)
params = {
uri: uri,
synchronous: synchronous,
checked_within: checked_within,
uri:,
synchronous:,
checked_within:,
}

response = get_json(
Expand Down Expand Up @@ -54,10 +54,10 @@ def check(uri, synchronous: nil, checked_within: nil)
# @raise [HTTPErrorResponse] if the request returns an error
def create_batch(uris, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil)
payload = {
uris: uris,
checked_within: checked_within,
webhook_uri: webhook_uri,
webhook_secret_token: webhook_secret_token,
uris:,
checked_within:,
webhook_uri:,
webhook_secret_token:,
}

response = post_json(
Expand Down
20 changes: 10 additions & 10 deletions lib/gds_api/publishing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def get_content(content_id, params = {})
# @raise [NoLiveVersion] when the content item is not found
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2contentcontent_id
def get_live_content(content_id, locale = "en")
content_item = get_content(content_id, locale: locale)
content_item = get_content(content_id, locale:)

live_states = %w[published unpublished]
return content_item if live_states.include?(content_item.to_h["publication_state"])

live_version_number = content_item["state_history"].find { |_, v| live_states.include?(v) }&.first
raise NoLiveVersion, "No live version exists for content_id: #{content_id}" unless live_version_number

get_content(content_id, locale: locale, version: live_version_number)
get_content(content_id, locale:, version: live_version_number)
end

# Find the content_ids for a list of base_paths.
Expand All @@ -73,7 +73,7 @@ def get_live_content(content_id, locale = "en")
#
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-lookup-by-base-path
def lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
options = { base_paths: base_paths }
options = { base_paths: }
options[:exclude_document_types] = exclude_document_types if exclude_document_types
options[:exclude_unpublishing_types] = exclude_unpublishing_types if exclude_unpublishing_types
options[:with_drafts] = with_drafts if with_drafts
Expand Down Expand Up @@ -102,9 +102,9 @@ def lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpubli
def lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
lookups = lookup_content_ids(
base_paths: [base_path],
exclude_document_types: exclude_document_types,
exclude_unpublishing_types: exclude_unpublishing_types,
with_drafts: with_drafts,
exclude_document_types:,
exclude_unpublishing_types:,
with_drafts:,
)
lookups[base_path]
end
Expand All @@ -122,7 +122,7 @@ def lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublish
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_idpublish
def publish(content_id, update_type = nil, options = {})
params = {
update_type: update_type,
update_type:,
}

optional_keys = %i[locale previous_version]
Expand Down Expand Up @@ -168,7 +168,7 @@ def republish(content_id, options = {})
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_idunpublish
def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil, unpublished_at: nil, redirects: nil)
params = {
type: type,
type:,
}

params[:explanation] = explanation if explanation
Expand Down Expand Up @@ -435,7 +435,7 @@ def get_paged_editions(params = {})
# }
#
def get_links_for_content_ids(content_ids)
post_json("#{endpoint}/v2/links/by-content-id", content_ids: content_ids).to_hash
post_json("#{endpoint}/v2/links/by-content-id", content_ids:).to_hash
end

# Reserves a path for a publishing application
Expand All @@ -452,7 +452,7 @@ def put_path(base_path, payload)
end

def unreserve_path(base_path, publishing_app)
payload = { publishing_app: publishing_app }
payload = { publishing_app: }
delete_json(unreserve_url(base_path), payload)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/gds_api/publishing_api/special_route_publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def publish(options)
schema_name: options.fetch(:schema_name, "special_route"),
title: options.fetch(:title),
description: options.fetch(:description, ""),
locale: locale,
locale:,
details: {},
routes: [
{
Expand All @@ -33,11 +33,11 @@ def publish(options)
publishing_app: options.fetch(:publishing_app),
rendering_app: options.fetch(:rendering_app),
public_updated_at: time.now.iso8601,
update_type: update_type,
update_type:,
)

publishing_api.patch_links(options.fetch(:content_id), links: options[:links]) if options[:links]
publishing_api.publish(options.fetch(:content_id), update_type, locale: locale)
publishing_api.publish(options.fetch(:content_id), update_type, locale:)
put_content_response
end

Expand Down
4 changes: 2 additions & 2 deletions lib/gds_api/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add_route(path, type, backend_id)
incoming_path: path,
route_type: type,
handler: "backend",
backend_id: backend_id,
backend_id:,
},
)
end
Expand All @@ -41,7 +41,7 @@ def add_redirect_route(path, type, destination, redirect_type = "permanent", opt
route_type: type,
handler: "redirect",
redirect_to: destination,
redirect_type: redirect_type,
redirect_type:,
segments_mode: options[:segments_mode],
},
)
Expand Down
Loading

0 comments on commit 52777e7

Please sign in to comment.