Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitAuto: [FEATURE] Use Feed V3 to get the orders #353

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions Src/VTEXFeedV3Config.cs
Original file line number Diff line number Diff line change
@@ -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";

Check failure on line 12 in Src/VTEXFeedV3Config.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/VTEXFeedV3Config.cs#L12

Change this constant to a 'static' read-only property.
}
47 changes: 47 additions & 0 deletions Src/VTEXFeedV3Integration.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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.");

Check warning on line 37 in Src/VTEXFeedV3Integration.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/VTEXFeedV3Integration.cs#L37

'System.Exception' should not be thrown by user code.
}
return content;
}
catch (HttpRequestException e)
{
throw new Exception("Error fetching order status from VTEX API.", e);

Check warning on line 43 in Src/VTEXFeedV3Integration.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/VTEXFeedV3Integration.cs#L43

'System.Exception' should not be thrown by user code.
}
}
}
}
46 changes: 46 additions & 0 deletions Tests/VTEXFeedV3IntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -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<Exception>(
async () => await integration.GetFeedOrderStatus1Async()
);
}

[Fact]
public async Task GetFeedOrderStatus1Async_EmptyResponse_ThrowsException()
{
// Arrange
var integration = new VTEXFeedV3Integration("validApiKey", "validApiToken");

// Act & Assert
await Assert.ThrowsAsync<Exception>(
async () => await integration.GetFeedOrderStatus1Async()
);
}
}
}
Loading