Skip to content

Commit

Permalink
Release 103 (#24)
Browse files Browse the repository at this point in the history
* Address confusion in client setup

We have two methods, WithBearerToken and WithApiKey.  The WithApiKey function doesn't work, so remove it.

Also, it's easy to mess up the custom environment string. Let's replace with an URI object.

# Patch notes for 103.0.3003

These patch notes summarize the changes from version 102.0.2886.

Added 2 new APIs:
* Changeset.RetrieveChangesetsByProjectID (GET /api/data/projects/{projectId}/changesets)
* Project.DeleteProject (DELETE /api/data/projects/{projectId})

Deprecated 1 old APIs:
* TaskMetadata.GetTaskMetadata
  • Loading branch information
tspence authored Feb 11, 2024
1 parent 9bcca64 commit 29f6280
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 57 deletions.
25 changes: 11 additions & 14 deletions ProjectManagerClient.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>ProjectManager.SDK</id>
<version>102.0.2949</version>
<version>103.0.3003</version>
<title>ProjectManager.SDK</title>
<authors>ProjectManager.com</authors>
<owners>ProjectManager.com, Inc.</owners>
Expand All @@ -14,19 +14,16 @@
<readme>docs/README.md</readme>
<summary>ProjectManager API for DotNet</summary>
<releaseNotes>
# Patch notes for 102.0.2949

These patch notes summarize the changes from version 102.0.2886.

Added 2 new APIs:
* Changeset.RetrieveChangesetsByProjectID (GET /api/data/changesets/{projectId}/changesets)
* Project.DeleteProject (DELETE /api/data/projects/{projectId})

Deprecated 1 old APIs:
* TaskMetadata.GetTaskMetadata

Fixed capitalization for data schema models and API methods - the previous build caused some items
to be incorrectly lowercased when they were already in PascalCase form.
# Patch notes for 103.0.3003

These patch notes summarize the changes from version 102.0.2886.

Added 2 new APIs:
* Changeset.RetrieveChangesetsByProjectID (GET /api/data/projects/{projectId}/changesets)
* Project.DeleteProject (DELETE /api/data/projects/{projectId})

Deprecated 1 old APIs:
* TaskMetadata.GetTaskMetadata


</releaseNotes>
Expand Down
2 changes: 1 addition & 1 deletion src/Clients/ChangesetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task<AstroResult<ChangesetGetResponseDto>> RetrieveCompletedChanges
/// <param name="take"></param>
public async Task<AstroResult<ChangeSetResponseDto[]>> RetrieveChangesetsByProjectID(Guid projectId, int? version = null, int? page = null, int? take = null)
{
var url = $"/api/data/changesets/{projectId}/changesets";
var url = $"/api/data/projects/{projectId}/changesets";
var options = new Dictionary<string, object>();
if (version != null) { options["version"] = version; }
if (page != null) { options["page"] = page; }
Expand Down
2 changes: 1 addition & 1 deletion src/IProjectManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author ProjectManager.com <[email protected]>
*
* @copyright 2023-2024 ProjectManager.com, Inc.
* @version 102.0.2949
* @version 103.0.3003
* @link https://github.com/projectmgr/projectmanager-sdk-csharp
*/

Expand Down
9 changes: 9 additions & 0 deletions src/Models/ProjectFileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,14 @@ public class ProjectFileDto : ApiModel
/// To expand this field, specify the name of this field in the `$expand` parameter.
/// </summary>
public ProjectFileTaskDto Task { get; set; }

/// <summary>
/// The folder that this file relates to.
///
/// This field will be present when you fetch a single object.
/// When you query for multiple objects, this field is not included in results by default.
/// To expand this field, specify the name of this field in the `$expand` parameter.
/// </summary>
public ProjectFileFolderDto Folder { get; set; }
}
}
39 changes: 39 additions & 0 deletions src/Models/ProjectFileFolderDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/***
* ProjectManager API for C#
*
* (c) 2023-2024 ProjectManager.com, Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author ProjectManager.com <[email protected]>
* @copyright 2023-2024 ProjectManager.com, Inc.
* @link https://github.com/projectmgr/projectmanager-sdk-csharp
*/



#pragma warning disable CS8618

using System;

namespace ProjectManager.SDK.Models
{

/// <summary>
/// A Folder is a named storage location that can contain Files.
/// </summary>
public class ProjectFileFolderDto : ApiModel
{

/// <summary>
/// The unique identifier of this Folder.
/// </summary>
public Guid? Id { get; set; }

/// <summary>
/// The name of this Folder.
/// </summary>
public string Name { get; set; }
}
}
5 changes: 0 additions & 5 deletions src/Models/WorkSpaceDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public class WorkSpaceDto : ApiModel
/// </summary>
public DateTime? RegisterDate { get; set; }

/// <summary>
/// True if the user has accepted an invitation to this Workspace.
/// </summary>
public bool? IsInviteAccepted { get; set; }

/// <summary>
/// The unique identifier of the BusinessUser that is the owner of this Workspace.
/// </summary>
Expand Down
52 changes: 16 additions & 36 deletions src/ProjectManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author ProjectManager.com <[email protected]>
*
* @copyright 2023-2024 ProjectManager.com, Inc.
* @version 102.0.2949
* @version 103.0.3003
* @link https://github.com/projectmgr/projectmanager-sdk-csharp
*/

Expand Down Expand Up @@ -39,15 +39,14 @@ public class ProjectManagerClient : IProjectManagerClient
/// <summary>
/// The version of the SDK
/// </summary>
public const string SdkVersion = "102.0.2949";
public const string SdkVersion = "103.0.3003";

private readonly string _apiUrl;
private readonly HttpClient _client;
internal readonly JsonSerializerOptions _options;

private string _appName;
private string _bearerToken;
private string _apiKey;

/// <summary>
/// API methods related to ApiKey
Expand Down Expand Up @@ -243,19 +242,24 @@ public class ProjectManagerClient : IProjectManagerClient
/// <summary>
/// Internal constructor for the client. You should always begin with `WithEnvironment()` or `WithCustomEnvironment`.
/// </summary>
/// <param name="url"></param>
/// <param name="baseEndpoint">The API endpoint to contact</param>
/// <param name="clientHandler">Handler for the HTTP client, when null the default handler will be used</param>
private ProjectManagerClient(string url, HttpClientHandler clientHandler)
private ProjectManagerClient(Uri baseEndpoint, HttpClientHandler clientHandler)
{
// Throw error if not HTTPS
if (baseEndpoint.Scheme != "https")
{
throw new InvalidOperationException("Invalid environment url. Please ensure the environment url starts with 'https://'");
}

// Add support for HTTP compression
var handler = clientHandler ?? new HttpClientHandler();
handler.AutomaticDecompression = DecompressionMethods.GZip;

// We intentionally use a single HttpClient object for the lifetime of this API connection.
// Best practices: https://bytedev.medium.com/net-core-httpclient-best-practices-4c1b20e32c6
_client = new HttpClient(handler);

_apiUrl = url;
_apiUrl = baseEndpoint.ToString();
ApiKey = new ApiKeyClient(this);
Changeset = new ChangesetClient(this);
Dashboard = new DashboardClient(this);
Expand Down Expand Up @@ -311,10 +315,10 @@ private ProjectManagerClient(string url, HttpClientHandler clientHandler)
/// <returns>The API client to use</returns>
public static ProjectManagerClient WithEnvironment(string env, HttpClientHandler clientHandler = null)
{
switch (env)
switch (env)
{
case "production":
return new ProjectManagerClient("https://api.projectmanager.com", clientHandler);
return new ProjectManagerClient(new Uri("https://api.projectmanager.com"), clientHandler);
}

throw new InvalidOperationException($"Unknown environment: {env}");
Expand All @@ -325,17 +329,12 @@ public static ProjectManagerClient WithEnvironment(string env, HttpClientHandler
/// an API gateway. Please be careful when using this mode.
/// You should prefer to use `WithEnvironment()` instead wherever possible.
/// </summary>
/// <param name="url">The custom URL to use for this client</param>
/// <param name="customEndpoint">The custom endpoint to use for this client</param>
/// <param name="clientHandler">Optional handler to set specific settings for the HTTP client</param>
/// <returns>The API client to use</returns>
public static ProjectManagerClient WithCustomEnvironment(string url, HttpClientHandler clientHandler = null)
public static ProjectManagerClient WithCustomEnvironment(Uri customEndpoint, HttpClientHandler clientHandler = null)
{
if (!url.StartsWith("https://"))
{
throw new InvalidOperationException("Invalid custom environment url. Please ensure the environment url starts with 'https://'");
}

return new ProjectManagerClient(url, clientHandler);
return new ProjectManagerClient(customEndpoint, clientHandler);
}

/// <summary>
Expand All @@ -359,21 +358,6 @@ public ProjectManagerClient WithAppName(string name)
public ProjectManagerClient WithBearerToken(string token)
{
_bearerToken = token;
_apiKey = null;
return this;
}

/// <summary>
/// Configures this API client to use an API Key.
///
///
/// </summary>
/// <param name="apiKey">The API key to use for this API session</param>
/// <returns></returns>
public ProjectManagerClient WithApiKey(string apiKey)
{
_apiKey = apiKey;
_bearerToken = null;
return this;
}

Expand Down Expand Up @@ -408,10 +392,6 @@ public async Task<AstroResult<T>> Request<T>(HttpMethod method, string path,
{
request.Headers.Add("Authorization", "Bearer " + _bearerToken);
}
else if (!string.IsNullOrWhiteSpace(_apiKey))
{
request.Headers.Add("Api-Key", _apiKey);
}

// Construct the request URI and query string
var uriBuilder = new UriBuilder(_apiUrl)
Expand Down

0 comments on commit 29f6280

Please sign in to comment.