Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ If bundler is not being used to manage dependencies, install the gem by executin

## Requirements

* Ruby 2.6.0 or higher
- Ruby 2.6.0 or higher

## Terms

### BOT

A bot is a tool responsible for executing a specific automation task. The bot's pipeline consists of reading from a shared storage (if required), processing a particular task, and then writing the result to a shared storage.

### Shared Storage

Shared storage is a central location where data can be read and written by multiple bots to facilitate coordination in an automation task. It serves as a common data exchange point, allowing each bot to access information generated by others as needed to complete its specific task. Examples of shared storage include a PostgreSQL database, an S3 bucket, or other types of storage systems that support concurrent access and data persistence.

### Use case

A use case refers to an automation problem larger than what a single bot can manage. It typically involves a set of bots, each solving a specific part of the overall problem independently. To enable these bots to interact, shared storage is used. This shared storage could be a PostgreSQL database, an S3 bucket, or another shared storage type, allowing bots to read and write data that other bots can access to complete their tasks.

## Building my own BOT
Expand All @@ -48,6 +51,7 @@ The `SharedStorage` class abstracts the process of reading from and writing to s
Currently, the gem supports: `PostgreSQL`.

### 2. Bot - Solve a specific automation task

The bot executes the logic required to complete a specific task. For this, an instance of shared storage (for reading and for writing) must be provided to the bot.

The base interface for a bot is available in the `bas/bot/base.rb class`.
Expand All @@ -56,7 +60,7 @@ The base interface for a bot is available in the `bas/bot/base.rb class`.

### Preparing the configurations

The current implementation of the PostgreSQL shared storage expect a table with the following structure:
The current implementation of the PostgreSQL shared storage expect a table with the following structure:

```sql
CREATE TABLE api_data(
Expand All @@ -79,12 +83,14 @@ CREATE TABLE api_data(
In this example, we demonstrate how to configure a bot to fetch data from an API and save it in a postgres database.

For this, a bot could be defined as follow:

```ruby
require 'bas'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use double quotes

require "httparty"

module Bas
module Bot
class FetchFromAPi
class FetchFromAPI < Bas::Bot::Base
URL = 'some-url.com'

def process
Expand Down Expand Up @@ -132,16 +138,16 @@ read_options = {
write_options = {
connection:,
db_table: "api_data",
tag: "FetchFromAPi"
tag: "FetchFromAPI"
}

options = {
token: "api_token"
}

shared_storage = SharedStorage.new(read_options:, write_options:)
shared_storage = Bas::SharedStorage::Postgres.new(read_options:, write_options:)

bot = Bas::Bot::FetchFromAPi.new(options, shared_storage)
bot = Bas::Bot::FetchFromAPI.new(options, shared_storage)
bot.execute
```

Expand Down
4 changes: 4 additions & 0 deletions lib/bas.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

require_relative "bas/version"
require_relative "bas/bot/base"
require_relative "bas/shared_storage/base"
require_relative "bas/shared_storage/default"
require_relative "bas/shared_storage/postgres"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this should be added by default when the gem is imported. Users should have the flexibility to import only the shared storage implementation required for their specific use case. Currently, postgres is the only option available, but in the future, we plan to add more implementations. For example, if a user wants to use shared storage with S3, importing the postgres module should not be enforced.

Let me know what you think! 🤔


module Bas
class Error < StandardError; end
Expand Down