Sha256: 1eb87a09e7b0d42d5d3389a088ff19c567d0f2db2f8ce16d7c04d1dbdacaca8a

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'ehbrs_ruby_utils/bga/session'
require 'ehbrs_ruby_utils/executables'
require 'ehbrs_ruby_utils/mudslide/message'
require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Gjt1
    class Manager
      include ::Singleton
      acts_as_abstract :bga_usernam, :bga_password, :whatsapp_recipient

      # @param table [EhbrsRubyUtils::Bga::Table]
      # @return [void]
      def bga_table_notify(table)
        formatter = ::EhbrsRubyUtils::Bga::TableWhatsappFormatter.new(table)
        whatsapp_send(formatter.to_s, formatter.image_local_path)
      end

      def on_bga_logged_session(&block)
        bga_session = new_bga_session
        begin
          bga_session.on_logged { block.call(bga_session) }
        ensure
          bga_session.close
          bga_session = nil
        end
      end

      # @return [EhbrsRubyUtils::Bga::Session] Cria uma nova sessão BGA.
      def new_bga_session
        ::EhbrsRubyUtils::Bga::Session.new(bga_username, bga_password)
      end

      # @param message [String]
      # @param image_path [Pathname]
      # @return [void]
      def whatsapp_send(message, image_path = nil)
        ::EhbrsRubyUtils::Mudslide::Message.new.text(message).image_path(image_path)
          .recipient(whatsapp_recipient).deliver
      end

      private

      def mudslide_run(*args)
        ::EhbrsRubyUtils::Executables.mudslide.command(*args).system!
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/gjt1/manager.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/gjt1/manager.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/gjt1/manager.rb