diff --git a/.fern/metadata.json b/.fern/metadata.json index 6f31e54..cd6f489 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -6,5 +6,5 @@ "package-prefix": "com.samsara.api", "enable-wire-tests": true }, - "sdkVersion": "8.1.1" + "sdkVersion": "8.1.2" } \ No newline at end of file diff --git a/README.md b/README.md index c45d0d6..efe565b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Add the dependency in your `pom.xml` file: com.samsara samsara-java-sdk - 8.1.1 + 8.1.2 ``` diff --git a/reference.md b/reference.md index 6815c6b..90c1067 100644 --- a/reference.md +++ b/reference.md @@ -4207,185 +4207,6 @@ client.betaApIs().recoverAsset( - - - - -
client.betaApIs.listCarbCtcVehicles() -> CarbCtcListCarbCtcVehiclesResponseBody -
-
- -#### 📝 Description - -
-
- -
-
- -Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - - Rate limit: 5 requests/sec (learn more about rate limits here). - -To use this endpoint, select **Read CARB CTC Integration** under the Closed Beta category when creating or editing an API token. Learn More. - - - **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.betaApIs().listCarbCtcVehicles( - ListCarbCtcVehiclesRequest - .builder() - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**tagIds:** `Optional` — A filter on the data based on this comma-separated list of tag IDs. Example: `tagIds=1234,5678` - -
-
- -
-
- -**parentTagIds:** `Optional` — A filter on the data based on this comma-separated list of parent tag IDs, for use by orgs with tag hierarchies. Specifying a parent tag will implicitly include all descendent tags of the parent tag. Example: `parentTagIds=345,678` - -
-
- -
-
- -**testStatus:** `Optional` — Optional filter based on the test status. This parameter can be passed multiple times to filter by multiple statuses. - -
-
- -
-
- -**after:** `Optional` — If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results. - -
-
-
-
- - -
-
-
- -
client.betaApIs.listCarbCtcVehicleHistory() -> CarbCtcListCarbCtcVehicleHistoryResponseBody -
-
- -#### 📝 Description - -
-
- -
-
- -Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - - Rate limit: 5 requests/sec (learn more about rate limits here). - -To use this endpoint, select **Read CARB CTC Integration** under the Closed Beta category when creating or editing an API token. Learn More. - - - **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.betaApIs().listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest - .builder() - .vehicleIds("vehicleIds") - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**vehicleIds:** `String` — A comma-separated list of vehicle IDs to fetch history for. Up to 100 IDs can be provided. Example: `vehicleIds=1234,5678` - -
-
- -
-
- -**startTime:** `Optional` — A start time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00). - -
-
- -
-
- -**endTime:** `Optional` — An end time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00). - -
-
- -
-
- -**after:** `Optional` — If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results. - -
-
-
-
- -
@@ -12581,6 +12402,186 @@ client.driverQrCodes().deleteDriverQrCode( + + + + +## CarbCtc +
client.carbCtc.listCarbCtcVehicles() -> CarbCtcListCarbCtcVehiclesResponseBody +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + + Rate limit: 5 requests/sec (learn more about rate limits here). + +To use this endpoint, select **Read CARB CTC Integration** under the CARB CTC Integration category when creating or editing an API token. Learn More. + + + **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.carbCtc().listCarbCtcVehicles( + ListCarbCtcVehiclesRequest + .builder() + .build() +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**tagIds:** `Optional` — A filter on the data based on this comma-separated list of tag IDs. Example: `tagIds=1234,5678` + +
+
+ +
+
+ +**parentTagIds:** `Optional` — A filter on the data based on this comma-separated list of parent tag IDs, for use by orgs with tag hierarchies. Specifying a parent tag will implicitly include all descendent tags of the parent tag. Example: `parentTagIds=345,678` + +
+
+ +
+
+ +**testStatus:** `Optional` — Optional filter based on the test status. This parameter can be passed multiple times to filter by multiple statuses. + +
+
+ +
+
+ +**after:** `Optional` — If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results. + +
+
+
+
+ + +
+
+
+ +
client.carbCtc.listCarbCtcVehicleHistory() -> CarbCtcListCarbCtcVehicleHistoryResponseBody +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + + Rate limit: 5 requests/sec (learn more about rate limits here). + +To use this endpoint, select **Read CARB CTC Integration** under the CARB CTC Integration category when creating or editing an API token. Learn More. + + + **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.carbCtc().listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest + .builder() + .vehicleIds("vehicleIds") + .build() +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**vehicleIds:** `String` — A comma-separated list of vehicle IDs to fetch history for. Up to 100 IDs can be provided. Example: `vehicleIds=1234,5678` + +
+
+ +
+
+ +**startTime:** `Optional` — A start time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00). + +
+
+ +
+
+ +**endTime:** `Optional` — An end time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00). + +
+
+ +
+
+ +**after:** `Optional` — If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results. + +
+
+
+
+ +
diff --git a/src/main/java/com/samsara/api/AsyncSamsaraApiClient.java b/src/main/java/com/samsara/api/AsyncSamsaraApiClient.java index f078677..ece937a 100644 --- a/src/main/java/com/samsara/api/AsyncSamsaraApiClient.java +++ b/src/main/java/com/samsara/api/AsyncSamsaraApiClient.java @@ -11,6 +11,7 @@ import com.samsara.api.resources.attributes.AsyncAttributesClient; import com.samsara.api.resources.authtokenfordriver.AsyncAuthTokenForDriverClient; import com.samsara.api.resources.betaapis.AsyncBetaApIsClient; +import com.samsara.api.resources.carbctc.AsyncCarbCtcClient; import com.samsara.api.resources.carrierproposedassignments.AsyncCarrierProposedAssignmentsClient; import com.samsara.api.resources.coaching.AsyncCoachingClient; import com.samsara.api.resources.contacts.AsyncContactsClient; @@ -90,6 +91,8 @@ public class AsyncSamsaraApiClient { protected final Supplier driverQrCodesClient; + protected final Supplier carbCtcClient; + protected final Supplier carrierProposedAssignmentsClient; protected final Supplier legacyApIsClient; @@ -188,6 +191,7 @@ public AsyncSamsaraApiClient(ClientOptions clientOptions) { this.driverTrailerAssignmentsClient = Suppliers.memoize(() -> new AsyncDriverTrailerAssignmentsClient(clientOptions)); this.driverQrCodesClient = Suppliers.memoize(() -> new AsyncDriverQrCodesClient(clientOptions)); + this.carbCtcClient = Suppliers.memoize(() -> new AsyncCarbCtcClient(clientOptions)); this.carrierProposedAssignmentsClient = Suppliers.memoize(() -> new AsyncCarrierProposedAssignmentsClient(clientOptions)); this.legacyApIsClient = Suppliers.memoize(() -> new AsyncLegacyApIsClient(clientOptions)); @@ -285,6 +289,10 @@ public AsyncDriverQrCodesClient driverQrCodes() { return this.driverQrCodesClient.get(); } + public AsyncCarbCtcClient carbCtc() { + return this.carbCtcClient.get(); + } + public AsyncCarrierProposedAssignmentsClient carrierProposedAssignments() { return this.carrierProposedAssignmentsClient.get(); } diff --git a/src/main/java/com/samsara/api/SamsaraApiClient.java b/src/main/java/com/samsara/api/SamsaraApiClient.java index 8345f4d..6683603 100644 --- a/src/main/java/com/samsara/api/SamsaraApiClient.java +++ b/src/main/java/com/samsara/api/SamsaraApiClient.java @@ -11,6 +11,7 @@ import com.samsara.api.resources.attributes.AttributesClient; import com.samsara.api.resources.authtokenfordriver.AuthTokenForDriverClient; import com.samsara.api.resources.betaapis.BetaApIsClient; +import com.samsara.api.resources.carbctc.CarbCtcClient; import com.samsara.api.resources.carrierproposedassignments.CarrierProposedAssignmentsClient; import com.samsara.api.resources.coaching.CoachingClient; import com.samsara.api.resources.contacts.ContactsClient; @@ -90,6 +91,8 @@ public class SamsaraApiClient { protected final Supplier driverQrCodesClient; + protected final Supplier carbCtcClient; + protected final Supplier carrierProposedAssignmentsClient; protected final Supplier legacyApIsClient; @@ -188,6 +191,7 @@ public SamsaraApiClient(ClientOptions clientOptions) { this.driverTrailerAssignmentsClient = Suppliers.memoize(() -> new DriverTrailerAssignmentsClient(clientOptions)); this.driverQrCodesClient = Suppliers.memoize(() -> new DriverQrCodesClient(clientOptions)); + this.carbCtcClient = Suppliers.memoize(() -> new CarbCtcClient(clientOptions)); this.carrierProposedAssignmentsClient = Suppliers.memoize(() -> new CarrierProposedAssignmentsClient(clientOptions)); this.legacyApIsClient = Suppliers.memoize(() -> new LegacyApIsClient(clientOptions)); @@ -285,6 +289,10 @@ public DriverQrCodesClient driverQrCodes() { return this.driverQrCodesClient.get(); } + public CarbCtcClient carbCtc() { + return this.carbCtcClient.get(); + } + public CarrierProposedAssignmentsClient carrierProposedAssignments() { return this.carrierProposedAssignmentsClient.get(); } diff --git a/src/main/java/com/samsara/api/core/ClientOptions.java b/src/main/java/com/samsara/api/core/ClientOptions.java index 6de9208..a3b17f7 100644 --- a/src/main/java/com/samsara/api/core/ClientOptions.java +++ b/src/main/java/com/samsara/api/core/ClientOptions.java @@ -44,10 +44,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.samsara:samsara-java-sdk/8.1.1"); + put("User-Agent", "com.samsara:samsara-java-sdk/8.1.2"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.samsara.fern:api-sdk"); - put("X-Fern-SDK-Version", "8.1.1"); + put("X-Fern-SDK-Version", "8.1.2"); } }); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/samsara/api/resources/betaapis/AsyncBetaApIsClient.java b/src/main/java/com/samsara/api/resources/betaapis/AsyncBetaApIsClient.java index 5977807..f2942eb 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/AsyncBetaApIsClient.java +++ b/src/main/java/com/samsara/api/resources/betaapis/AsyncBetaApIsClient.java @@ -52,8 +52,6 @@ import com.samsara.api.resources.betaapis.requests.JobsCreateJobRequestBody; import com.samsara.api.resources.betaapis.requests.JobsPatchJobRequestBody; import com.samsara.api.resources.betaapis.requests.ListAssociationsRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehicleHistoryRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehiclesRequest; import com.samsara.api.resources.betaapis.requests.ListDeviceRecoveryMissingAssetsRequest; import com.samsara.api.resources.betaapis.requests.ListHubCustomPropertiesRequest; import com.samsara.api.resources.betaapis.requests.ListMaintenanceVendorsRequest; @@ -80,8 +78,6 @@ import com.samsara.api.types.AempEquipmentGetAempEquipmentListResponseBody; import com.samsara.api.types.AssetsInputsGetAssetsInputsResponseBody; import com.samsara.api.types.AssociationsListAssociationsResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; import com.samsara.api.types.DepreciationGetDepreciationTransactionsResponseBody; import com.samsara.api.types.DetectionLogGetDetectionsResponseBody; import com.samsara.api.types.DeviceRecoveryListDeviceRecoveryMissingAssetsResponseBody; @@ -778,71 +774,6 @@ public CompletableFuture recoverAsset( return this.rawClient.recoverAsset(id, request, requestOptions).thenApply(response -> response.body()); } - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicles() { - return this.rawClient.listCarbCtcVehicles().thenApply(response -> response.body()); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicles( - RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicles(requestOptions).thenApply(response -> response.body()); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request) { - return this.rawClient.listCarbCtcVehicles(request).thenApply(response -> response.body()); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicles(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request) { - return this.rawClient.listCarbCtcVehicleHistory(request).thenApply(response -> response.body()); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicleHistory(request, requestOptions).thenApply(response -> response.body()); - } - /** * Resolves a driver by name within an organization via voice sign-in, then creates a driver-vehicle assignment via the Driver Assignment Service. *

Rate limit: 100 requests/min (learn more about rate limits here).

diff --git a/src/main/java/com/samsara/api/resources/betaapis/AsyncRawBetaApIsClient.java b/src/main/java/com/samsara/api/resources/betaapis/AsyncRawBetaApIsClient.java index ed275bb..bc44908 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/AsyncRawBetaApIsClient.java +++ b/src/main/java/com/samsara/api/resources/betaapis/AsyncRawBetaApIsClient.java @@ -68,8 +68,6 @@ import com.samsara.api.resources.betaapis.requests.JobsCreateJobRequestBody; import com.samsara.api.resources.betaapis.requests.JobsPatchJobRequestBody; import com.samsara.api.resources.betaapis.requests.ListAssociationsRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehicleHistoryRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehiclesRequest; import com.samsara.api.resources.betaapis.requests.ListDeviceRecoveryMissingAssetsRequest; import com.samsara.api.resources.betaapis.requests.ListHubCustomPropertiesRequest; import com.samsara.api.resources.betaapis.requests.ListMaintenanceVendorsRequest; @@ -96,8 +94,6 @@ import com.samsara.api.types.AempEquipmentGetAempEquipmentListResponseBody; import com.samsara.api.types.AssetsInputsGetAssetsInputsResponseBody; import com.samsara.api.types.AssociationsListAssociationsResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; import com.samsara.api.types.DepreciationGetDepreciationTransactionsResponseBody; import com.samsara.api.types.DetectionLogGetDetectionsResponseBody; import com.samsara.api.types.DeviceRecoveryListDeviceRecoveryMissingAssetsResponseBody; @@ -3049,294 +3045,6 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { return future; } - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> listCarbCtcVehicles() { - return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> listCarbCtcVehicles( - RequestOptions requestOptions) { - return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build(), requestOptions); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request) { - return listCarbCtcVehicles(request, null); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("fleet/carb-ctc/vehicles"); - if (request.getTagIds().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "tagIds", request.getTagIds().get(), false); - } - if (request.getParentTagIds().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "parentTagIds", request.getParentTagIds().get(), false); - } - if (request.getAfter().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "after", request.getAfter().get(), false); - } - if (request.getTestStatus().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "testStatus", request.getTestStatus().get(), true); - } - if (requestOptions != null) { - requestOptions.getQueryParameters().forEach((_key, _value) -> { - httpUrl.addQueryParameter(_key, _value); - }); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = - new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SamsaraApiHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CarbCtcListCarbCtcVehiclesResponseBody.class), - response)); - return; - } - try { - switch (response.code()) { - case 401: - future.completeExceptionally(new UnauthorizedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 404: - future.completeExceptionally(new NotFoundError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 405: - future.completeExceptionally(new MethodNotAllowedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 429: - future.completeExceptionally(new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 500: - future.completeExceptionally(new InternalServerError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 501: - future.completeExceptionally(new NotImplementedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 502: - future.completeExceptionally(new BadGatewayError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 503: - future.completeExceptionally(new ServiceUnavailableError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 504: - future.completeExceptionally(new GatewayTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - } - } catch (JsonProcessingException ignored) { - // unable to map error response, throwing generic error - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SamsaraApiApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> - listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest request) { - return listCarbCtcVehicleHistory(request, null); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CompletableFuture> - listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("fleet/carb-ctc/vehicles/history"); - QueryStringMapper.addQueryParameter(httpUrl, "vehicleIds", request.getVehicleIds(), false); - if (request.getStartTime().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "startTime", request.getStartTime().get(), false); - } - if (request.getEndTime().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "endTime", request.getEndTime().get(), false); - } - if (request.getAfter().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "after", request.getAfter().get(), false); - } - if (requestOptions != null) { - requestOptions.getQueryParameters().forEach((_key, _value) -> { - httpUrl.addQueryParameter(_key, _value); - }); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = - new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SamsaraApiHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CarbCtcListCarbCtcVehicleHistoryResponseBody.class), - response)); - return; - } - try { - switch (response.code()) { - case 401: - future.completeExceptionally(new UnauthorizedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 404: - future.completeExceptionally(new NotFoundError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 405: - future.completeExceptionally(new MethodNotAllowedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 429: - future.completeExceptionally(new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 500: - future.completeExceptionally(new InternalServerError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 501: - future.completeExceptionally(new NotImplementedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 502: - future.completeExceptionally(new BadGatewayError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 503: - future.completeExceptionally(new ServiceUnavailableError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - case 504: - future.completeExceptionally(new GatewayTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); - return; - } - } catch (JsonProcessingException ignored) { - // unable to map error response, throwing generic error - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SamsaraApiApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); - } - }); - return future; - } - /** * Resolves a driver by name within an organization via voice sign-in, then creates a driver-vehicle assignment via the Driver Assignment Service. *

Rate limit: 100 requests/min (learn more about rate limits here).

diff --git a/src/main/java/com/samsara/api/resources/betaapis/BetaApIsClient.java b/src/main/java/com/samsara/api/resources/betaapis/BetaApIsClient.java index 450a94c..abbdce1 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/BetaApIsClient.java +++ b/src/main/java/com/samsara/api/resources/betaapis/BetaApIsClient.java @@ -52,8 +52,6 @@ import com.samsara.api.resources.betaapis.requests.JobsCreateJobRequestBody; import com.samsara.api.resources.betaapis.requests.JobsPatchJobRequestBody; import com.samsara.api.resources.betaapis.requests.ListAssociationsRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehicleHistoryRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehiclesRequest; import com.samsara.api.resources.betaapis.requests.ListDeviceRecoveryMissingAssetsRequest; import com.samsara.api.resources.betaapis.requests.ListHubCustomPropertiesRequest; import com.samsara.api.resources.betaapis.requests.ListMaintenanceVendorsRequest; @@ -80,8 +78,6 @@ import com.samsara.api.types.AempEquipmentGetAempEquipmentListResponseBody; import com.samsara.api.types.AssetsInputsGetAssetsInputsResponseBody; import com.samsara.api.types.AssociationsListAssociationsResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; import com.samsara.api.types.DepreciationGetDepreciationTransactionsResponseBody; import com.samsara.api.types.DetectionLogGetDetectionsResponseBody; import com.samsara.api.types.DeviceRecoveryListDeviceRecoveryMissingAssetsResponseBody; @@ -765,69 +761,6 @@ public DeviceRecoveryRecoverAssetResponseBody recoverAsset( return this.rawClient.recoverAsset(id, request, requestOptions).body(); } - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles() { - return this.rawClient.listCarbCtcVehicles().body(); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles(RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicles(requestOptions).body(); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles(ListCarbCtcVehiclesRequest request) { - return this.rawClient.listCarbCtcVehicles(request).body(); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicles(request, requestOptions).body(); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehicleHistoryResponseBody listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request) { - return this.rawClient.listCarbCtcVehicleHistory(request).body(); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public CarbCtcListCarbCtcVehicleHistoryResponseBody listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { - return this.rawClient.listCarbCtcVehicleHistory(request, requestOptions).body(); - } - /** * Resolves a driver by name within an organization via voice sign-in, then creates a driver-vehicle assignment via the Driver Assignment Service. *

Rate limit: 100 requests/min (learn more about rate limits here).

diff --git a/src/main/java/com/samsara/api/resources/betaapis/RawBetaApIsClient.java b/src/main/java/com/samsara/api/resources/betaapis/RawBetaApIsClient.java index 2dec50e..d8f4d8c 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/RawBetaApIsClient.java +++ b/src/main/java/com/samsara/api/resources/betaapis/RawBetaApIsClient.java @@ -68,8 +68,6 @@ import com.samsara.api.resources.betaapis.requests.JobsCreateJobRequestBody; import com.samsara.api.resources.betaapis.requests.JobsPatchJobRequestBody; import com.samsara.api.resources.betaapis.requests.ListAssociationsRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehicleHistoryRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehiclesRequest; import com.samsara.api.resources.betaapis.requests.ListDeviceRecoveryMissingAssetsRequest; import com.samsara.api.resources.betaapis.requests.ListHubCustomPropertiesRequest; import com.samsara.api.resources.betaapis.requests.ListMaintenanceVendorsRequest; @@ -96,8 +94,6 @@ import com.samsara.api.types.AempEquipmentGetAempEquipmentListResponseBody; import com.samsara.api.types.AssetsInputsGetAssetsInputsResponseBody; import com.samsara.api.types.AssociationsListAssociationsResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; import com.samsara.api.types.DepreciationGetDepreciationTransactionsResponseBody; import com.samsara.api.types.DetectionLogGetDetectionsResponseBody; import com.samsara.api.types.DeviceRecoveryListDeviceRecoveryMissingAssetsResponseBody; @@ -2415,230 +2411,6 @@ public SamsaraApiHttpResponse recoverAss } } - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicles() { - return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicles( - RequestOptions requestOptions) { - return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build(), requestOptions); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request) { - return listCarbCtcVehicles(request, null); - } - - /** - * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicles( - ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("fleet/carb-ctc/vehicles"); - if (request.getTagIds().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "tagIds", request.getTagIds().get(), false); - } - if (request.getParentTagIds().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "parentTagIds", request.getParentTagIds().get(), false); - } - if (request.getAfter().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "after", request.getAfter().get(), false); - } - if (request.getTestStatus().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "testStatus", request.getTestStatus().get(), true); - } - if (requestOptions != null) { - requestOptions.getQueryParameters().forEach((_key, _value) -> { - httpUrl.addQueryParameter(_key, _value); - }); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SamsaraApiHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CarbCtcListCarbCtcVehiclesResponseBody.class), - response); - } - try { - switch (response.code()) { - case 401: - throw new UnauthorizedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 404: - throw new NotFoundError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 405: - throw new MethodNotAllowedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 429: - throw new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 500: - throw new InternalServerError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 501: - throw new NotImplementedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 502: - throw new BadGatewayError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 503: - throw new ServiceUnavailableError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 504: - throw new GatewayTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - } - } catch (JsonProcessingException ignored) { - // unable to map error response, throwing generic error - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SamsaraApiApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SamsaraApiException("Network error executing HTTP request", e); - } - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request) { - return listCarbCtcVehicleHistory(request, null); - } - - /** - * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. - *

Rate limit: 5 requests/sec (learn more about rate limits here).

- *

To use this endpoint, select Read CARB CTC Integration under the Closed Beta category when creating or editing an API token. Learn More.

- *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

- */ - public SamsaraApiHttpResponse listCarbCtcVehicleHistory( - ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("fleet/carb-ctc/vehicles/history"); - QueryStringMapper.addQueryParameter(httpUrl, "vehicleIds", request.getVehicleIds(), false); - if (request.getStartTime().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "startTime", request.getStartTime().get(), false); - } - if (request.getEndTime().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "endTime", request.getEndTime().get(), false); - } - if (request.getAfter().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "after", request.getAfter().get(), false); - } - if (requestOptions != null) { - requestOptions.getQueryParameters().forEach((_key, _value) -> { - httpUrl.addQueryParameter(_key, _value); - }); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SamsaraApiHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CarbCtcListCarbCtcVehicleHistoryResponseBody.class), - response); - } - try { - switch (response.code()) { - case 401: - throw new UnauthorizedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 404: - throw new NotFoundError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 405: - throw new MethodNotAllowedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 429: - throw new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 500: - throw new InternalServerError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 501: - throw new NotImplementedError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 502: - throw new BadGatewayError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 503: - throw new ServiceUnavailableError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - case 504: - throw new GatewayTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); - } - } catch (JsonProcessingException ignored) { - // unable to map error response, throwing generic error - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SamsaraApiApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SamsaraApiException("Network error executing HTTP request", e); - } - } - /** * Resolves a driver by name within an organization via voice sign-in, then creates a driver-vehicle assignment via the Driver Assignment Service. *

Rate limit: 100 requests/min (learn more about rate limits here).

diff --git a/src/main/java/com/samsara/api/resources/carbctc/AsyncCarbCtcClient.java b/src/main/java/com/samsara/api/resources/carbctc/AsyncCarbCtcClient.java new file mode 100644 index 0000000..26968d3 --- /dev/null +++ b/src/main/java/com/samsara/api/resources/carbctc/AsyncCarbCtcClient.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.samsara.api.resources.carbctc; + +import com.samsara.api.core.ClientOptions; +import com.samsara.api.core.RequestOptions; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehicleHistoryRequest; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehiclesRequest; +import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; +import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; +import java.util.concurrent.CompletableFuture; + +public class AsyncCarbCtcClient { + protected final ClientOptions clientOptions; + + private final AsyncRawCarbCtcClient rawClient; + + public AsyncCarbCtcClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + this.rawClient = new AsyncRawCarbCtcClient(clientOptions); + } + + /** + * Get responses with HTTP metadata like headers + */ + public AsyncRawCarbCtcClient withRawResponse() { + return this.rawClient; + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicles() { + return this.rawClient.listCarbCtcVehicles().thenApply(response -> response.body()); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicles( + RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicles(requestOptions).thenApply(response -> response.body()); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request) { + return this.rawClient.listCarbCtcVehicles(request).thenApply(response -> response.body()); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicles(request, requestOptions).thenApply(response -> response.body()); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request) { + return this.rawClient.listCarbCtcVehicleHistory(request).thenApply(response -> response.body()); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicleHistory(request, requestOptions).thenApply(response -> response.body()); + } +} diff --git a/src/main/java/com/samsara/api/resources/carbctc/AsyncRawCarbCtcClient.java b/src/main/java/com/samsara/api/resources/carbctc/AsyncRawCarbCtcClient.java new file mode 100644 index 0000000..6307e6d --- /dev/null +++ b/src/main/java/com/samsara/api/resources/carbctc/AsyncRawCarbCtcClient.java @@ -0,0 +1,333 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.samsara.api.resources.carbctc; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.samsara.api.core.ClientOptions; +import com.samsara.api.core.ObjectMappers; +import com.samsara.api.core.QueryStringMapper; +import com.samsara.api.core.RequestOptions; +import com.samsara.api.core.SamsaraApiApiException; +import com.samsara.api.core.SamsaraApiException; +import com.samsara.api.core.SamsaraApiHttpResponse; +import com.samsara.api.errors.BadGatewayError; +import com.samsara.api.errors.GatewayTimeoutError; +import com.samsara.api.errors.InternalServerError; +import com.samsara.api.errors.MethodNotAllowedError; +import com.samsara.api.errors.NotFoundError; +import com.samsara.api.errors.NotImplementedError; +import com.samsara.api.errors.ServiceUnavailableError; +import com.samsara.api.errors.TooManyRequestsError; +import com.samsara.api.errors.UnauthorizedError; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehicleHistoryRequest; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehiclesRequest; +import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; +import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; +import java.io.IOException; +import java.util.concurrent.CompletableFuture; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; +import org.jetbrains.annotations.NotNull; + +public class AsyncRawCarbCtcClient { + protected final ClientOptions clientOptions; + + public AsyncRawCarbCtcClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> listCarbCtcVehicles() { + return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> listCarbCtcVehicles( + RequestOptions requestOptions) { + return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build(), requestOptions); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request) { + return listCarbCtcVehicles(request, null); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("fleet/carb-ctc/vehicles"); + if (request.getTagIds().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "tagIds", request.getTagIds().get(), false); + } + if (request.getParentTagIds().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "parentTagIds", request.getParentTagIds().get(), false); + } + if (request.getAfter().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "after", request.getAfter().get(), false); + } + if (request.getTestStatus().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "testStatus", request.getTestStatus().get(), true); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = + new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + if (response.isSuccessful()) { + future.complete(new SamsaraApiHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, CarbCtcListCarbCtcVehiclesResponseBody.class), + response)); + return; + } + try { + switch (response.code()) { + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 405: + future.completeExceptionally(new MethodNotAllowedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 429: + future.completeExceptionally(new TooManyRequestsError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 501: + future.completeExceptionally(new NotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 502: + future.completeExceptionally(new BadGatewayError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 504: + future.completeExceptionally(new GatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + future.completeExceptionally(new SamsaraApiApiException( + "Error with status code " + response.code(), response.code(), errorBody, response)); + return; + } catch (IOException e) { + future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); + } + }); + return future; + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> + listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest request) { + return listCarbCtcVehicleHistory(request, null); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CompletableFuture> + listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("fleet/carb-ctc/vehicles/history"); + QueryStringMapper.addQueryParameter(httpUrl, "vehicleIds", request.getVehicleIds(), false); + if (request.getStartTime().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "startTime", request.getStartTime().get(), false); + } + if (request.getEndTime().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "endTime", request.getEndTime().get(), false); + } + if (request.getAfter().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "after", request.getAfter().get(), false); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = + new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + if (response.isSuccessful()) { + future.complete(new SamsaraApiHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, CarbCtcListCarbCtcVehicleHistoryResponseBody.class), + response)); + return; + } + try { + switch (response.code()) { + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 405: + future.completeExceptionally(new MethodNotAllowedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 429: + future.completeExceptionally(new TooManyRequestsError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 501: + future.completeExceptionally(new NotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 502: + future.completeExceptionally(new BadGatewayError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 504: + future.completeExceptionally(new GatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + future.completeExceptionally(new SamsaraApiApiException( + "Error with status code " + response.code(), response.code(), errorBody, response)); + return; + } catch (IOException e) { + future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new SamsaraApiException("Network error executing HTTP request", e)); + } + }); + return future; + } +} diff --git a/src/main/java/com/samsara/api/resources/carbctc/CarbCtcClient.java b/src/main/java/com/samsara/api/resources/carbctc/CarbCtcClient.java new file mode 100644 index 0000000..027a257 --- /dev/null +++ b/src/main/java/com/samsara/api/resources/carbctc/CarbCtcClient.java @@ -0,0 +1,92 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.samsara.api.resources.carbctc; + +import com.samsara.api.core.ClientOptions; +import com.samsara.api.core.RequestOptions; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehicleHistoryRequest; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehiclesRequest; +import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; +import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; + +public class CarbCtcClient { + protected final ClientOptions clientOptions; + + private final RawCarbCtcClient rawClient; + + public CarbCtcClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + this.rawClient = new RawCarbCtcClient(clientOptions); + } + + /** + * Get responses with HTTP metadata like headers + */ + public RawCarbCtcClient withRawResponse() { + return this.rawClient; + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles() { + return this.rawClient.listCarbCtcVehicles().body(); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles(RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicles(requestOptions).body(); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles(ListCarbCtcVehiclesRequest request) { + return this.rawClient.listCarbCtcVehicles(request).body(); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehiclesResponseBody listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicles(request, requestOptions).body(); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehicleHistoryResponseBody listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request) { + return this.rawClient.listCarbCtcVehicleHistory(request).body(); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public CarbCtcListCarbCtcVehicleHistoryResponseBody listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { + return this.rawClient.listCarbCtcVehicleHistory(request, requestOptions).body(); + } +} diff --git a/src/main/java/com/samsara/api/resources/carbctc/RawCarbCtcClient.java b/src/main/java/com/samsara/api/resources/carbctc/RawCarbCtcClient.java new file mode 100644 index 0000000..52783f7 --- /dev/null +++ b/src/main/java/com/samsara/api/resources/carbctc/RawCarbCtcClient.java @@ -0,0 +1,265 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.samsara.api.resources.carbctc; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.samsara.api.core.ClientOptions; +import com.samsara.api.core.ObjectMappers; +import com.samsara.api.core.QueryStringMapper; +import com.samsara.api.core.RequestOptions; +import com.samsara.api.core.SamsaraApiApiException; +import com.samsara.api.core.SamsaraApiException; +import com.samsara.api.core.SamsaraApiHttpResponse; +import com.samsara.api.errors.BadGatewayError; +import com.samsara.api.errors.GatewayTimeoutError; +import com.samsara.api.errors.InternalServerError; +import com.samsara.api.errors.MethodNotAllowedError; +import com.samsara.api.errors.NotFoundError; +import com.samsara.api.errors.NotImplementedError; +import com.samsara.api.errors.ServiceUnavailableError; +import com.samsara.api.errors.TooManyRequestsError; +import com.samsara.api.errors.UnauthorizedError; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehicleHistoryRequest; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehiclesRequest; +import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; +import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; +import java.io.IOException; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +public class RawCarbCtcClient { + protected final ClientOptions clientOptions; + + public RawCarbCtcClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicles() { + return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicles( + RequestOptions requestOptions) { + return listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build(), requestOptions); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request) { + return listCarbCtcVehicles(request, null); + } + + /** + * Returns a paginated list of vehicles enrolled in the CARB CTC program with their latest compliance status. Results can be filtered by tag IDs and test status. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicles( + ListCarbCtcVehiclesRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("fleet/carb-ctc/vehicles"); + if (request.getTagIds().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "tagIds", request.getTagIds().get(), false); + } + if (request.getParentTagIds().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "parentTagIds", request.getParentTagIds().get(), false); + } + if (request.getAfter().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "after", request.getAfter().get(), false); + } + if (request.getTestStatus().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "testStatus", request.getTestStatus().get(), true); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + if (response.isSuccessful()) { + return new SamsaraApiHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, CarbCtcListCarbCtcVehiclesResponseBody.class), + response); + } + try { + switch (response.code()) { + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 405: + throw new MethodNotAllowedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 429: + throw new TooManyRequestsError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 501: + throw new NotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 502: + throw new BadGatewayError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 504: + throw new GatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + throw new SamsaraApiApiException( + "Error with status code " + response.code(), response.code(), errorBody, response); + } catch (IOException e) { + throw new SamsaraApiException("Network error executing HTTP request", e); + } + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request) { + return listCarbCtcVehicleHistory(request, null); + } + + /** + * Returns paginated collection history for a batch of vehicles enrolled in the CARB CTC program. Use vehicle IDs from the list enrolled vehicles endpoint. Optionally filter by time range. Results are ordered by happenedAtTime descending, with vehicle ID as a tiebreaker. + *

Rate limit: 5 requests/sec (learn more about rate limits here).

+ *

To use this endpoint, select Read CARB CTC Integration under the CARB CTC Integration category when creating or editing an API token. Learn More.

+ *

Submit Feedback: Likes, dislikes, and API feature requests should be filed as feedback in our API feedback form. If you encountered an issue or noticed inaccuracies in the API documentation, please submit a case to our support team.

+ */ + public SamsaraApiHttpResponse listCarbCtcVehicleHistory( + ListCarbCtcVehicleHistoryRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("fleet/carb-ctc/vehicles/history"); + QueryStringMapper.addQueryParameter(httpUrl, "vehicleIds", request.getVehicleIds(), false); + if (request.getStartTime().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "startTime", request.getStartTime().get(), false); + } + if (request.getEndTime().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "endTime", request.getEndTime().get(), false); + } + if (request.getAfter().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "after", request.getAfter().get(), false); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + if (response.isSuccessful()) { + return new SamsaraApiHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, CarbCtcListCarbCtcVehicleHistoryResponseBody.class), + response); + } + try { + switch (response.code()) { + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 405: + throw new MethodNotAllowedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 429: + throw new TooManyRequestsError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 501: + throw new NotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 502: + throw new BadGatewayError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 504: + throw new GatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + throw new SamsaraApiApiException( + "Error with status code " + response.code(), response.code(), errorBody, response); + } catch (IOException e) { + throw new SamsaraApiException("Network error executing HTTP request", e); + } + } +} diff --git a/src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehicleHistoryRequest.java b/src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehicleHistoryRequest.java similarity index 99% rename from src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehicleHistoryRequest.java rename to src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehicleHistoryRequest.java index f3e60be..71236e0 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehicleHistoryRequest.java +++ b/src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehicleHistoryRequest.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.samsara.api.resources.betaapis.requests; +package com.samsara.api.resources.carbctc.requests; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehiclesRequest.java b/src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehiclesRequest.java similarity index 98% rename from src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehiclesRequest.java rename to src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehiclesRequest.java index bc7200e..5a83e9a 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/requests/ListCarbCtcVehiclesRequest.java +++ b/src/main/java/com/samsara/api/resources/carbctc/requests/ListCarbCtcVehiclesRequest.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.samsara.api.resources.betaapis.requests; +package com.samsara.api.resources.carbctc.requests; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; @@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.samsara.api.core.ObjectMappers; -import com.samsara.api.resources.betaapis.types.ListCarbCtcVehiclesRequestTestStatusItem; +import com.samsara.api.resources.carbctc.types.ListCarbCtcVehiclesRequestTestStatusItem; import java.util.Collections; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/com/samsara/api/resources/betaapis/types/ListCarbCtcVehiclesRequestTestStatusItem.java b/src/main/java/com/samsara/api/resources/carbctc/types/ListCarbCtcVehiclesRequestTestStatusItem.java similarity index 98% rename from src/main/java/com/samsara/api/resources/betaapis/types/ListCarbCtcVehiclesRequestTestStatusItem.java rename to src/main/java/com/samsara/api/resources/carbctc/types/ListCarbCtcVehiclesRequestTestStatusItem.java index a2a6562..7b40d74 100644 --- a/src/main/java/com/samsara/api/resources/betaapis/types/ListCarbCtcVehiclesRequestTestStatusItem.java +++ b/src/main/java/com/samsara/api/resources/carbctc/types/ListCarbCtcVehiclesRequestTestStatusItem.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.samsara.api.resources.betaapis.types; +package com.samsara.api.resources.carbctc.types; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/src/test/java/com/samsara/api/BetaApIsWireTest.java b/src/test/java/com/samsara/api/BetaApIsWireTest.java index 3a0f615..a9ec2d5 100644 --- a/src/test/java/com/samsara/api/BetaApIsWireTest.java +++ b/src/test/java/com/samsara/api/BetaApIsWireTest.java @@ -50,8 +50,6 @@ import com.samsara.api.resources.betaapis.requests.JobsCreateJobRequestBody; import com.samsara.api.resources.betaapis.requests.JobsPatchJobRequestBody; import com.samsara.api.resources.betaapis.requests.ListAssociationsRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehicleHistoryRequest; -import com.samsara.api.resources.betaapis.requests.ListCarbCtcVehiclesRequest; import com.samsara.api.resources.betaapis.requests.ListDeviceRecoveryMissingAssetsRequest; import com.samsara.api.resources.betaapis.requests.ListHubCustomPropertiesRequest; import com.samsara.api.resources.betaapis.requests.ListMaintenanceVendorsRequest; @@ -87,8 +85,6 @@ import com.samsara.api.types.AempEquipmentGetAempEquipmentListResponseBody; import com.samsara.api.types.AssetsInputsGetAssetsInputsResponseBody; import com.samsara.api.types.AssociationsListAssociationsResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; -import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; import com.samsara.api.types.CreateFunctionRequestConfigRequestBody; import com.samsara.api.types.CreateReportConfigObjectRequestBody; import com.samsara.api.types.DepreciationGetDepreciationTransactionsResponseBody; @@ -1777,137 +1773,6 @@ else if (actualResponseNode.has("kind")) } } - @Test - public void testListCarbCtcVehicles() throws Exception { - server.enqueue( - new MockResponse() - .setResponseCode(200) - .setBody( - "{\"data\":[{\"enrollmentId\":\"550e8400-e29b-41d4-a716-446655440000\",\"enrollmentVin\":\"1HGCM82633A123456\",\"id\":\"12345\",\"lastCollectionAtTime\":\"2024-06-15T08:00:00Z\",\"nextCollectionAtTime\":\"2024-12-15T00:00:00Z\",\"testStatus\":\"notScheduled\",\"testStatusDetails\":\"Response from CARB CTC: Vehicle PASSED emissions scan.\"}],\"pagination\":{\"endCursor\":\"MjkY\",\"hasNextPage\":true}}")); - CarbCtcListCarbCtcVehiclesResponseBody response = client.betaApIs() - .listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); - RecordedRequest request = server.takeRequest(); - Assertions.assertNotNull(request); - Assertions.assertEquals("GET", request.getMethod()); - - // Validate response body - Assertions.assertNotNull(response, "Response should not be null"); - String actualResponseJson = objectMapper.writeValueAsString(response); - String expectedResponseBody = "" - + "{\n" - + " \"data\": [\n" - + " {\n" - + " \"enrollmentId\": \"550e8400-e29b-41d4-a716-446655440000\",\n" - + " \"enrollmentVin\": \"1HGCM82633A123456\",\n" - + " \"id\": \"12345\",\n" - + " \"lastCollectionAtTime\": \"2024-06-15T08:00:00Z\",\n" - + " \"nextCollectionAtTime\": \"2024-12-15T00:00:00Z\",\n" - + " \"testStatus\": \"notScheduled\",\n" - + " \"testStatusDetails\": \"Response from CARB CTC: Vehicle PASSED emissions scan.\"\n" - + " }\n" - + " ],\n" - + " \"pagination\": {\n" - + " \"endCursor\": \"MjkY\",\n" - + " \"hasNextPage\": true\n" - + " }\n" - + "}"; - JsonNode actualResponseNode = objectMapper.readTree(actualResponseJson); - JsonNode expectedResponseNode = objectMapper.readTree(expectedResponseBody); - Assertions.assertTrue( - jsonEquals(expectedResponseNode, actualResponseNode), - "Response body structure does not match expected"); - if (actualResponseNode.has("type") || actualResponseNode.has("_type") || actualResponseNode.has("kind")) { - String discriminator = null; - if (actualResponseNode.has("type")) - discriminator = actualResponseNode.get("type").asText(); - else if (actualResponseNode.has("_type")) - discriminator = actualResponseNode.get("_type").asText(); - else if (actualResponseNode.has("kind")) - discriminator = actualResponseNode.get("kind").asText(); - Assertions.assertNotNull(discriminator, "Union type should have a discriminator field"); - Assertions.assertFalse(discriminator.isEmpty(), "Union discriminator should not be empty"); - } - - if (!actualResponseNode.isNull()) { - Assertions.assertTrue( - actualResponseNode.isObject() || actualResponseNode.isArray() || actualResponseNode.isValueNode(), - "response should be a valid JSON value"); - } - - if (actualResponseNode.isArray()) { - Assertions.assertTrue(actualResponseNode.size() >= 0, "Array should have valid size"); - } - if (actualResponseNode.isObject()) { - Assertions.assertTrue(actualResponseNode.size() >= 0, "Object should have valid field count"); - } - } - - @Test - public void testListCarbCtcVehicleHistory() throws Exception { - server.enqueue( - new MockResponse() - .setResponseCode(200) - .setBody( - "{\"data\":[{\"enrollmentId\":\"550e8400-e29b-41d4-a716-446655440000\",\"enrollmentVin\":\"1HGCM82633A123456\",\"happenedAtTime\":\"2024-06-15T08:00:00Z\",\"id\":\"12345\",\"testResult\":\"pass\",\"testResultDetails\":\"Response from CARB CTC: Vehicle PASSED emissions scan.\"}],\"pagination\":{\"endCursor\":\"MjkY\",\"hasNextPage\":true}}")); - CarbCtcListCarbCtcVehicleHistoryResponseBody response = client.betaApIs() - .listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest.builder() - .vehicleIds("vehicleIds") - .build()); - RecordedRequest request = server.takeRequest(); - Assertions.assertNotNull(request); - Assertions.assertEquals("GET", request.getMethod()); - - // Validate response body - Assertions.assertNotNull(response, "Response should not be null"); - String actualResponseJson = objectMapper.writeValueAsString(response); - String expectedResponseBody = "" - + "{\n" - + " \"data\": [\n" - + " {\n" - + " \"enrollmentId\": \"550e8400-e29b-41d4-a716-446655440000\",\n" - + " \"enrollmentVin\": \"1HGCM82633A123456\",\n" - + " \"happenedAtTime\": \"2024-06-15T08:00:00Z\",\n" - + " \"id\": \"12345\",\n" - + " \"testResult\": \"pass\",\n" - + " \"testResultDetails\": \"Response from CARB CTC: Vehicle PASSED emissions scan.\"\n" - + " }\n" - + " ],\n" - + " \"pagination\": {\n" - + " \"endCursor\": \"MjkY\",\n" - + " \"hasNextPage\": true\n" - + " }\n" - + "}"; - JsonNode actualResponseNode = objectMapper.readTree(actualResponseJson); - JsonNode expectedResponseNode = objectMapper.readTree(expectedResponseBody); - Assertions.assertTrue( - jsonEquals(expectedResponseNode, actualResponseNode), - "Response body structure does not match expected"); - if (actualResponseNode.has("type") || actualResponseNode.has("_type") || actualResponseNode.has("kind")) { - String discriminator = null; - if (actualResponseNode.has("type")) - discriminator = actualResponseNode.get("type").asText(); - else if (actualResponseNode.has("_type")) - discriminator = actualResponseNode.get("_type").asText(); - else if (actualResponseNode.has("kind")) - discriminator = actualResponseNode.get("kind").asText(); - Assertions.assertNotNull(discriminator, "Union type should have a discriminator field"); - Assertions.assertFalse(discriminator.isEmpty(), "Union discriminator should not be empty"); - } - - if (!actualResponseNode.isNull()) { - Assertions.assertTrue( - actualResponseNode.isObject() || actualResponseNode.isArray() || actualResponseNode.isValueNode(), - "response should be a valid JSON value"); - } - - if (actualResponseNode.isArray()) { - Assertions.assertTrue(actualResponseNode.size() >= 0, "Array should have valid size"); - } - if (actualResponseNode.isObject()) { - Assertions.assertTrue(actualResponseNode.size() >= 0, "Object should have valid field count"); - } - } - @Test public void testResolveAssignmentByDetails() throws Exception { server.enqueue(new MockResponse() diff --git a/src/test/java/com/samsara/api/CarbCtcWireTest.java b/src/test/java/com/samsara/api/CarbCtcWireTest.java new file mode 100644 index 0000000..58668b0 --- /dev/null +++ b/src/test/java/com/samsara/api/CarbCtcWireTest.java @@ -0,0 +1,198 @@ +package com.samsara.api; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.samsara.api.core.ObjectMappers; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehicleHistoryRequest; +import com.samsara.api.resources.carbctc.requests.ListCarbCtcVehiclesRequest; +import com.samsara.api.types.CarbCtcListCarbCtcVehicleHistoryResponseBody; +import com.samsara.api.types.CarbCtcListCarbCtcVehiclesResponseBody; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CarbCtcWireTest { + private MockWebServer server; + private SamsaraApiClient client; + private ObjectMapper objectMapper = ObjectMappers.JSON_MAPPER; + + @BeforeEach + public void setup() throws Exception { + server = new MockWebServer(); + server.start(); + client = SamsaraApiClient.builder() + .url(server.url("/").toString()) + .token("test-token") + .build(); + } + + @AfterEach + public void teardown() throws Exception { + server.shutdown(); + } + + @Test + public void testListCarbCtcVehicles() throws Exception { + server.enqueue( + new MockResponse() + .setResponseCode(200) + .setBody( + "{\"data\":[{\"enrollmentId\":\"550e8400-e29b-41d4-a716-446655440000\",\"enrollmentVin\":\"1HGCM82633A123456\",\"id\":\"12345\",\"lastCollectionAtTime\":\"2024-06-15T08:00:00Z\",\"nextCollectionAtTime\":\"2024-12-15T00:00:00Z\",\"testStatus\":\"notScheduled\",\"testStatusDetails\":\"Response from CARB CTC: Vehicle PASSED emissions scan.\"}],\"pagination\":{\"endCursor\":\"MjkY\",\"hasNextPage\":true}}")); + CarbCtcListCarbCtcVehiclesResponseBody response = client.carbCtc() + .listCarbCtcVehicles(ListCarbCtcVehiclesRequest.builder().build()); + RecordedRequest request = server.takeRequest(); + Assertions.assertNotNull(request); + Assertions.assertEquals("GET", request.getMethod()); + + // Validate response body + Assertions.assertNotNull(response, "Response should not be null"); + String actualResponseJson = objectMapper.writeValueAsString(response); + String expectedResponseBody = "" + + "{\n" + + " \"data\": [\n" + + " {\n" + + " \"enrollmentId\": \"550e8400-e29b-41d4-a716-446655440000\",\n" + + " \"enrollmentVin\": \"1HGCM82633A123456\",\n" + + " \"id\": \"12345\",\n" + + " \"lastCollectionAtTime\": \"2024-06-15T08:00:00Z\",\n" + + " \"nextCollectionAtTime\": \"2024-12-15T00:00:00Z\",\n" + + " \"testStatus\": \"notScheduled\",\n" + + " \"testStatusDetails\": \"Response from CARB CTC: Vehicle PASSED emissions scan.\"\n" + + " }\n" + + " ],\n" + + " \"pagination\": {\n" + + " \"endCursor\": \"MjkY\",\n" + + " \"hasNextPage\": true\n" + + " }\n" + + "}"; + JsonNode actualResponseNode = objectMapper.readTree(actualResponseJson); + JsonNode expectedResponseNode = objectMapper.readTree(expectedResponseBody); + Assertions.assertTrue( + jsonEquals(expectedResponseNode, actualResponseNode), + "Response body structure does not match expected"); + if (actualResponseNode.has("type") || actualResponseNode.has("_type") || actualResponseNode.has("kind")) { + String discriminator = null; + if (actualResponseNode.has("type")) + discriminator = actualResponseNode.get("type").asText(); + else if (actualResponseNode.has("_type")) + discriminator = actualResponseNode.get("_type").asText(); + else if (actualResponseNode.has("kind")) + discriminator = actualResponseNode.get("kind").asText(); + Assertions.assertNotNull(discriminator, "Union type should have a discriminator field"); + Assertions.assertFalse(discriminator.isEmpty(), "Union discriminator should not be empty"); + } + + if (!actualResponseNode.isNull()) { + Assertions.assertTrue( + actualResponseNode.isObject() || actualResponseNode.isArray() || actualResponseNode.isValueNode(), + "response should be a valid JSON value"); + } + + if (actualResponseNode.isArray()) { + Assertions.assertTrue(actualResponseNode.size() >= 0, "Array should have valid size"); + } + if (actualResponseNode.isObject()) { + Assertions.assertTrue(actualResponseNode.size() >= 0, "Object should have valid field count"); + } + } + + @Test + public void testListCarbCtcVehicleHistory() throws Exception { + server.enqueue( + new MockResponse() + .setResponseCode(200) + .setBody( + "{\"data\":[{\"enrollmentId\":\"550e8400-e29b-41d4-a716-446655440000\",\"enrollmentVin\":\"1HGCM82633A123456\",\"happenedAtTime\":\"2024-06-15T08:00:00Z\",\"id\":\"12345\",\"testResult\":\"pass\",\"testResultDetails\":\"Response from CARB CTC: Vehicle PASSED emissions scan.\"}],\"pagination\":{\"endCursor\":\"MjkY\",\"hasNextPage\":true}}")); + CarbCtcListCarbCtcVehicleHistoryResponseBody response = client.carbCtc() + .listCarbCtcVehicleHistory(ListCarbCtcVehicleHistoryRequest.builder() + .vehicleIds("vehicleIds") + .build()); + RecordedRequest request = server.takeRequest(); + Assertions.assertNotNull(request); + Assertions.assertEquals("GET", request.getMethod()); + + // Validate response body + Assertions.assertNotNull(response, "Response should not be null"); + String actualResponseJson = objectMapper.writeValueAsString(response); + String expectedResponseBody = "" + + "{\n" + + " \"data\": [\n" + + " {\n" + + " \"enrollmentId\": \"550e8400-e29b-41d4-a716-446655440000\",\n" + + " \"enrollmentVin\": \"1HGCM82633A123456\",\n" + + " \"happenedAtTime\": \"2024-06-15T08:00:00Z\",\n" + + " \"id\": \"12345\",\n" + + " \"testResult\": \"pass\",\n" + + " \"testResultDetails\": \"Response from CARB CTC: Vehicle PASSED emissions scan.\"\n" + + " }\n" + + " ],\n" + + " \"pagination\": {\n" + + " \"endCursor\": \"MjkY\",\n" + + " \"hasNextPage\": true\n" + + " }\n" + + "}"; + JsonNode actualResponseNode = objectMapper.readTree(actualResponseJson); + JsonNode expectedResponseNode = objectMapper.readTree(expectedResponseBody); + Assertions.assertTrue( + jsonEquals(expectedResponseNode, actualResponseNode), + "Response body structure does not match expected"); + if (actualResponseNode.has("type") || actualResponseNode.has("_type") || actualResponseNode.has("kind")) { + String discriminator = null; + if (actualResponseNode.has("type")) + discriminator = actualResponseNode.get("type").asText(); + else if (actualResponseNode.has("_type")) + discriminator = actualResponseNode.get("_type").asText(); + else if (actualResponseNode.has("kind")) + discriminator = actualResponseNode.get("kind").asText(); + Assertions.assertNotNull(discriminator, "Union type should have a discriminator field"); + Assertions.assertFalse(discriminator.isEmpty(), "Union discriminator should not be empty"); + } + + if (!actualResponseNode.isNull()) { + Assertions.assertTrue( + actualResponseNode.isObject() || actualResponseNode.isArray() || actualResponseNode.isValueNode(), + "response should be a valid JSON value"); + } + + if (actualResponseNode.isArray()) { + Assertions.assertTrue(actualResponseNode.size() >= 0, "Array should have valid size"); + } + if (actualResponseNode.isObject()) { + Assertions.assertTrue(actualResponseNode.size() >= 0, "Object should have valid field count"); + } + } + + /** + * Compares two JsonNodes with numeric equivalence and null safety. + * For objects, checks that all fields in 'expected' exist in 'actual' with matching values. + * Allows 'actual' to have extra fields (e.g., default values added during serialization). + */ + private boolean jsonEquals(JsonNode expected, JsonNode actual) { + if (expected == null && actual == null) return true; + if (expected == null || actual == null) return false; + if (expected.equals(actual)) return true; + if (expected.isNumber() && actual.isNumber()) + return Math.abs(expected.doubleValue() - actual.doubleValue()) < 1e-10; + if (expected.isObject() && actual.isObject()) { + java.util.Iterator> iter = expected.fields(); + while (iter.hasNext()) { + java.util.Map.Entry entry = iter.next(); + JsonNode actualValue = actual.get(entry.getKey()); + if (actualValue == null || !jsonEquals(entry.getValue(), actualValue)) return false; + } + return true; + } + if (expected.isArray() && actual.isArray()) { + if (expected.size() != actual.size()) return false; + for (int i = 0; i < expected.size(); i++) { + if (!jsonEquals(expected.get(i), actual.get(i))) return false; + } + return true; + } + return false; + } +}