# Ruby

### Installation

Add this line to your application's Gemfile:

```ruby
gem 'promptjoy-ruby'
```

And then execute:

```bash
bundle install
```

Or install it yourself as:

```bash
gem install promptjoy-ruby
```

### Usage

```ruby
require 'promptjoy-ruby'

client = PromptjoyRuby::Client.new('your_api_key')
```

You can find the API you want to interact with by using its URL. You can find the URL in the endpoint field of the API's page:

```ruby
api = client.find_by_api_url('https://api.promptjoy.com/api/id')
```

You can also just find the API by its id:

```ruby
api = client.find('id')
```

To call the API, pass in the data as a Hash:

```ruby
response = api.call({
  key1: 'value1',
  key2: 'value2'
})
```

### Example

The following example uses PromptJoy to build an API that recommends an open-source software package based on a problem to be solved: <https://promptjoy.com/apis/jNqC7A>

```ruby
> require 'promptjoy-ruby'
> client = PromptjoyRuby::Client.new('***********************')
> api = client.find_by_api_url('https://api.promptjoy.com/api/jNqC7A')
> response = api.call({problem: "queue processing in ruby"})
> puts response

{"software"=>"Sidekiq", "reason"=>"Efficient and reliable background processing 
for Ruby", "github_url"=>"https://github.com/mperham/sidekiq"}
```

### Error Handling

If an error occurs during an API call, an instance of PromptjoyRuby::Error is raised with a message indicating the nature of the error.

```ruby
begin
  api.call(some_data)
rescue PromptjoyRuby::Error => e
  puts "An error occurred: #{e.message}"
end
```


---

# 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.promptjoy.com/api/api-usage/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.
