Skip to main content

Yasminaai C# Library

fern shield nuget shield The Yasminaai C# library provides convenient access to the Yasminaai APIs from C#.

Table of Contents

Requirements

This SDK requires:

Installation

dotnet add package Yasmina.Motor.DotNet

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:
using YasminaaiApi;

var client = new YasminaaiApiClient("TOKEN");
await client.Quotes.RequestQuotesAsync(
    new PostQuoteRequestsRequest
    {
        Otp = "123456",
        OwnerId = "owner_id",
        Phone = "phone",
        Birthdate = new DateOnly(2023, 1, 15),
        CarEstimatedCost = 1.1,
    }
);

Environments

This SDK allows you to configure different environments for API requests.
using YasminaaiApi;

var client = new YasminaaiApiClient(new ClientOptions
{
    BaseUrl = YasminaaiApiEnvironment.Sandbox
});

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
using YasminaaiApi;

try {
    var response = await client.Quotes.RequestQuotesAsync(...);
} catch (YasminaaiApiApiException e) {
    System.Console.WriteLine(e.Body);
    System.Console.WriteLine(e.StatusCode);

    // Access the raw HTTP response (status code, URL, headers) off the exception
    var rawResponse = e.RawResponse;
    if (rawResponse != null)
    {
        System.Console.WriteLine(rawResponse.Url);
        if (rawResponse.Headers.TryGetValue("X-Request-Id", out var requestId))
        {
            System.Console.WriteLine($"Request ID: {requestId}");
        }
    }
}

Advanced

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2). Which status codes are retried depends on the retryStatusCodes generator configuration: legacy (current default): retries on
  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (All server errors, including 500)
recommended: retries on
  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 502 (Bad Gateway)
  • 503 (Service Unavailable)
  • 504 (Gateway Timeout)
Use the MaxRetries request option to configure this behavior.
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        MaxRetries: 0 // Override MaxRetries at the request level
    }
);

Timeouts

The SDK defaults to a 30 second timeout. Use the Timeout option to configure this behavior.
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        Timeout: TimeSpan.FromSeconds(3) // Override timeout to 3s
    }
);

Raw Response

Access raw HTTP response data (status code, headers, URL) alongside parsed response data using the .WithRawResponse() method.
using YasminaaiApi;

// Access raw response data (status code, headers, etc.) alongside the parsed response
var result = await client.Quotes.RequestQuotesAsync(...).WithRawResponse();

// Access the parsed data
var data = result.Data;

// Access raw response metadata
var statusCode = result.RawResponse.StatusCode;
var headers = result.RawResponse.Headers;
var url = result.RawResponse.Url;

// Access specific headers (case-insensitive)
if (headers.TryGetValue("X-Request-Id", out var requestId))
{
    System.Console.WriteLine($"Request ID: {requestId}");
}

// For the default behavior, simply await without .WithRawResponse()
var data = await client.Quotes.RequestQuotesAsync(...);

// .WithRawResponse() also works on streaming endpoints (returns IAsyncEnumerable<T> + RawResponse)
// and on endpoints with no response body (returns RawResponse only).

Additional Headers

If you would like to send additional headers as part of the request, use the AdditionalHeaders request option.
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        AdditionalHeaders = new Dictionary<string, string?>
        {
            { "X-Custom-Header", "custom-value" }
        }
    }
);

Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the AdditionalQueryParameters request option.
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        AdditionalQueryParameters = new Dictionary<string, string>
        {
            { "custom_param", "custom-value" }
        }
    }
);

Forward Compatible Enums

This SDK uses forward-compatible enums that can handle unknown values gracefully.
using YasminaaiApi;

// Using a built-in value
var postQuoteRequestsRequestAcceptLanguage = PostQuoteRequestsRequestAcceptLanguage.Ar;

// Using a custom value
var customPostQuoteRequestsRequestAcceptLanguage = PostQuoteRequestsRequestAcceptLanguage.FromCustom("custom-value");

// Using in a switch statement
switch (postQuoteRequestsRequestAcceptLanguage.Value)
{
    case PostQuoteRequestsRequestAcceptLanguage.Values.Ar:
        Console.WriteLine("Ar");
        break;
    default:
        Console.WriteLine($"Unknown value: {postQuoteRequestsRequestAcceptLanguage.Value}");
        break;
}

// Explicit casting
string postQuoteRequestsRequestAcceptLanguageString = (string)PostQuoteRequestsRequestAcceptLanguage.Ar;
PostQuoteRequestsRequestAcceptLanguage postQuoteRequestsRequestAcceptLanguageFromString = (PostQuoteRequestsRequestAcceptLanguage)"ar";

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us! On the other hand, contributions to the README are always very welcome!