# Ruby

### Requisitos previos

Para poder seguir esta guía, primero necesitarás:

* [Obtener un access\_token de Afip SDK](https://app.afipsdk.com)

### 1. Instalación

Agregá la librería de Afip SDK en Ruby

{% tabs %}
{% tab title="RubyGems" %}

```bash
gem install afip.rb
```

{% endtab %}

{% tab title="Gemfile" %}

```bash
gem 'afip.rb'
```

{% endtab %}
{% endtabs %}

### 2. Crear una instancia de la clase Afip

Para usar los Web Services de ARCA se necesita un certificado digital, pero con Afip SDK podés empezar en modo desarrollo usando el CUIT 20-40937847-2 sin necesidad de uno.

Si preferís [usar tu propio certificado](#usar-tu-propio-certificado-opcional), al final te mostramos cómo.

{% tabs %}
{% tab title="index.rb" %}

```ruby
require "afip"

afip = Afip.new({ 
    "CUIT": 20409378472,
    "access_token": "TU_ACCESS_TOKEN" # Obtenido de https://app.afipsdk.com
})
```

{% endtab %}
{% endtabs %}

### 3. Llamar al método del Web Service que necesites

Con la instancia creada ya podés realizar las llamadas a los Web Services que necesites.

{% content-ref url="/pages/mVTz5YrKc8PCEeJKHt0W" %}
[Web services](/siguientes-pasos/web-services.md)
{% endcontent-ref %}

Si el Web Service que necesitás no se encuentra en la lista de la documentación, podés llamarlo siguiendo esta guía:

{% content-ref url="/pages/4zlCsTNGo99FZGfrhpZn" %}
[Otro web service](/siguientes-pasos/web-services/otro-web-service.md)
{% endcontent-ref %}

Podés usar la referencia de la API para obtener ejemplos de cómo usar los métodos de todos los web services de ARCA.

{% embed url="<https://afipsdk.com/docs/api-reference/introduction/>" %}

También podés usar las guías del blog de Afip SDK para Ruby:

{% embed url="<https://afipsdk.com/blog/category/Ruby/>" %}

***

### Usar tu propio certificado <sup><sub>(Opcional)<sub></sup>

Primero, obtenemos el certificado siguiendo esta guía.

{% embed url="<https://afipsdk.com/blog/como-obtener-certificado-para-web-services-arca/>" fullWidth="false" %}

Y luego lo agregamos a la instancia de la clase Afip.

{% tabs %}
{% tab title="index.rb" %}

<pre class="language-ruby"><code class="lang-ruby">require "afip"

# Certificado (Puede estar guardado en archivos, DB, etc)
cert = File.read("ruta/a/certificado.crt")

# Key (Puede estar guardado en archivos, DB, etc)
key = File.read("ruta/a/key.key")

# CUIT del certificado
tax_id = 20111111112

<strong>afip = Afip.new({
</strong>    "CUIT": tax_id,
    "cert": cert,
    "key": key,
    "access_token": "TU_ACCESS_TOKEN" # Obtenido de https://app.afipsdk.com
))
</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.afipsdk.com/integracion/ruby.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
