bas 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +6 -0
 - data/lib/bas/bot/fetch_domain_services_from_notion.rb +93 -0
 - data/lib/bas/bot/format_do_bill_alert.rb +2 -2
 - data/lib/bas/bot/review_domain_availability.rb +101 -0
 - data/lib/bas/bot/write_domain_review_requests.rb +104 -0
 - data/lib/bas/utils/notion/request.rb +1 -0
 - data/lib/bas/version.rb +1 -1
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3488575b41bad4918323fc10988339fa6eb121d5923586a416b71f9bb7665d15
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9599e9fea3a5e1f6d283941d8220f2b87a495adf8c1c1d077c4c6a66ef1b7278
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 77439d8970fc20a1d6ad7fddc349252e6e19cbed2f44bf06191c572fb45e951130715bc3285ba1a9a013d8669575260cb97886aa1721b274d2b0078c7c17a9b6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 27df232926e7652eab7d7fddb523aea3542c417f6ac7e2193287c548ee472428f76c31c48deb165a103125a7beb1bd93148458a8a42173406d382c2ea7c69a6f
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,5 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Changelog
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            # 1.3.0 (18.07.2024)
         
     | 
| 
      
 4 
     | 
    
         
            +
            - [Add bots to check webs availability](https://github.com/kommitters/bas/issues/83)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # 1.2.1 (16.07.2024)
         
     | 
| 
      
 7 
     | 
    
         
            +
            - [Update format message for the digital ocean alert bots use case](https://github.com/kommitters/bas/pull/84)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       3 
9 
     | 
    
         
             
            # 1.2.0 (12.07.2024)
         
     | 
| 
       4 
10 
     | 
    
         
             
            - [Add bots to process digital ocean billing checker](https://github.com/kommitters/bas/issues/78)
         
     | 
| 
       5 
11 
     | 
    
         | 
| 
         @@ -0,0 +1,93 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "./base"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "../read/default"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative "../utils/notion/request"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative "../write/postgres"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            module Bot
         
     | 
| 
      
 9 
     | 
    
         
            +
              ##
         
     | 
| 
      
 10 
     | 
    
         
            +
              # The Bot::FetchDomainServicesFromNotion class serves as a bot implementation to read
         
     | 
| 
      
 11 
     | 
    
         
            +
              # web domains from a notion database and write them on a PostgresDB table with a specific format.
         
     | 
| 
      
 12 
     | 
    
         
            +
              #
         
     | 
| 
      
 13 
     | 
    
         
            +
              # <br>
         
     | 
| 
      
 14 
     | 
    
         
            +
              # <b>Example</b>
         
     | 
| 
      
 15 
     | 
    
         
            +
              #
         
     | 
| 
      
 16 
     | 
    
         
            +
              #   options = {
         
     | 
| 
      
 17 
     | 
    
         
            +
              #     process_options: {
         
     | 
| 
      
 18 
     | 
    
         
            +
              #       database_id: "notion database id",
         
     | 
| 
      
 19 
     | 
    
         
            +
              #       secret: "notion secret"
         
     | 
| 
      
 20 
     | 
    
         
            +
              #     },
         
     | 
| 
      
 21 
     | 
    
         
            +
              #     write_options: {
         
     | 
| 
      
 22 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 23 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 24 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 25 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 26 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 27 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 28 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 29 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 30 
     | 
    
         
            +
              #       tag: "FetchDomainServicesFromNotion"
         
     | 
| 
      
 31 
     | 
    
         
            +
              #     }
         
     | 
| 
      
 32 
     | 
    
         
            +
              #   }
         
     | 
| 
      
 33 
     | 
    
         
            +
              #
         
     | 
| 
      
 34 
     | 
    
         
            +
              #   bot = Bot::FetchDomainServicesFromNotion.new(options)
         
     | 
| 
      
 35 
     | 
    
         
            +
              #   bot.execute
         
     | 
| 
      
 36 
     | 
    
         
            +
              #
         
     | 
| 
      
 37 
     | 
    
         
            +
              class FetchDomainServicesFromNotion < Bot::Base
         
     | 
| 
      
 38 
     | 
    
         
            +
                def read
         
     | 
| 
      
 39 
     | 
    
         
            +
                  reader = Read::Default.new
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  reader.execute
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                # Process function to execute the Notion utility to fetch web domains from a notion database
         
     | 
| 
      
 45 
     | 
    
         
            +
                #
         
     | 
| 
      
 46 
     | 
    
         
            +
                def process
         
     | 
| 
      
 47 
     | 
    
         
            +
                  response = Utils::Notion::Request.execute(params)
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  if response.code == 200
         
     | 
| 
      
 50 
     | 
    
         
            +
                    urls_list = normalize_response(response.parsed_response["results"])
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    { success: { urls: urls_list } }
         
     | 
| 
      
 53 
     | 
    
         
            +
                  else
         
     | 
| 
      
 54 
     | 
    
         
            +
                    { error: { message: response.parsed_response, status_code: response.code } }
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                # Write function to execute the PostgresDB write component
         
     | 
| 
      
 59 
     | 
    
         
            +
                #
         
     | 
| 
      
 60 
     | 
    
         
            +
                def write
         
     | 
| 
      
 61 
     | 
    
         
            +
                  write = Write::Postgres.new(write_options, process_response)
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  write.execute
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                private
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                def params
         
     | 
| 
      
 69 
     | 
    
         
            +
                  {
         
     | 
| 
      
 70 
     | 
    
         
            +
                    endpoint: "databases/#{process_options[:database_id]}/query",
         
     | 
| 
      
 71 
     | 
    
         
            +
                    secret: process_options[:secret],
         
     | 
| 
      
 72 
     | 
    
         
            +
                    method: "post",
         
     | 
| 
      
 73 
     | 
    
         
            +
                    body: {}
         
     | 
| 
      
 74 
     | 
    
         
            +
                  }
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                def normalize_response(results)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  return [] if results.nil?
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  results.map do |value|
         
     | 
| 
      
 81 
     | 
    
         
            +
                    properties = value["properties"]
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    {
         
     | 
| 
      
 84 
     | 
    
         
            +
                      "url" => extract_rich_text_field_value(properties["domain"])
         
     | 
| 
      
 85 
     | 
    
         
            +
                    }
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                def extract_rich_text_field_value(data)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  data["rich_text"][0]["plain_text"]
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -93,10 +93,10 @@ module Bot 
     | 
|
| 
       93 
93 
     | 
    
         
             
                  balance = read_response.data["billing"]["month_to_date_balance"]
         
     | 
| 
       94 
94 
     | 
    
         
             
                  threshold = process_options[:threshold]
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
                  """The daily usage was exceeded.
         
     | 
| 
      
 96 
     | 
    
         
            +
                  """:warning: The **DigitalOcean** daily usage was exceeded.
         
     | 
| 
       97 
97 
     | 
    
         
             
                  Current balance: #{balance}
         
     | 
| 
       98 
98 
     | 
    
         
             
                  Threshold: #{threshold}
         
     | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
      
 99 
     | 
    
         
            +
                  Current daily usage: #{daily_usage.round(3)}
         
     | 
| 
       100 
100 
     | 
    
         
             
                  """
         
     | 
| 
       101 
101 
     | 
    
         
             
                end
         
     | 
| 
       102 
102 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,101 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "httparty"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative "./base"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative "../read/postgres"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative "../write/postgres"
         
     | 
| 
      
 8 
     | 
    
         
            +
            require_relative "../utils/openai/run_assistant"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            module Bot
         
     | 
| 
      
 11 
     | 
    
         
            +
              ##
         
     | 
| 
      
 12 
     | 
    
         
            +
              # The Bot::ReviewDomainAvailability class serves as a bot implementation to read from a postgres
         
     | 
| 
      
 13 
     | 
    
         
            +
              # shared storage a domain requests and review its availability.
         
     | 
| 
      
 14 
     | 
    
         
            +
              #
         
     | 
| 
      
 15 
     | 
    
         
            +
              # <br>
         
     | 
| 
      
 16 
     | 
    
         
            +
              # <b>Example</b>
         
     | 
| 
      
 17 
     | 
    
         
            +
              #
         
     | 
| 
      
 18 
     | 
    
         
            +
              #   options = {
         
     | 
| 
      
 19 
     | 
    
         
            +
              #     read_options: {
         
     | 
| 
      
 20 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 21 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 22 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 23 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 24 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 25 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 26 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 27 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 28 
     | 
    
         
            +
              #       tag: "ReviewDomainRequest"
         
     | 
| 
      
 29 
     | 
    
         
            +
              #     },
         
     | 
| 
      
 30 
     | 
    
         
            +
              #     write_options: {
         
     | 
| 
      
 31 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 32 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 33 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 34 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 35 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 36 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 37 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 38 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 39 
     | 
    
         
            +
              #       tag: "ReviewDomainAvailability"
         
     | 
| 
      
 40 
     | 
    
         
            +
              #     }
         
     | 
| 
      
 41 
     | 
    
         
            +
              #   }
         
     | 
| 
      
 42 
     | 
    
         
            +
              #
         
     | 
| 
      
 43 
     | 
    
         
            +
              #   bot = Bot::ReviewDomainAvailability.new(options)
         
     | 
| 
      
 44 
     | 
    
         
            +
              #   bot.execute
         
     | 
| 
      
 45 
     | 
    
         
            +
              #
         
     | 
| 
      
 46 
     | 
    
         
            +
              class ReviewDomainAvailability < Bot::Base
         
     | 
| 
      
 47 
     | 
    
         
            +
                # read function to execute the PostgresDB Read component
         
     | 
| 
      
 48 
     | 
    
         
            +
                #
         
     | 
| 
      
 49 
     | 
    
         
            +
                def read
         
     | 
| 
      
 50 
     | 
    
         
            +
                  reader = Read::Postgres.new(read_options.merge(conditions))
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  reader.execute
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                # process function to make a http request to the domain and check the status
         
     | 
| 
      
 56 
     | 
    
         
            +
                #
         
     | 
| 
      
 57 
     | 
    
         
            +
                def process
         
     | 
| 
      
 58 
     | 
    
         
            +
                  return { success: { review: nil } } if unprocessable_response
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  response = availability
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  if response.code == 200
         
     | 
| 
      
 63 
     | 
    
         
            +
                    { success: { review: nil } }
         
     | 
| 
      
 64 
     | 
    
         
            +
                  else
         
     | 
| 
      
 65 
     | 
    
         
            +
                    { success: { notification: notification(response) } }
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                # write function to execute the PostgresDB write component
         
     | 
| 
      
 70 
     | 
    
         
            +
                #
         
     | 
| 
      
 71 
     | 
    
         
            +
                def write
         
     | 
| 
      
 72 
     | 
    
         
            +
                  write = Write::Postgres.new(write_options, process_response)
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  write.execute
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                private
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                def conditions
         
     | 
| 
      
 80 
     | 
    
         
            +
                  {
         
     | 
| 
      
 81 
     | 
    
         
            +
                    where: "archived=$1 AND tag=$2 AND stage=$3 ORDER BY inserted_at ASC",
         
     | 
| 
      
 82 
     | 
    
         
            +
                    params: [false, read_options[:tag], "unprocessed"]
         
     | 
| 
      
 83 
     | 
    
         
            +
                  }
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                def availability
         
     | 
| 
      
 87 
     | 
    
         
            +
                  url = read_response.data["url"]
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  HTTParty.get(url, {})
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                def notification(response)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  data = {
         
     | 
| 
      
 94 
     | 
    
         
            +
                    domain: read_response.data["url"],
         
     | 
| 
      
 95 
     | 
    
         
            +
                    status_code: response.code
         
     | 
| 
      
 96 
     | 
    
         
            +
                  }
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                  ":warning: Domain is down: #{data}"
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
              end
         
     | 
| 
      
 101 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,104 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "./base"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "../read/postgres"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative "../utils/notion/update_db_state"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative "../write/postgres"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            module Bot
         
     | 
| 
      
 9 
     | 
    
         
            +
              ##
         
     | 
| 
      
 10 
     | 
    
         
            +
              # The Bot::WriteDomainReviewRequests class serves as a bot implementation to read from a postgres
         
     | 
| 
      
 11 
     | 
    
         
            +
              # shared storage a set of review domain requests and create single request on the shared storage to
         
     | 
| 
      
 12 
     | 
    
         
            +
              # be processed one by one.
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              # <br>
         
     | 
| 
      
 15 
     | 
    
         
            +
              # <b>Example</b>
         
     | 
| 
      
 16 
     | 
    
         
            +
              #
         
     | 
| 
      
 17 
     | 
    
         
            +
              #   options = {
         
     | 
| 
      
 18 
     | 
    
         
            +
              #     read_options: {
         
     | 
| 
      
 19 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 20 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 21 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 22 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 23 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 24 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 25 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 26 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 27 
     | 
    
         
            +
              #       tag: "FetchDomainServicesFromNotion"
         
     | 
| 
      
 28 
     | 
    
         
            +
              #     },
         
     | 
| 
      
 29 
     | 
    
         
            +
              #     process_options: {
         
     | 
| 
      
 30 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 31 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 32 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 33 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 34 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 35 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 36 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 37 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 38 
     | 
    
         
            +
              #       tag: "ReviewDomainRequest"
         
     | 
| 
      
 39 
     | 
    
         
            +
              #     },
         
     | 
| 
      
 40 
     | 
    
         
            +
              #     write_options: {
         
     | 
| 
      
 41 
     | 
    
         
            +
              #       connection: {
         
     | 
| 
      
 42 
     | 
    
         
            +
              #         host: "localhost",
         
     | 
| 
      
 43 
     | 
    
         
            +
              #         port: 5432,
         
     | 
| 
      
 44 
     | 
    
         
            +
              #         dbname: "bas",
         
     | 
| 
      
 45 
     | 
    
         
            +
              #         user: "postgres",
         
     | 
| 
      
 46 
     | 
    
         
            +
              #         password: "postgres"
         
     | 
| 
      
 47 
     | 
    
         
            +
              #       },
         
     | 
| 
      
 48 
     | 
    
         
            +
              #       db_table: "web_availability",
         
     | 
| 
      
 49 
     | 
    
         
            +
              #       tag: "WriteDomainReviewRequests"
         
     | 
| 
      
 50 
     | 
    
         
            +
              #     }
         
     | 
| 
      
 51 
     | 
    
         
            +
              #   }
         
     | 
| 
      
 52 
     | 
    
         
            +
              #
         
     | 
| 
      
 53 
     | 
    
         
            +
              #   bot = Bot::WriteDomainReviewRequests.new(options)
         
     | 
| 
      
 54 
     | 
    
         
            +
              #   bot.execute
         
     | 
| 
      
 55 
     | 
    
         
            +
              #
         
     | 
| 
      
 56 
     | 
    
         
            +
              class WriteDomainReviewRequests < Bot::Base
         
     | 
| 
      
 57 
     | 
    
         
            +
                # read function to execute the PostgresDB Read component
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                def read
         
     | 
| 
      
 60 
     | 
    
         
            +
                  reader = Read::Postgres.new(read_options.merge(conditions))
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  reader.execute
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                # Process function to execute the Notion utility create single review requests
         
     | 
| 
      
 66 
     | 
    
         
            +
                #
         
     | 
| 
      
 67 
     | 
    
         
            +
                def process
         
     | 
| 
      
 68 
     | 
    
         
            +
                  return { success: { created: nil } } if unprocessable_response
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  read_response.data["urls"].each { |request| create_request(request) }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  { success: { created: true } }
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                # Write function to execute the PostgresDB write component
         
     | 
| 
      
 76 
     | 
    
         
            +
                #
         
     | 
| 
      
 77 
     | 
    
         
            +
                def write
         
     | 
| 
      
 78 
     | 
    
         
            +
                  write = Write::Postgres.new(write_options, process_response)
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  write.execute
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                private
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                def conditions
         
     | 
| 
      
 86 
     | 
    
         
            +
                  {
         
     | 
| 
      
 87 
     | 
    
         
            +
                    where: "archived=$1 AND tag=$2 AND stage=$3 ORDER BY inserted_at ASC",
         
     | 
| 
      
 88 
     | 
    
         
            +
                    params: [false, read_options[:tag], "unprocessed"]
         
     | 
| 
      
 89 
     | 
    
         
            +
                  }
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                def create_request(request)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  write_data = write_request(request)
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  Write::Postgres.new(process_options, write_data).execute
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                def write_request(request)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  return { error: request } if request["url"].empty? || !request["error"].nil?
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                  { success: request }
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
              end
         
     | 
| 
      
 104 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/bas/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bas
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - kommitters Open Source
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-07-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: gmail_xoauth
         
     | 
| 
         @@ -189,6 +189,7 @@ files: 
     | 
|
| 
       189 
189 
     | 
    
         
             
            - lib/bas/bot/compare_wip_limit_count.rb
         
     | 
| 
       190 
190 
     | 
    
         
             
            - lib/bas/bot/fetch_billing_from_digital_ocean.rb
         
     | 
| 
       191 
191 
     | 
    
         
             
            - lib/bas/bot/fetch_birthdays_from_notion.rb
         
     | 
| 
      
 192 
     | 
    
         
            +
            - lib/bas/bot/fetch_domain_services_from_notion.rb
         
     | 
| 
       192 
193 
     | 
    
         
             
            - lib/bas/bot/fetch_domains_wip_counts_from_notion.rb
         
     | 
| 
       193 
194 
     | 
    
         
             
            - lib/bas/bot/fetch_domains_wip_limit_from_notion.rb
         
     | 
| 
       194 
195 
     | 
    
         
             
            - lib/bas/bot/fetch_emails_from_imap.rb
         
     | 
| 
         @@ -204,8 +205,10 @@ files: 
     | 
|
| 
       204 
205 
     | 
    
         
             
            - lib/bas/bot/humanize_pto.rb
         
     | 
| 
       205 
206 
     | 
    
         
             
            - lib/bas/bot/notify_discord.rb
         
     | 
| 
       206 
207 
     | 
    
         
             
            - lib/bas/bot/notify_do_bill_alert_email.rb
         
     | 
| 
      
 208 
     | 
    
         
            +
            - lib/bas/bot/review_domain_availability.rb
         
     | 
| 
       207 
209 
     | 
    
         
             
            - lib/bas/bot/review_media.rb
         
     | 
| 
       208 
210 
     | 
    
         
             
            - lib/bas/bot/update_review_media_state.rb
         
     | 
| 
      
 211 
     | 
    
         
            +
            - lib/bas/bot/write_domain_review_requests.rb
         
     | 
| 
       209 
212 
     | 
    
         
             
            - lib/bas/bot/write_media_review_in_notion.rb
         
     | 
| 
       210 
213 
     | 
    
         
             
            - lib/bas/bot/write_media_review_requests.rb
         
     | 
| 
       211 
214 
     | 
    
         
             
            - lib/bas/read/base.rb
         
     |