Skip to content

Commit

Permalink
Merge pull request #39 from ahwm/httpclient-update
Browse files Browse the repository at this point in the history
initial updates to HttpClient
  • Loading branch information
ahwm authored Oct 22, 2024
2 parents 09a4145 + 90b110d commit f2047eb
Show file tree
Hide file tree
Showing 18 changed files with 336 additions and 354 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "**"
pull_request:
branches:
- "main"
- "master"
jobs:
build:
runs-on: windows-latest
Expand All @@ -17,16 +17,16 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Setup .NET 3.1
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.x
dotnet-version: 6.0.x
- name: Build
run: |
cd src
dotnet build
- name: Test
if: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}
if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request' }}
env:
GODADDY_API_SECRET: ${{ secrets.GODADDY_API_SECRET }}
GODADDY_ACCESS_KEY: ${{ secrets.GODADDY_ACCESS_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ obj
bin
.vs
*.user
*.runsettings
50 changes: 35 additions & 15 deletions src/GodaddyWrapper.Tests/DomainTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using GodaddyWrapper;
using GodaddyWrapper.Base;
using GodaddyWrapper.Requests;
using GodaddyWrapper.Requests;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

namespace GodaddyWrapper.Tests
Expand All @@ -14,31 +12,53 @@ public class DomainTests
private readonly string AccessKey;

Check warning on line 12 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.AccessKey' is never used

Check warning on line 12 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.AccessKey' is never used

Check warning on line 12 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.AccessKey' is never used

Check warning on line 12 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.AccessKey' is never used
private readonly string ApiSecret;

Check warning on line 13 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.ApiSecret' is never used

Check warning on line 13 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.ApiSecret' is never used

Check warning on line 13 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.ApiSecret' is never used

Check warning on line 13 in src/GodaddyWrapper.Tests/DomainTests.cs

View workflow job for this annotation

GitHub Actions / build

The field 'DomainTests.ApiSecret' is never used

private readonly GoDaddyClient client;

#if NETCORE
public DomainTests(GoDaddyClient goDaddyClient)
{
client = goDaddyClient;
}
#else
public DomainTests()
{
AccessKey = Environment.GetEnvironmentVariable("GODADDY_ACCESS_KEY").Trim();
ApiSecret = Environment.GetEnvironmentVariable("GODADDY_API_SECRET").Trim();
client = new GoDaddyClient(new GoDaddyClientOptions { AccessKey = AccessKey, SecretKey = ApiSecret, IsTesting = true });
}
#endif

[Fact]
public async void DomainCheckTest()
public async Task DomainCheckTest()
{
var client = new Client(AccessKey, ApiSecret, "https://api.ote-godaddy.com/api/v1/");
var response = await client.CheckDomainAvailable(new DomainAvailable
try
{
Domain = "google.com"
});
var response = await client.CheckDomainAvailable(new DomainAvailable
{
Domain = "google.com"
});

response.Available.ShouldBe(false);
response.Available.ShouldBe(false);
}
catch (Exception)
{
Assert.Fail();
}
}

[Fact]
public async void DomainListTest()
public async Task DomainListTest()
{
var client = new Client(AccessKey, ApiSecret, "https://api.ote-godaddy.com/api/v1/");
var response = await client.RetrieveDomainList(new DomainRetrieve { Limit = 100 });
try
{
var response = await client.RetrieveDomainList(new DomainRetrieve { Limit = 100 });

response.Count.ShouldBe(0);
response.Count.ShouldBe(0);
}
catch (Exception)
{
Assert.Fail();
}
}
}
}
9 changes: 7 additions & 2 deletions src/GodaddyWrapper.Tests/GodaddyWrapper.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net8.0'">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
21 changes: 21 additions & 0 deletions src/GodaddyWrapper.Tests/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using GodaddyWrapper;
#if NETCORE
using Microsoft.Extensions.DependencyInjection;
using System;
#endif

namespace GodaddyWrapper.Tests
{
#if NETCORE
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
string AccessKey = Environment.GetEnvironmentVariable("GODADDY_ACCESS_KEY").Trim();
string ApiSecret = Environment.GetEnvironmentVariable("GODADDY_API_SECRET").Trim();
services.AddGoDaddy(AccessKey, ApiSecret, true);
//services.AddTransient<IDomainService, OpenSRSDomainService>();
}
}
#endif
}
98 changes: 44 additions & 54 deletions src/GodaddyWrapper/Client.AbuseTicket.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
using GodaddyWrapper.Responses;
using GodaddyWrapper.Requests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using GodaddyWrapper.Helper;
using GodaddyWrapper.Helper;
using GodaddyWrapper.Requests;
using GodaddyWrapper.Responses;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace GodaddyWrapper
{
public partial class Client
{
/// <summary>
/// Create a new abuse ticket
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketIdResponse> CreateAbuseTicket(AbuseTicketCreate request)
{
var client = GetBaseHttpClient();
var response = await client.PostAsync($"abuse/tickets", JsonConvert.SerializeObject(request, JsonSettings));
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketIdResponse>();
}
/// <summary>
/// List all abuse tickets ids that match user provided filters
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketListResponse> RetrieveAbuseTickets(AbuseTicketRetrieve request)
{
var client = GetBaseHttpClient();
var response = await client.GetAsync($"abuse/tickets{QueryStringBuilder.RequestObjectToQueryString(request)}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketListResponse>();
}

/// <summary>
/// Return the abuse ticket data for a given ticket id
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketResponse> RetrieveAbuseTicketDetail(AbuseTicketDetailRetrieve request)
{
var client = GetBaseHttpClient();
var response = await client.GetAsync($"abuse/tickets/{request.TicketId}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketResponse>();
}

}
}
namespace GodaddyWrapper
{
public partial class GoDaddyClient
{
/// <summary>
/// Create a new abuse ticket
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketIdResponse> CreateAbuseTicket(AbuseTicketCreate request)
{
var response = await httpClient.PostAsync($"abuse/tickets", JsonConvert.SerializeObject(request, JsonSettings));
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketIdResponse>();
}
/// <summary>
/// List all abuse tickets ids that match user provided filters
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketListResponse> RetrieveAbuseTickets(AbuseTicketRetrieve request)
{
var response = await httpClient.GetAsync($"abuse/tickets{QueryStringBuilder.RequestObjectToQueryString(request)}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketListResponse>();
}

/// <summary>
/// Return the abuse ticket data for a given ticket id
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<AbuseTicketResponse> RetrieveAbuseTicketDetail(AbuseTicketDetailRetrieve request)
{
var response = await httpClient.GetAsync($"abuse/tickets/{request.TicketId}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AbuseTicketResponse>();
}
}
}
19 changes: 6 additions & 13 deletions src/GodaddyWrapper/Client.Aftermarket.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using GodaddyWrapper.Responses;
using GodaddyWrapper.Helper;
using GodaddyWrapper.Requests;
using System;
using GodaddyWrapper.Responses;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using GodaddyWrapper.Helper;
using Newtonsoft.Json;

namespace GodaddyWrapper
{
public partial class Client
public partial class GoDaddyClient
{

/// <summary>
Expand All @@ -22,8 +17,7 @@ public partial class Client
/// <returns></returns>
public async Task<AftermarketListingActionResponse> AddExpiryAuction(List<AftermarketListingExpiryCreate> request)
{
var client = GetBaseHttpClient();
var response = await client.PostAsync($"aftermarket/listings/expiry", JsonConvert.SerializeObject(request, JsonSettings));
var response = await httpClient.PostAsync($"aftermarket/listings/expiry", JsonConvert.SerializeObject(request, JsonSettings));
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<AftermarketListingActionResponse>();
}
Expand All @@ -35,8 +29,7 @@ public async Task<AftermarketListingActionResponse> AddExpiryAuction(List<Afterm
/// <returns></returns>
public async Task<ListingActionResponse> RemoveAuctionListings(AgreementRetrieve request)
{
var client = GetBaseHttpClient();
var response = await client.DeleteAsync($"aftermarket/listings{QueryStringBuilder.RequestObjectToQueryString(request)}");
var response = await httpClient.DeleteAsync($"aftermarket/listings{QueryStringBuilder.RequestObjectToQueryString(request)}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<ListingActionResponse>();
}
Expand Down
19 changes: 6 additions & 13 deletions src/GodaddyWrapper/Client.Agreements.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using GodaddyWrapper.Responses;
using GodaddyWrapper.Helper;
using GodaddyWrapper.Requests;
using System;
using GodaddyWrapper.Responses;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using GodaddyWrapper.Helper;

namespace GodaddyWrapper
{
public partial class Client
public partial class GoDaddyClient
{

/// <summary>
Expand All @@ -23,13 +18,11 @@ public partial class Client
/// <returns></returns>
public async Task<List<LegalAgreementResponse>> RetrieveAgreements(AgreementRetrieve request, string XPrivateLabelId = null, string XMarketId = null)
{
var client = GetBaseHttpClient();

if (XPrivateLabelId != null)
client.DefaultRequestHeaders.Add("X-Private-Label-Id", XPrivateLabelId);
httpClient.DefaultRequestHeaders.Add("X-Private-Label-Id", XPrivateLabelId);
if (XMarketId != null)
client.DefaultRequestHeaders.Add("X-Market-Id", XMarketId);
var response = await client.GetAsync($"aggreements{QueryStringBuilder.RequestObjectToQueryString(request)}");
httpClient.DefaultRequestHeaders.Add("X-Market-Id", XMarketId);
var response = await httpClient.GetAsync($"aggreements{QueryStringBuilder.RequestObjectToQueryString(request)}");
await CheckResponseMessageIsValid(response);
return await response.Content.ReadAsAsync<List<LegalAgreementResponse>>();
}
Expand Down
Loading

0 comments on commit f2047eb

Please sign in to comment.