Skip to content

Commit

Permalink
Add support for new API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
patchoulish committed Jan 12, 2025
1 parent 5d230dd commit 76f8853
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 0 deletions.
39 changes: 39 additions & 0 deletions source/Firecrawl.Tests/FirecrawlServiceTests.GetCreditUsage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Firecrawl
{
partial class FirecrawlServiceTests
{
/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
[TestCategory(
"FirecrawlService")]
[TestCategory(
"GetCreditUsage")]
[TestCategory(
"Result")]
[TestMethod]
public async Task GetCreditUsageAsync()
{
var creditUsageResult =
await this.firecrawl
.GetCreditUsageAsync();

Assert.IsNotNull(
creditUsageResult);

Assert.IsTrue(
creditUsageResult.Success);
}
}
}
111 changes: 111 additions & 0 deletions source/Firecrawl.Tests/FirecrawlServiceTests.Search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;

using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Firecrawl
{
partial class FirecrawlServiceTests
{
/// <summary>
///
/// </summary>
public static IEnumerable<object[]> SearchThrowOnBadRequestTestData =>
[
[
new FirecrawlSearchOptions()
{
Query = default
}
],
];

/// <summary>
///
/// </summary>
public static IEnumerable<object[]> SearchTestData =>
[
[
new FirecrawlSearchOptions()
{
Query = "current weather san francisco"
}
],
];

/// <summary>
///
/// </summary>
/// <returns></returns>
[TestCategory(
"FirecrawlService")]
[TestCategory(
"Search")]
[TestCategory(
"Argument")]
[TestMethod]
public async Task SearchThrowOnArgumentNullTestAsync()
{
await Assert.ThrowsExceptionAsync<ArgumentNullException>(
() => this.firecrawl.SearchAsync(
default));
}

/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
[TestCategory(
"FirecrawlService")]
[TestCategory(
"Search")]
[TestCategory(
"BadRequest")]
//[DataTestMethod]
[DynamicData(
nameof(SearchThrowOnBadRequestTestData))]
public async Task SearchThrowOnBadRequestAsync(
FirecrawlSearchOptions options)
{
await Assert.ThrowsExceptionAsync<FirecrawlException>(
() => this.firecrawl.SearchAsync(
options));
}

/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
[TestCategory(
"FirecrawlService")]
[TestCategory(
"Search")]
[TestCategory(
"Result")]
//[DataTestMethod]
[DynamicData(
nameof(SearchTestData))]
public async Task SearchAsync(
FirecrawlSearchOptions options)
{
var searchResult =
await this.firecrawl
.SearchAsync(
options);

Assert.IsNotNull(
searchResult);

Assert.IsTrue(
searchResult.Success);
}
}
}
20 changes: 20 additions & 0 deletions source/Firecrawl/FirecrawlCreditUsageData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Firecrawl
{
/// <summary>
///
/// </summary>
public class FirecrawlCreditUsageData
{
/// <summary>
///
/// </summary>
[JsonPropertyName(
"remaining_credits")]
public int CreditsRemaining { get; set; }
}
}
28 changes: 28 additions & 0 deletions source/Firecrawl/FirecrawlCreditUsageResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Firecrawl
{
/// <summary>
///
/// </summary>
public class FirecrawlCreditUsageResult :
FirecrawlResult
{
/// <summary>
///
/// </summary>
[JsonPropertyName(
"success")]
public bool Success { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"data")]
public FirecrawlCreditUsageData Data { get; init; }
}
}
72 changes: 72 additions & 0 deletions source/Firecrawl/FirecrawlSearchData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace Firecrawl
{
/// <summary>
///
/// </summary>
public class FirecrawlSearchData
{
/// <summary>
///
/// </summary>
[JsonPropertyName(
"url")]
public Uri Url { get; init; }

[JsonPropertyName(
"title")]
public string Title { get; init; }

Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs

View workflow job for this annotation

GitHub Actions / Build

Missing XML comment for publicly visible type or member 'FirecrawlSearchData.Title'

Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs

View workflow job for this annotation

GitHub Actions / Build

Missing XML comment for publicly visible type or member 'FirecrawlSearchData.Title'

Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs

View workflow job for this annotation

GitHub Actions / Build

Missing XML comment for publicly visible type or member 'FirecrawlSearchData.Title'

Check warning on line 21 in source/Firecrawl/FirecrawlSearchData.cs

View workflow job for this annotation

GitHub Actions / Build

Missing XML comment for publicly visible type or member 'FirecrawlSearchData.Title'

/// <summary>
///
/// </summary>
[JsonPropertyName(
"description")]
public string Description { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"html")]
public string Html { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"rawHtml")]
public string HtmlRaw { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"markdown")]
public string Markdown { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"links")]
public ImmutableArray<string> Links { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"screenshot")]
public string Screenshot { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"metadata")]
public FirecrawlSearchDataMetadata Metadata { get; init; }
}
}
56 changes: 56 additions & 0 deletions source/Firecrawl/FirecrawlSearchDataMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Collections;
using System.Collections.Generic;

namespace Firecrawl
{
/// <summary>
///
/// </summary>
public sealed class FirecrawlSearchDataMetadata
{
/// <summary>
///
/// </summary>
[JsonPropertyName(
"title")]
public string Title { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"description")]
public string Description { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"sourceURL")]
public string SourceUrl { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"statusCode")]
public int StatusCode { get; init; }

/// <summary>
///
/// </summary>
[JsonPropertyName(
"error")]
public string ErrorMessage { get; init; }

/// <summary>
///
/// </summary>
[JsonExtensionData]
public Dictionary<string, JsonElement> ExtensionData { get; init; }
}
}
Loading

0 comments on commit 76f8853

Please sign in to comment.