Sha256: c833f527ad347e2706a11b7b0e04fbfae334dc05aae123c11eea549aced33d46

Contents?: true

Size: 1.94 KB

Versions: 16

Compression:

Stored size: 1.94 KB

Contents

module Souls
  module Worker
    module Generate
      class << self
        def mailer(class_name: "mailer", option: "")
          if option.to_sym == :sendgrid
            sendgrid_mailer(class_name: class_name)
          else
            mailgun_mailer(class_name: class_name)
          end
        end

        private

        def mailgun_mailer(class_name: "mailer")
          file_dir = "./app/graphql/mutations/"
          FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
          file_path = "#{file_dir}#{class_name.singularize}.rb"
          raise(StandardError, "Mailer already exist! #{file_path}") if File.exist?(file_path)

          File.open(file_path, "w") do |f|
            f.write(<<~TEXT)
              module Mutations
                class #{class_name.camelize} < BaseMutation
                  description "Mail を送信します。"
                  field :response, String, null: false

                  def resolve
                    # First, instantiate the Mailgun Client with your API key
                    mg_client = ::Mailgun::Client.new("YOUR-API-KEY")

                    # Define your message parameters
                    message_params = {
                      from: "postmaster@YOUR-DOMAIN",
                      to: "sending@to.mail.com",
                      subject: "SOULs Mailer test!",
                      text: "It is really easy to send a message!"
                    }

                    # Send your message through the client
                    mg_client.send_message("YOUR-MAILGUN-DOMAIN", message_params)
                    { response: "Job done!" }
                  rescue StandardError => e
                    GraphQL::ExecutionError.new(e.to_s)
                  end
                end
              end
            TEXT
          end
          puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
          file_path
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
souls-0.51.2 lib/souls/worker/generate/mailer.rb
souls-0.51.1 lib/souls/worker/generate/mailer.rb
souls-0.51.0 lib/souls/worker/generate/mailer.rb
souls-0.50.0 lib/souls/worker/generate/mailer.rb
souls-0.49.0 lib/souls/worker/generate/mailer.rb
souls-0.48.2 lib/souls/worker/generate/mailer.rb
souls-0.48.1 lib/souls/worker/generate/mailer.rb
souls-0.48.0 lib/souls/worker/generate/mailer.rb
souls-0.47.1 lib/souls/worker/generate/mailer.rb
souls-0.47.0 lib/souls/worker/generate/mailer.rb
souls-0.46.1 lib/souls/worker/generate/mailer.rb
souls-0.46.0 lib/souls/worker/generate/mailer.rb
souls-0.45.4 lib/souls/worker/generate/mailer.rb
souls-0.45.3 lib/souls/worker/generate/mailer.rb
souls-0.45.2 lib/souls/worker/generate/mailer.rb
souls-0.45.1 lib/souls/worker/generate/mailer.rb