diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..66bd44e97 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + env: + VTEX_API_KEY: ${{ secrets.VTEX_API_KEY }} + VTEX_API_TOKEN: ${{ secrets.VTEX_API_TOKEN }} + steps: + - uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '8.0.x' + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal diff --git a/README.md b/README.md index 79c4d7f5c..9e54c0cec 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,24 @@ Console.WriteLine("Sequence: {1} | Value: {0} | ", order.Value, order.Sequence); ``` +### VTEX Feed V3 API Integration + +To integrate with the VTEX Feed V3 API and retrieve order status information, use the `VTEXFeedV3Integration` class. + +```cs +using VTEXIntegration; + +var integration = new VTEXFeedV3Integration(VTEXFeedV3Config.ApiKey, VTEXFeedV3Config.ApiToken); + +try +{ + var orderStatus = await integration.GetFeedOrderStatus1Async(); + Console.WriteLine("Order Status: " + orderStatus); +} +catch (Exception ex) +{ + Console.WriteLine("Error: " + ex.Message); + --- ## Support diff --git a/Src/VTEXFeedV3Config.cs b/Src/VTEXFeedV3Config.cs new file mode 100644 index 000000000..9cc8cedef --- /dev/null +++ b/Src/VTEXFeedV3Config.cs @@ -0,0 +1,13 @@ +namespace VTEXIntegration +{ + public static class VTEXFeedV3Config + { + // Replace with your actual VTEX API key + public static string ApiKey => Environment.GetEnvironmentVariable("VTEX_API_KEY") ?? throw new ArgumentNullException("VTEX_API_KEY"); + + // Replace with your actual VTEX API token + public static string ApiToken => Environment.GetEnvironmentVariable("VTEX_API_TOKEN") ?? throw new ArgumentNullException("VTEX_API_TOKEN"); + + // VTEX account name + public const string AccountName = "your-account"; +} diff --git a/Src/VTEXFeedV3Integration.cs b/Src/VTEXFeedV3Integration.cs new file mode 100644 index 000000000..8cb4364b2 --- /dev/null +++ b/Src/VTEXFeedV3Integration.cs @@ -0,0 +1,47 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; + +namespace VTEXIntegration +{ + public class VTEXFeedV3Integration + { + private readonly HttpClient _httpClient; + private readonly string _apiKey; + private readonly string _apiToken; + + public VTEXFeedV3Integration(string apiKey, string apiToken) + { + _httpClient = new HttpClient(); + _apiKey = apiKey; + _apiToken = apiToken; + } + + public async Task GetFeedOrderStatus1Async() + { + var request = new HttpRequestMessage( + HttpMethod.Get, + "https://api.vtex.com/your-account/feed/orders/status" + ); + request.Headers.Add("X-VTEX-API-AppKey", _apiKey); + request.Headers.Add("X-VTEX-API-AppToken", _apiToken); + + try + { + var response = await _httpClient.SendAsync(request); + response.EnsureSuccessStatusCode(); + + var content = await response.Content.ReadAsStringAsync(); + if (string.IsNullOrWhiteSpace(content)) + { + throw new Exception("Received empty response from VTEX API."); + } + return content; + } + catch (HttpRequestException e) + { + throw new Exception("Error fetching order status from VTEX API.", e); + } + } + } +} diff --git a/Tests/VTEXFeedV3IntegrationTest.cs b/Tests/VTEXFeedV3IntegrationTest.cs new file mode 100644 index 000000000..5ee7e6831 --- /dev/null +++ b/Tests/VTEXFeedV3IntegrationTest.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Xunit; + +namespace VTEXIntegration.Tests +{ + public class VTEXFeedV3IntegrationTest + { + [Fact] + public async Task GetFeedOrderStatus1Async_ValidResponse_ReturnsContent() + { + // Arrange + var integration = new VTEXFeedV3Integration("validApiKey", "validApiToken"); + + // Act + var result = await integration.GetFeedOrderStatus1Async(); + + // Assert + Assert.False(string.IsNullOrWhiteSpace(result), "Expected non-empty response content."); + } + + [Fact] + public async Task GetFeedOrderStatus1Async_InvalidCredentials_ThrowsException() + { + // Arrange + var integration = new VTEXFeedV3Integration("invalidApiKey", "invalidApiToken"); + + // Act & Assert + await Assert.ThrowsAsync( + async () => await integration.GetFeedOrderStatus1Async() + ); + } + + [Fact] + public async Task GetFeedOrderStatus1Async_EmptyResponse_ThrowsException() + { + // Arrange + var integration = new VTEXFeedV3Integration("validApiKey", "validApiToken"); + + // Act & Assert + await Assert.ThrowsAsync( + async () => await integration.GetFeedOrderStatus1Async() + ); + } + } +}