Skip to content

Commit

Permalink
feat: Support get collection by ID endpoint (box/box-openapi#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Nov 4, 2024
1 parent aed06af commit 9394b50
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "9c64675", "specHash": "9d452cf", "version": "1.4.0" }
{ "engineHash": "9c64675", "specHash": "c2c76f3", "version": "1.4.0" }
20 changes: 20 additions & 0 deletions Box.Sdk.Gen/Managers/Collections/CollectionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,25 @@ public async System.Threading.Tasks.Task<Items> GetCollectionItemsAsync(string c
return SimpleJsonSerializer.Deserialize<Items>(response.Data);
}

/// <summary>
/// Retrieves a collection by its ID.
/// </summary>
/// <param name="collectionId">
/// The ID of the collection.
/// Example: "926489"
/// </param>
/// <param name="headers">
/// Headers of getCollectionById method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public async System.Threading.Tasks.Task<Collection> GetCollectionByIdAsync(string collectionId, GetCollectionByIdHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
headers = headers ?? new GetCollectionByIdHeaders();
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { }, headers.ExtraHeaders));
FetchResponse response = await HttpClientAdapter.FetchAsync(new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/collections/", StringUtils.ToStringRepresentation(collectionId)), networkSession: this.NetworkSession) { Method = "GET", Headers = headersMap, ResponseFormat = "json", Auth = this.Auth, CancellationToken = cancellationToken }).ConfigureAwait(false);
return SimpleJsonSerializer.Deserialize<Collection>(response.Data);
}

}
}
19 changes: 19 additions & 0 deletions Box.Sdk.Gen/Managers/Collections/GetCollectionByIdHeaders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Box.Sdk.Gen;
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Internal;

namespace Box.Sdk.Gen.Managers {
public class GetCollectionByIdHeaders {
/// <summary>
/// Extra headers that will be included in the HTTP request.
/// </summary>
public Dictionary<string, string?> ExtraHeaders { get; }

public GetCollectionByIdHeaders(Dictionary<string, string?>? extraHeaders = default) {
ExtraHeaders = extraHeaders ?? new Dictionary<string, string?>() { };
}
}
}
15 changes: 15 additions & 0 deletions Box.Sdk.Gen/Managers/Collections/ICollectionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,20 @@ public interface ICollectionsManager {
/// </param>
public System.Threading.Tasks.Task<Items> GetCollectionItemsAsync(string collectionId, GetCollectionItemsQueryParams? queryParams = default, GetCollectionItemsHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null) => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it.");

/// <summary>
/// Retrieves a collection by its ID.
/// </summary>
/// <param name="collectionId">
/// The ID of the collection.
/// Example: "926489"
/// </param>
/// <param name="headers">
/// Headers of getCollectionById method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public System.Threading.Tasks.Task<Collection> GetCollectionByIdAsync(string collectionId, GetCollectionByIdHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null) => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it.");

}
}
29 changes: 29 additions & 0 deletions docs/Collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

- [List all collections](#list-all-collections)
- [List collection items](#list-collection-items)
- [Get collection by ID](#get-collection-by-id)

## List all collections

Expand Down Expand Up @@ -72,3 +73,31 @@ This function returns a value of type `Items`.
Returns an array of items in the collection.


## Get collection by ID

Retrieves a collection by its ID.

This operation is performed by calling function `GetCollectionById`.

See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-collections-id/).

*Currently we don't have an example for calling `GetCollectionById` in integration tests*

### Arguments

- collectionId `string`
- The ID of the collection. Example: "926489"
- headers `GetCollectionByIdHeaders`
- Headers of getCollectionById method
- cancellationToken `System.Threading.CancellationToken?`
- Token used for request cancellation.


### Returns

This function returns a value of type `Collection`.

Returns an array of items in the collection.


0 comments on commit 9394b50

Please sign in to comment.