From 91b75adddea9389af8f0a218587bca5330931ee9 Mon Sep 17 00:00:00 2001 From: Dylan Bowker Date: Thu, 7 Nov 2024 21:02:20 -0700 Subject: [PATCH] fix: `Status` enums weren't roundtripping --- CHANGELOG.md | 5 +++ Cargo.toml | 4 +-- src/directions/response/status.rs | 34 ++++++++++++------- src/distance_matrix/response/status.rs | 24 ++++++++----- src/elevation/response/status.rs | 21 +++++++----- src/geocoding/response/status.rs | 23 ++++++++----- .../place_autocomplete/response/status.rs | 21 +++++++----- src/places/status.rs | 24 ++++++++----- src/roads/status.rs | 12 +++---- src/time_zone/response/status.rs | 24 ++++++++----- 10 files changed, 121 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d213a..c96e968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ * Release notes are available on [GitHub](https://github.com/leontoeides/google_maps/releases). +# 3.7.2 + +* 2024-11-07: Corrected issue with `Status` enums not round-tripping through + de-serialisation and re-serialisation. + # 3.7.1 * 2024-10-15: Small tweaks to the features. Put back `enable-reqwest`. diff --git a/Cargo.toml b/Cargo.toml index 4fb7ba9..1d84dda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "google_maps" -version = "3.7.1" +version = "3.7.2" authors = ["Dylan Bowker "] edition = "2021" categories = ["api-bindings"] @@ -125,7 +125,7 @@ rust_decimal_macros = "1" serde = { version = "1.0", features = ["derive"] } simd-json = "0.14" stream_throttle = { version = "0.5", optional = true } -thiserror = "1.0" +thiserror = "2.0" tokio = { version = "1", optional = true, features = ["time"] } tracing = { version = "0.1", features = ["log"] } diff --git a/src/directions/response/status.rs b/src/directions/response/status.rs index d35a17e..c221846 100644 --- a/src/directions/response/status.rs +++ b/src/directions/response/status.rs @@ -6,37 +6,42 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// The `status` field within the Directions response object contains the /// [status](https://developers.google.com/maps/documentation/directions/intro#StatusCodes) /// of the request, and may contain debugging information to help you track down /// why the Directions service failed. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates that the provided request was invalid. Common causes of this /// status include an invalid parameter or parameter value. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates the requested route is too long and cannot be processed. This /// error occurs when more complex directions are returned. Try reducing the /// number of waypoints, turns, or instructions. - #[serde(alias = "MAX_ROUTE_LENGTH_EXCEEDED")] + #[serde(alias = "MaxRouteLengthExceeded")] MaxRouteLengthExceeded, + /// Indicates that too many `waypoints` were provided in the request. For /// applications using the Directions API as a web service, or the /// [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), /// the maximum allowed number of `waypoints` is 25, plus the origin and /// destination. - #[serde(alias = "MAX_WAYPOINTS_EXCEEDED")] + #[serde(alias = "MaxWaypointsExceeded")] MaxWaypointsExceeded, + /// Indicates at least one of the locations specified in the request's /// origin, destination, or waypoints could not be geocoded. - #[serde(alias = "NOT_FOUND")] + #[serde(alias = "NotFound")] NotFound, + /// Indicates the response contains a valid `result`. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * The API key is missing or invalid. /// * Billing has not been enabled on your account. @@ -47,22 +52,27 @@ pub enum Status { /// See the [Maps /// FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to /// learn how to fix this. - #[serde(alias = "OVER_DAILY_LIMIT")] + + #[serde(alias = "OverDailyLimit")] OverDailyLimit, + /// Indicates the service has received too many requests from your /// application within the allowed time period. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that the service denied use of the directions service by your /// application. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates a directions request could not be processed due to a server /// error. The request may succeed if you try again. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, + /// Indicates no route could be found between the origin and destination. - #[serde(alias = "ZERO_RESULTS")] + #[serde(alias = "ZeroResults")] ZeroResults, } // enum diff --git a/src/distance_matrix/response/status.rs b/src/distance_matrix/response/status.rs index 49bc2c1..b6c10da 100644 --- a/src/distance_matrix/response/status.rs +++ b/src/distance_matrix/response/status.rs @@ -6,27 +6,30 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// The `status` fields within the response object contain the status of the /// request, and may contain useful debugging information. The Distance Matrix /// API returns a top-level status field, with information about the request in /// general, as well as a status field for each element field, with information /// about that particular origin-destination pairing. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates that the provided request was invalid. Common causes of this /// status include an invalid parameter or parameter value. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates that the product of origins and destinations exceeds the /// per-query /// [limit](https://developers.google.com/maps/documentation/distance-matrix/usage-and-billing). - #[serde(alias = "MAX_ELEMENTS_EXCEEDED")] + #[serde(alias = "MaxElementsExceeded")] MaxElementsExceeded, + /// Indicates the response contains a valid `result`. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * The API key is missing or invalid. /// * Billing has not been enabled on your account. @@ -37,19 +40,22 @@ pub enum Status { /// See the [Maps /// FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to /// learn how to fix this. - #[serde(alias = "OVER_DAILY_LIMIT")] + #[serde(alias = "OverDailyLimit")] OverDailyLimit, + /// Indicates the service has received too many requests from your /// application within the allowed time period. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that the service denied use of the Distance Matrix service by /// your application. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates a Distance Matrix request could not be processed due to a /// server error. The request may succeed if you try again. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, } // enum diff --git a/src/elevation/response/status.rs b/src/elevation/response/status.rs index 36b474b..3bb8041 100644 --- a/src/elevation/response/status.rs +++ b/src/elevation/response/status.rs @@ -6,17 +6,19 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates that the request was malformed. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates that the request was successful. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * The API key is missing or invalid. /// * Billing has not been enabled on your account. @@ -27,16 +29,19 @@ pub enum Status { /// See the [Maps /// FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to /// learn how to fix this. - #[serde(alias = "OVER_DAILY_LIMIT")] + #[serde(alias = "OverDailyLimit")] OverDailyLimit, + /// Indicates the requestor has exceeded quota. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that the API did not complete the request. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates an unknown error. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, } // enum diff --git a/src/geocoding/response/status.rs b/src/geocoding/response/status.rs index 442e4e8..a73bfb6 100644 --- a/src/geocoding/response/status.rs +++ b/src/geocoding/response/status.rs @@ -7,20 +7,23 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Generally indicates one of the following: /// * The query (`address`, `components` or `latlng`) is missing. /// * An invalid `result_type` or `location_type` was given. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates that no errors occurred; the address was successfully parsed /// and at least one geocode was returned. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * The API key is missing or invalid. /// * Billing has not been enabled on your account. @@ -31,23 +34,27 @@ pub enum Status { /// See the [Maps /// FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to /// learn how to fix this. - #[serde(alias = "OVER_DAILY_LIMIT")] + #[serde(alias = "OverDailyLimit")] OverDailyLimit, + /// Indicates the requestor has exceeded quota. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that the API did not complete the request. Confirm that the /// request was sent over HTTPS instead of HTTP. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates that the request could not be processed due to a server error. /// The request may succeed if you try again. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, + /// Indicates that the geocode was successful but returned no results. This /// may occur if the geocoder was passed a non-existent `address`. This may /// also occur if the geocoder was passed a `latlng` in a remote location. - #[serde(alias = "ZERO_RESULTS")] + #[serde(alias = "ZeroResults")] ZeroResults, } // enum diff --git a/src/places/place_autocomplete/response/status.rs b/src/places/place_autocomplete/response/status.rs index 2d194ab..4ab6846 100644 --- a/src/places/place_autocomplete/response/status.rs +++ b/src/places/place_autocomplete/response/status.rs @@ -7,18 +7,20 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates the API request was malformed, generally due to the missing /// input parameter. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates that the request was successful. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * You have exceeded the QPS limits. /// * Billing has not been enabled on your account. @@ -29,19 +31,22 @@ pub enum Status { /// /// See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) /// for more information about how to resolve this error. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that your request was denied, generally because: /// * The request is missing an API key. /// * The key parameter is invalid. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates an unknown error. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, + /// Indicates that the search was successful but returned no results. This /// may occur if the search was passed a bounds in a remote location. - #[serde(alias = "ZERO_RESULTS")] + #[serde(alias = "ZeroResults")] ZeroResults, } // struct diff --git a/src/places/status.rs b/src/places/status.rs index 6b5d8f8..bb597a7 100644 --- a/src/places/status.rs +++ b/src/places/status.rs @@ -7,22 +7,25 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates that the request was successful. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates that the search was successful but returned no results. This /// may occur if the search was passed a `latlng` in a remote location. - #[serde(alias = "ZERO_RESULTS")] + #[serde(alias = "ZeroResults")] ZeroResults, + /// Indicates the API request was malformed, generally due to missing /// required query parameter (`location` or `radius`). - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates any of the following: /// * You have exceeded the QPS limits. /// * Billing has not been enabled on your account. @@ -33,19 +36,22 @@ pub enum Status { /// /// See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) /// for more information about how to resolve this error. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that your request was denied, generally because: /// * The request is missing an API key. /// * The `key` parameter is invalid. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates an unknown error. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, + /// Indicates that that the referenced location, `place_id`, was not found /// in the Places database. - #[serde(alias = "NOT_FOUND")] + #[serde(alias = "NotFound")] NotFound, } // struct diff --git a/src/roads/status.rs b/src/roads/status.rs index a28dd0e..ed0d7b4 100644 --- a/src/roads/status.rs +++ b/src/roads/status.rs @@ -7,10 +7,10 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// 1. Your API key is not valid or was not included in the request. Please /// ensure that you've included the entire key, and that you've enabled @@ -28,7 +28,7 @@ pub enum Status { /// parameters may be specified for each request. /// This error will not be returned if a `placeId` is passed for a road /// which no longer exists, or for a place which is not a road. - #[serde(alias = "INVALID_ARGUMENT")] + #[serde(alias = "InvalidArgument")] InvalidArgument, /// The request was denied for one or more of the following reasons: @@ -48,12 +48,12 @@ pub enum Status { /// on your account. /// * [Adjust your usage cap](https://developers.google.com/maps/documentation/roads/errors?hl=en#usage-cap) /// to increase your daily limit (if applicable). - #[serde(alias = "PERMISSION_DENIED")] + #[serde(alias = "PermissionDenied")] PermissionDenied, /// Ensure that you are sending requests to `https://roads.googleapis.com/` /// and not `http://roads.googleapis.com/`. - #[serde(alias = "NOT_FOUND")] + #[serde(alias = "NotFound")] NotFound, /// You have exceeded the request limit that you configured in the Google @@ -62,7 +62,7 @@ pub enum Status { /// limit should be configured to prevent a single or small group of users /// from exhausting your daily quota, while still allowing reasonable access /// to all users. See Capping API Usage to configure these limits. - #[serde(alias = "RESOURCE_EXHAUSTED")] + #[serde(alias = "ResourceExhausted")] ResourceExhausted, } // struct diff --git a/src/time_zone/response/status.rs b/src/time_zone/response/status.rs index c14ea54..6b2807f 100644 --- a/src/time_zone/response/status.rs +++ b/src/time_zone/response/status.rs @@ -7,17 +7,19 @@ use phf::phf_map; use serde::{Deserialize, Deserializer, Serialize}; // ----------------------------------------------------------------------------- - +// /// Indicates the status of the response. - #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE", deserialize = "SCREAMING_SNAKE_CASE"))] pub enum Status { /// Indicates that the request was malformed. - #[serde(alias = "INVALID_REQUEST")] + #[serde(alias = "InvalidRequest")] InvalidRequest, + /// Indicates that the request was successful. - #[serde(alias = "OK")] + #[serde(alias = "Ok")] Ok, + /// Indicates any of the following: /// * The API key is missing or invalid. /// * Billing has not been enabled on your account. @@ -28,22 +30,26 @@ pub enum Status { /// See the [Maps /// FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to /// learn how to fix this. - #[serde(alias = "OVER_DAILY_LIMIT")] + #[serde(alias = "OverDailyLimit")] OverDailyLimit, + /// Indicates the requestor has exceeded quota. - #[serde(alias = "OVER_QUERY_LIMIT")] + #[serde(alias = "OverQueryLimit")] OverQueryLimit, + /// Indicates that the API did not complete the request. Confirm that the /// request was sent over HTTPS instead of HTTP. - #[serde(alias = "REQUEST_DENIED")] + #[serde(alias = "RequestDenied")] RequestDenied, + /// Indicates an unknown error. - #[serde(alias = "UNKNOWN_ERROR")] + #[serde(alias = "UnknownError")] UnknownError, + /// Indicates that no time zone data could be found for the specified /// position or time. Confirm that the request is for a location on land, /// and not over water. - #[serde(alias = "ZERO_RESULTS")] + #[serde(alias = "ZeroResults")] ZeroResults, } // struct