> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yasmina.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Ruby

# Yasminaai Ruby Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github\&utm_medium=github\&utm_campaign=readme\&utm_source=https%3A%2F%2Fgithub.com%2FYasminaAI%2Fmotor-ruby-sdk)

The Yasminaai Ruby library provides convenient access to the Yasminaai APIs from Ruby.

## Table of Contents

* [Reference](#reference)
* [Usage](#usage)
* [Environments](#environments)
* [Errors](#errors)
* [Advanced](#advanced)
  * [Retries](#retries)
  * [Timeouts](#timeouts)
  * [Additional Headers](#additional-headers)
  * [Additional Query Parameters](#additional-query-parameters)
* [Contributing](#contributing)

## Reference

A full reference for this library is available [here](https://github.com/YasminaAI/motor-ruby-sdk/blob/HEAD/./reference.md).

## Usage

Instantiate and use the client with the following:

```ruby theme={null}
require "yasminaai"

client = Yasminaai::Client.new(token: "<token>")

client.quotes.request_quotes(
  otp: "123456",
  owner_id: "owner_id",
  phone: "phone",
  birthdate: "2023-01-15",
  car_estimated_cost: 1.1
)
```

## Environments

This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.

### Environments

```ruby theme={null}
require "yasminaai"

yasminaai = Yasminaai::Client.new(
    base_url: Yasminaai::Environment::SANDBOX
)
```

### Custom URL

```ruby theme={null}
require "yasminaai"

client = Yasminaai::Client.new(
    base_url: "https://example.com"
)
```

## Errors

Failed API calls will raise errors that can be rescued from granularly.

```ruby theme={null}
require "yasminaai"

client = Yasminaai::Client.new(
    base_url: "https://example.com"
)

begin
    result = client.quotes.request_quotes
rescue Yasminaai::Errors::TimeoutError
    puts "API didn't respond before our timeout elapsed"
rescue Yasminaai::Errors::ServiceUnavailableError
    puts "API returned status 503, is probably overloaded, try again later"
rescue Yasminaai::Errors::ServerError
    puts "API returned some other 5xx status, this is probably a bug"
rescue Yasminaai::Errors::ResponseError => e
    puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
rescue Yasminaai::Errors::ApiError => e
    puts "Some other error occurred when calling the API: #{e.message}"
end
```

## Advanced

### Retries

The SDK is instrumented with automatic retries. 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).

A request is deemed retryable when any of the following HTTP status codes is returned:

* [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
* [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
* [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)

The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:

* `legacy` (default): Retries `408`, `429`, `500`, `502`, `503`, `504`, `521`, `522`, `524`
* `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)

Use the `max_retries` option to configure this behavior.

```ruby theme={null}
require "yasminaai"

client = Yasminaai::Client.new(
    base_url: "https://example.com",
    max_retries: 3  # Configure max retries (default is 2)
)
```

### Timeouts

The SDK defaults to a 60 second timeout. Use the `timeout` option to configure this behavior.

```ruby theme={null}
require "yasminaai"

response = client.quotes.request_quotes(
    ...,
    timeout: 30  # 30 second timeout
)
```

### Additional Headers

If you would like to send additional headers as part of the request, use the `additional_headers` request option.

```ruby theme={null}
require "yasminaai"

response = client.quotes.request_quotes(
    ...,
    request_options: {
        additional_headers: {
            "X-Custom-Header" => "custom-value"
        }
    }
)
```

### Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the `additional_query_parameters` request option.

```ruby theme={null}
require "yasminaai"

response = client.quotes.request_quotes(
    ...,
    request_options: {
        additional_query_parameters: {
            "custom_param" => "custom-value"
        }
    }
)
```

## 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!
