From d33a965e5577da5095b34404d3db7d5e728b8ca8 Mon Sep 17 00:00:00 2001 From: Eleazar Meza Date: Mon, 18 Nov 2024 17:41:28 -0400 Subject: [PATCH 1/2] Add require_relative to expose bot and shared storage classes --- lib/bas.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bas.rb b/lib/bas.rb index 4c6e37a..c1f4091 100644 --- a/lib/bas.rb +++ b/lib/bas.rb @@ -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" module Bas class Error < StandardError; end From 6fae26cdfa01ca47d0c0a3326728a37399959630 Mon Sep 17 00:00:00 2001 From: jimmygm16 Date: Mon, 18 Nov 2024 17:12:12 -0500 Subject: [PATCH 2/2] Update README --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 925667b..1abd6c1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`. @@ -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( @@ -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' require "httparty" module Bas module Bot - class FetchFromAPi + class FetchFromAPI < Bas::Bot::Base URL = 'some-url.com' def process @@ -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 ```