Skip to content

Commit

Permalink
fix: Status enums weren't roundtripping
Browse files Browse the repository at this point in the history
  • Loading branch information
leontoeides committed Nov 8, 2024
1 parent 9b7a94d commit 91b75ad
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "google_maps"
version = "3.7.1"
version = "3.7.2"
authors = ["Dylan Bowker <[email protected]>"]
edition = "2021"
categories = ["api-bindings"]
Expand Down Expand Up @@ -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"] }

Expand Down
34 changes: 22 additions & 12 deletions src/directions/response/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
24 changes: 15 additions & 9 deletions src/distance_matrix/response/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
21 changes: 13 additions & 8 deletions src/elevation/response/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
23 changes: 15 additions & 8 deletions src/geocoding/response/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
21 changes: 13 additions & 8 deletions src/places/place_autocomplete/response/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
24 changes: 15 additions & 9 deletions src/places/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
Loading

0 comments on commit 91b75ad

Please sign in to comment.