Sha256: 6ff0007e1db443a3762dd8a0a31cedc2b63bac4bf7bd26f3ba75e80f320c7578

Contents?: true

Size: 1.73 KB

Versions: 40

Compression:

Stored size: 1.73 KB

Contents

module Souls
  class Generate < Thor
    desc "mailer [MAILER_NAME]", "Generate Mailer Template in Worker"
    def mailer(class_name)
      mailgun_mailer(class_name: class_name)
    rescue Thor::Error => e
      raise(Thor::Error, e)
    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

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
souls-0.59.1 lib/souls/worker/generate/mailer.rb
souls-0.59.0 lib/souls/worker/generate/mailer.rb
souls-0.58.3 lib/souls/worker/generate/mailer.rb
souls-0.58.2 lib/souls/worker/generate/mailer.rb
souls-0.58.1 lib/souls/worker/generate/mailer.rb
souls-0.58.0 lib/souls/worker/generate/mailer.rb
souls-0.57.1 lib/souls/worker/generate/mailer.rb
souls-0.57.0 lib/souls/worker/generate/mailer.rb
souls-0.56.4 lib/souls/worker/generate/mailer.rb
souls-0.56.3 lib/souls/worker/generate/mailer.rb
souls-0.56.2 lib/souls/worker/generate/mailer.rb
souls-0.56.1 lib/souls/worker/generate/mailer.rb
souls-0.56.0 lib/souls/worker/generate/mailer.rb
souls-0.55.5 lib/souls/worker/generate/mailer.rb
souls-0.55.4 lib/souls/worker/generate/mailer.rb
souls-0.55.3 lib/souls/worker/generate/mailer.rb
souls-0.55.2 lib/souls/worker/generate/mailer.rb
souls-0.55.1 lib/souls/worker/generate/mailer.rb
souls-0.55.0 lib/souls/worker/generate/mailer.rb
souls-0.54.6 lib/souls/worker/generate/mailer.rb