deepgram / deepgram-dotnet-sdk

.NET SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
28 stars 32 forks source link

Add "key" to public Record Key #300

Closed tieje closed 3 months ago

tieje commented 3 months ago

Proposed changes

Add "key" to public Record Key

Context

I needed to perform a workaround by using normal HTTP requests instead of the Deepgram library just to get the "key" when creating a key. The NodeJS SDK just gives you the key.

image

Possible Implementation

Please just add "key" to public record Key

My current workaround:

        string comment = "\"Temporary User Key\"";
        string scopes = "[\"usage:write\"]";
        string tags = "[\"public\", \"user\"]";

        StringBuilder sb = new();

        sb.AppendLine("{");
        sb.AppendLine($"\"comment\": {comment},");
        sb.AppendLine($"\"scopes\": {scopes},");
        sb.AppendLine($"\"tags\": {tags}");
        //sb.AppendLine($"\"\": \"{expiration}\"");
        sb.AppendLine("}");

        HttpContent httpContent = new StringContent(sb.ToString(), Encoding.UTF8, "application/json");

        var client = new HttpClient();
        var request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri($"https://api.deepgram.com/v1/projects/{options.ProjectId}/keys"),
            Content = httpContent
        };

        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        request.Headers.Authorization = new AuthenticationHeaderValue("Token", options.ApiKey);

        using HttpResponseMessage response = await client.SendAsync(request);

        //response.EnsureSuccessStatusCode();
        string body = await response.Content.ReadAsStringAsync();

        return body;

Other information

dvonthenen commented 3 months ago

Hi @tieje

Thanks for the issue. Looks like just a small oversight/oops.

Either you can submit a PR for the change, or I should get back to this SDK sometime mid next week. You put more time into the bug report than just opening the PR for this small little change. 😀

tieje3 commented 3 months ago

This is my work account. I'm not a contributor. I cannot push branches to make PRs.

Here is the code: for Key.cs

// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Manage.v1;

public record Key
{
    /// <summary>
    /// Unique identifier of the Deepgram API key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("api_key_id")]
    public string? ApiKeyId { get; set; }

    /// <summary>
    /// Deepgram secret key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("key")]
    public string? Key { get; set; }

    /// <summary>
    /// Comment for the Deepgram API key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("comment")]
    public string? Comment { get; set; }

    /// <summary>
    /// Scope of the Deepgram API key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("scopes")]
    public IReadOnlyList<string>? Scopes { get; set; }

    /// <summary>
    /// Creation date of the Deepgram API key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("created")]
    public DateTime? Created { get; set; }

    /// <summary>
    /// Tags for the Deepgram API key
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonPropertyName("tags")]
    public IReadOnlyList<string>? Tags { get; set; }

    /// <summary>
    /// Override ToString method to serialize the object
    /// </summary>
    public override string ToString()
    {
        return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
    }
}
dvonthenen commented 3 months ago

I mean you can fork the repo, create a branch from your fork with the change, and submit the PR from your fork. No special access required.

My primary system is a Mac. So I don't fire up the ol' Windows laptop unless there is an urgent issue or after my round robin time allocation for Windows comes up (which is looking like mid next week).

In worst case, will get to it with a release containing the fix mid next week.

tieje3 commented 3 months ago

Thank you for teaching me how to create a pull request. You can find it here

dvonthenen commented 3 months ago

Thanks for doing this! Will cut a release of this on Monday!

dvonthenen commented 2 months ago

@tieje3 this change is available in this release: https://github.com/deepgram/deepgram-dotnet-sdk/releases/tag/4.0.2

thanks again for your contribution!