diff --git a/sources/Contenda/Contenda.Sdk/Auth/APIKeyAuthProvider.cs b/sources/Contenda/Contenda.Sdk/Auth/APIKeyAuthProvider.cs index 6371191..5a65575 100644 --- a/sources/Contenda/Contenda.Sdk/Auth/APIKeyAuthProvider.cs +++ b/sources/Contenda/Contenda.Sdk/Auth/APIKeyAuthProvider.cs @@ -1,9 +1,9 @@ using System; using System.IdentityModel.Tokens.Jwt; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using System.Web; using Contenda.Sdk.Exceptions; using Contenda.Sdk.Models.Request; using Contenda.Sdk.Models.Result; @@ -56,11 +56,11 @@ public async Task TryAuthenticate(string apiBaseUri) var client = PoorMansHttpClientFactory.Instance.Client; - var uri = $"{apiBaseUri}{Constants.Version2Prefix}{Constants.IdentityV2.Token}"; - var body = new TokenV2 + var uri = $"{apiBaseUri}{Constants.AuthVersion1Prefix}{Constants.AuthV1.Token}"; + var body = new AuthV1Token { api_key = _apiKey, - email = _email + user_email = _email }; var bodyString = JsonConvert.SerializeObject(body); @@ -79,13 +79,13 @@ public async Task TryAuthenticate(string apiBaseUri) } } - private bool EnsureValid() => DateTime.Now < ValidUntil(); + private bool EnsureValid() => DateTime.UtcNow < ValidUntil(); /// public void ModifyHeadersCallback(HttpClient httpClient) { if (!EnsureValid()) throw new AuthenticationException("You have to be authenticated to call APIs with authentication."); - // nothing to do here + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiToken); } /// @@ -93,11 +93,10 @@ public string ModifyQueryCallback(string currentQuery) { if (!EnsureValid()) throw new AuthenticationException("You have to be authenticated to call APIs with authentication."); - var nvc = HttpUtility.ParseQueryString((new Uri(currentQuery)).Query); - var paramChar = nvc.Count == 0 ? "?" : "&"; - return $"{currentQuery}{paramChar}token={HttpUtility.UrlEncode(_apiToken)}"; - } + // nothing to do here + return currentQuery; + } } } diff --git a/sources/Contenda/Contenda.Sdk/Constants.cs b/sources/Contenda/Contenda.Sdk/Constants.cs index fd5e4f7..7a92971 100644 --- a/sources/Contenda/Contenda.Sdk/Constants.cs +++ b/sources/Contenda/Contenda.Sdk/Constants.cs @@ -2,9 +2,11 @@ { internal static class Constants { - internal const string BaseApiUri = "https://prod.contenda.io/"; + internal const string BaseApiUri = "https://prod.contenda.co/"; - internal const string Version2Prefix = "api/v2/"; + internal const string MainVersion3Prefix = "api/v3/"; + + internal const string AuthVersion1Prefix = "auth/v1/"; internal const string Health = "health"; @@ -12,12 +14,12 @@ internal static class Constants internal const string JsonMimeType = "application/json"; - internal static class IdentityV2 + internal static class AuthV1 { - internal const string Token = "identity/token"; + internal const string Token = "flow/apilogin"; } - internal static class JobsV2 + internal static class JobsV3 { internal const string Status = "jobs/status/"; @@ -26,7 +28,7 @@ internal static class JobsV2 internal const string UsageLimits = "jobs/usage-limits"; } - internal static class ContentV2 + internal static class ContentV3 { internal const string BlogMarkdown = "content/blog/{0}/markdown"; } diff --git a/sources/Contenda/Contenda.Sdk/Contenda.Sdk.csproj b/sources/Contenda/Contenda.Sdk/Contenda.Sdk.csproj index 63edab0..f5908c6 100644 --- a/sources/Contenda/Contenda.Sdk/Contenda.Sdk.csproj +++ b/sources/Contenda/Contenda.Sdk/Contenda.Sdk.csproj @@ -4,8 +4,8 @@ netstandard2.0 latest enable - 0.1.1.0 - 0.1.1.0 + 0.2.0.0 + 0.2.0.0 Contenda .NET SDK tomzorz Contenda @@ -16,7 +16,7 @@ True https://github.com/Contenda-Team/contenda-dotnet-sdk MIT - 0.1.1 + 0.2.0 https://github.com/Contenda-Team/contenda-dotnet-sdk logo_white.png diff --git a/sources/Contenda/Contenda.Sdk/ContendaAPI.cs b/sources/Contenda/Contenda.Sdk/ContendaAPI.cs index d33b844..f45390a 100644 --- a/sources/Contenda/Contenda.Sdk/ContendaAPI.cs +++ b/sources/Contenda/Contenda.Sdk/ContendaAPI.cs @@ -65,7 +65,7 @@ public async Task Authenticate() public async Task GetUsageLimits() { var client = PoorMansHttpClientFactory.Instance.Client; - var uri = $"{_apiBaseUri}{Constants.Version2Prefix}{Constants.JobsV2.UsageLimits}"; + var uri = $"{_apiBaseUri}{Constants.MainVersion3Prefix}{Constants.JobsV3.UsageLimits}"; _authProvider.ModifyHeadersCallback(client); uri = _authProvider.ModifyQueryCallback(uri); @@ -84,7 +84,7 @@ public async Task Authenticate() public async Task GetJobStatus(string jobId) { var client = PoorMansHttpClientFactory.Instance.Client; - var uri = $"{_apiBaseUri}{Constants.Version2Prefix}{Constants.JobsV2.Status}{HttpUtility.UrlEncode(jobId)}"; + var uri = $"{_apiBaseUri}{Constants.MainVersion3Prefix}{Constants.JobsV3.Status}{HttpUtility.UrlEncode(jobId)}"; _authProvider.ModifyHeadersCallback(client); uri = _authProvider.ModifyQueryCallback(uri); @@ -126,12 +126,12 @@ public async Task Authenticate() public async Task SubmitVideoToBlogJob(string sourceId, VideoToBlogJobSubType subType, string? statusUpdateWebhookUrl = null, string? statusUpdateEmail = null) { var client = PoorMansHttpClientFactory.Instance.Client; - var uri = $"{_apiBaseUri}{Constants.Version2Prefix}{Constants.JobsV2.SubmitVideoToBlog}"; + var uri = $"{_apiBaseUri}{Constants.MainVersion3Prefix}{Constants.JobsV3.SubmitVideoToBlog}"; _authProvider.ModifyHeadersCallback(client); uri = _authProvider.ModifyQueryCallback(uri); - var content = new StringContent(JsonConvert.SerializeObject(new SubmitJobV2 + var content = new StringContent(JsonConvert.SerializeObject(new SubmitJobV3 { source_id = sourceId, status_update_email = statusUpdateEmail, @@ -153,7 +153,7 @@ public async Task Authenticate() public async Task GetBlogAsMarkdown(string blogId) { var client = PoorMansHttpClientFactory.Instance.Client; - var uri = $"{_apiBaseUri}{Constants.Version2Prefix}{Constants.ContentV2.BlogMarkdown}"; + var uri = $"{_apiBaseUri}{Constants.MainVersion3Prefix}{Constants.ContentV3.BlogMarkdown}"; uri = string.Format(uri, blogId); diff --git a/sources/Contenda/Contenda.Sdk/Models/Request/TokenV2.cs b/sources/Contenda/Contenda.Sdk/Models/Request/AuthV1Token.cs similarity index 66% rename from sources/Contenda/Contenda.Sdk/Models/Request/TokenV2.cs rename to sources/Contenda/Contenda.Sdk/Models/Request/AuthV1Token.cs index 56b4660..ad891a1 100644 --- a/sources/Contenda/Contenda.Sdk/Models/Request/TokenV2.cs +++ b/sources/Contenda/Contenda.Sdk/Models/Request/AuthV1Token.cs @@ -4,9 +4,9 @@ namespace Contenda.Sdk.Models.Request { - internal class TokenV2 + internal class AuthV1Token { - public string? email { [UsedImplicitly] get; set; } + public string? user_email { [UsedImplicitly] get; set; } public string? api_key { [UsedImplicitly] get; set; } } diff --git a/sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV2.cs b/sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV3.cs similarity index 92% rename from sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV2.cs rename to sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV3.cs index b00d62e..dac705c 100644 --- a/sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV2.cs +++ b/sources/Contenda/Contenda.Sdk/Models/Request/SubmitJobV3.cs @@ -4,7 +4,7 @@ namespace Contenda.Sdk.Models.Request { - internal class SubmitJobV2 + internal class SubmitJobV3 { public string? source_id { [UsedImplicitly] get; set; } diff --git a/sources/Contenda/Contenda.Sdk/Models/Result/TokenResult.cs b/sources/Contenda/Contenda.Sdk/Models/Result/TokenResult.cs index 3788ff4..ab19e05 100644 --- a/sources/Contenda/Contenda.Sdk/Models/Result/TokenResult.cs +++ b/sources/Contenda/Contenda.Sdk/Models/Result/TokenResult.cs @@ -6,8 +6,6 @@ namespace Contenda.Sdk.Models.Result { internal class TokenResult { - [UsedImplicitly] public string? valid_until { get; set; } - public string? access_token { get; [UsedImplicitly] set; } } } diff --git a/sources/Contenda/Contenda.SdkDemo/Program.cs b/sources/Contenda/Contenda.SdkDemo/Program.cs index 6cee30c..bdc7965 100644 --- a/sources/Contenda/Contenda.SdkDemo/Program.cs +++ b/sources/Contenda/Contenda.SdkDemo/Program.cs @@ -23,6 +23,8 @@ Console.WriteLine($"Successfully submitted job: {jobId}"); +await Task.Delay(TimeSpan.FromSeconds(5)); + var jobStatus = await api.GetJobStatus(jobId!); while (jobStatus!.Status != "succeeded" && jobStatus.Status != "failed")