visit_widget_email 0.7.14
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 +7 -0
- data/README.md +70 -0
- data/Rakefile +33 -0
- data/app/helpers/visit_widget_email/mailer_helper.rb +78 -0
- data/app/mailers/visit_widget_email/mailer.rb +5 -0
- data/app/mailers/visit_widget_email/mailer_defaults.rb +19 -0
- data/app/views/layouts/visit_widget_email/email.html.erb +86 -0
- data/app/views/layouts/visit_widget_email/images/apple_app_store_logo_de.png +0 -0
- data/app/views/layouts/visit_widget_email/images/apple_app_store_logo_en.png +0 -0
- data/app/views/layouts/visit_widget_email/images/apple_app_store_logo_es.png +0 -0
- data/app/views/layouts/visit_widget_email/images/apple_app_store_logo_fr.png +0 -0
- data/app/views/layouts/visit_widget_email/images/apple_app_store_logo_zn-CH.png +0 -0
- data/app/views/layouts/visit_widget_email/images/google_app_store_logo_de.png +0 -0
- data/app/views/layouts/visit_widget_email/images/google_app_store_logo_en.png +0 -0
- data/app/views/layouts/visit_widget_email/images/google_app_store_logo_es.png +0 -0
- data/app/views/layouts/visit_widget_email/images/google_app_store_logo_fr.png +0 -0
- data/app/views/layouts/visit_widget_email/images/google_app_store_logo_zn-CH.png +0 -0
- data/config/locales/de.yml +5 -0
- data/config/locales/en-GB.yml +4 -0
- data/config/locales/en.yml +4 -0
- data/config/locales/es.yml +4 -0
- data/config/locales/fr.yml +4 -0
- data/config/locales/it.yml +4 -0
- data/config/locales/nl.yml +4 -0
- data/config/locales/pt-BR.yml +4 -0
- data/config/locales/zh-CN.yml +4 -0
- data/lib/tasks/visit_widget_mailer_tasks.rake +4 -0
- data/lib/visit_widget_email/commands/send_dynamic_template_email.rb +75 -0
- data/lib/visit_widget_email/commands/send_email.rb +30 -0
- data/lib/visit_widget_email/email_params.rb +12 -0
- data/lib/visit_widget_email/engine.rb +4 -0
- data/lib/visit_widget_email/settings.rb +15 -0
- data/lib/visit_widget_email/version.rb +3 -0
- data/lib/visit_widget_email.rb +9 -0
- metadata +106 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 91d0baeed3fc442f160e0f82fd051b0e21f7b66f14d25f8d9b113dfdfeaa154a
         | 
| 4 | 
            +
              data.tar.gz: df5b79d1c3f59b1f1d5a1ed4171bfa4c03157c0b9286209e402a6aba14ce88f5
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 1ae9d37e5b4d4f6a6a7434f1ff61a63a4f00038cd31d3a945e2522455b670e8159cd57603008fce3f27f7c8504d85f579a7122725d80b2a965660fef52e32dda
         | 
| 7 | 
            +
              data.tar.gz: d87a24333af7d4177a495eb4f6eed296466b7be766feaa33fc192f678b91bc0ef15eb6f1ccfcba701133e664a691eec377e4d8ea1e1673c156d0d9ecc4649eb2
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,70 @@ | |
| 1 | 
            +
            # VisitWidgetMailer
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Short description and motivation.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Usage
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            How to use my plugin.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ## Installation
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Add this line to your application's Gemfile:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ```ruby
         | 
| 14 | 
            +
            gem 'visit_widget_email'
         | 
| 15 | 
            +
            ```
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            And then execute:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ```bash
         | 
| 20 | 
            +
            $ bundle
         | 
| 21 | 
            +
            ```
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            Or install it yourself as:
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ```bash
         | 
| 26 | 
            +
            $ gem install visit_widget_email
         | 
| 27 | 
            +
            ```
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ## Usage
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            ### Command and Query
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            `VisitWidgetEmail::Commands::SendEmail` is the command used to send emails
         | 
| 34 | 
            +
            anywhere in the app. The constructor takes these params:
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            `mailer_class_name, mailer_action, client_id, params`
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            Where params are the custom parameters for that particular mailer.
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            For the command to work, you'll need to implement the
         | 
| 41 | 
            +
            `VisitWidgetEmail::Queries::GetEmailParamsFromClient` class. This query should
         | 
| 42 | 
            +
            have an `execute` method that takes in the client id and returns a
         | 
| 43 | 
            +
            VisitWidgetEmail::EmailParams object with these attributes set:
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            - primary_color
         | 
| 46 | 
            +
            - host
         | 
| 47 | 
            +
            - logo_url
         | 
| 48 | 
            +
            - client_name
         | 
| 49 | 
            +
            - enable_email_links
         | 
| 50 | 
            +
            - ios_itunes_app_id
         | 
| 51 | 
            +
            - android_bundle_identifier
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            ### Mailers
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            You'll want to have your `ApplicationMailer` inherit from `VisitWidgetEmail::Mailer`:
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            ```ruby
         | 
| 58 | 
            +
            class ApplicationMailer < VisitWidgetEmail::Mailer
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
            ```
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            Your mailer methods should have `email_params` as the first parameter.
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            ## Contributing
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            Contribution directions go here.
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ## License
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            begin
         | 
| 2 | 
            +
              require 'bundler/setup'
         | 
| 3 | 
            +
            rescue LoadError
         | 
| 4 | 
            +
              puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
         | 
| 5 | 
            +
            end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            require 'rdoc/task'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            RDoc::Task.new(:rdoc) do |rdoc|
         | 
| 10 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 11 | 
            +
              rdoc.title    = 'VisitWidgetEmail'
         | 
| 12 | 
            +
              rdoc.options << '--line-numbers'
         | 
| 13 | 
            +
              rdoc.rdoc_files.include('README.md')
         | 
| 14 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
         | 
| 18 | 
            +
            load 'rails/tasks/engine.rake'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            load 'rails/tasks/statistics.rake'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            require 'bundler/gem_tasks'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            require 'rake/testtask'
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            Rake::TestTask.new(:test) do |t|
         | 
| 27 | 
            +
              t.libs << 'test'
         | 
| 28 | 
            +
              t.pattern = 'test/**/*_test.rb'
         | 
| 29 | 
            +
              t.verbose = false
         | 
| 30 | 
            +
              t.warning = false
         | 
| 31 | 
            +
            end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            task default: :test
         | 
| @@ -0,0 +1,78 @@ | |
| 1 | 
            +
            module VisitWidgetEmail
         | 
| 2 | 
            +
              module MailerHelper
         | 
| 3 | 
            +
                def primary_button(url, text, color, width=180)
         | 
| 4 | 
            +
                  html = '<a href="' + url + '"
         | 
| 5 | 
            +
                      style="width: ' + width.to_s + 'px;
         | 
| 6 | 
            +
                      display: block;
         | 
| 7 | 
            +
                      height: 40px;
         | 
| 8 | 
            +
                      margin: 0 auto 0 auto;
         | 
| 9 | 
            +
                      margin-top: 20px;
         | 
| 10 | 
            +
                      border-radius: 5px;
         | 
| 11 | 
            +
                      text-decoration: none;
         | 
| 12 | 
            +
                      background-color: ' + color + ';">
         | 
| 13 | 
            +
                          <span 
         | 
| 14 | 
            +
                          style="display: block;
         | 
| 15 | 
            +
                          text-align: center;
         | 
| 16 | 
            +
                          color: white;
         | 
| 17 | 
            +
                          padding-top: 12px;
         | 
| 18 | 
            +
                          font-family: ''open sans'', helvetica, arial, sans-serif;"
         | 
| 19 | 
            +
                          >' +
         | 
| 20 | 
            +
                            text +
         | 
| 21 | 
            +
                         '</span>' +
         | 
| 22 | 
            +
                      '</a>'     
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                  return html.html_safe
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                def title(&block)
         | 
| 28 | 
            +
                  html = '<p style="font-size: 120%; text-align: center;"><strong>' +
         | 
| 29 | 
            +
                    + capture(&block) + '</strong></p>'
         | 
| 30 | 
            +
                    
         | 
| 31 | 
            +
                  html.html_safe
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
                
         | 
| 34 | 
            +
                def primary_content(&block)
         | 
| 35 | 
            +
                  html = 
         | 
| 36 | 
            +
                    '<div style="border: 1px solid #656A71; 
         | 
| 37 | 
            +
                    width: 90%; 
         | 
| 38 | 
            +
                    margin: 0 auto 0 auto; 
         | 
| 39 | 
            +
                    background-color: white; 
         | 
| 40 | 
            +
                    -webkit-box-shadow: 0px 0px 6px 0px rgba(50, 50, 50, 0.2);
         | 
| 41 | 
            +
                    -moz-box-shadow: 0px 0px 6px 0px rgba(50, 50, 50, 0.2);
         | 
| 42 | 
            +
                    box-shadow: 0px 0px 6px 0px rgba(50, 50, 50, 0.2);">' + 
         | 
| 43 | 
            +
                    capture(&block) + '</div>'
         | 
| 44 | 
            +
                  
         | 
| 45 | 
            +
                  html.html_safe
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
                
         | 
| 48 | 
            +
                def message(&block)
         | 
| 49 | 
            +
                  html =
         | 
| 50 | 
            +
                    '<div class="message" 
         | 
| 51 | 
            +
                  	      style="text-align: center; 
         | 
| 52 | 
            +
                  	             font-family: ''open sans'', helvetica, arial, sans-serif; 
         | 
| 53 | 
            +
                  	             font-weight: 100; 
         | 
| 54 | 
            +
                  	             color: #656A71; 
         | 
| 55 | 
            +
                                 margin-top: 16px;
         | 
| 56 | 
            +
                                 margin-bottom: 16px;
         | 
| 57 | 
            +
                                 padding-left: 10px; 
         | 
| 58 | 
            +
                                 padding-right: 10px;">' + 
         | 
| 59 | 
            +
                    capture(&block) + '</div>'
         | 
| 60 | 
            +
                  
         | 
| 61 | 
            +
                  html.html_safe
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
                
         | 
| 64 | 
            +
                def message_with_centered_text_and_left_justified(&block)
         | 
| 65 | 
            +
                  html =
         | 
| 66 | 
            +
                    '<div style="text-align: center;">
         | 
| 67 | 
            +
                      <div class="message" 
         | 
| 68 | 
            +
                       style="font-family: ''open sans'', helvetica, arial, sans-serif; 
         | 
| 69 | 
            +
                       font-weight: 100; 
         | 
| 70 | 
            +
                       color: #656A71; padding-left: 10px; padding-right: 10px;
         | 
| 71 | 
            +
                       display: inline-block; text-align: left;">' + 
         | 
| 72 | 
            +
                        capture(&block) + '</div></div><br />'
         | 
| 73 | 
            +
                  
         | 
| 74 | 
            +
                  html.html_safe
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module VisitWidgetEmail
         | 
| 2 | 
            +
              module MailerDefaults
         | 
| 3 | 
            +
                extend ActiveSupport::Concern 
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  helper "visit_widget_email/mailer"
         | 
| 7 | 
            +
                  layout 'layouts/visit_widget_email/email' 
         | 
| 8 | 
            +
                  before_action :set_sendgrid_header
         | 
| 9 | 
            +
                  default from: Proc.new { 
         | 
| 10 | 
            +
                    VisitWidgetEmail::Settings.no_reply_email_address(@email_params) 
         | 
| 11 | 
            +
                  }
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def set_sendgrid_header
         | 
| 15 | 
            +
                  headers['X-SMTPAPI'] = '{"asm_group_id": "' + 
         | 
| 16 | 
            +
                    ENV["SENDGRID_ALL_UNSUBSCRIBE_GROUP_ID"].to_s + '"}'
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            <!DOCTYPE html>
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
         | 
| 5 | 
            +
              </head>
         | 
| 6 | 
            +
            	<body>
         | 
| 7 | 
            +
            		<div style="background-color: #F7F7F7">
         | 
| 8 | 
            +
            			<div class="header" 
         | 
| 9 | 
            +
            			style="width: 100%; 
         | 
| 10 | 
            +
            			background-color: <%= @email_params.primary_color %>; 
         | 
| 11 | 
            +
            			height: 50px;"
         | 
| 12 | 
            +
            			>
         | 
| 13 | 
            +
            		    <%= link_to root_url(host: @email_params.host) do %>
         | 
| 14 | 
            +
            				  <img src="<%= @email_params.logo_url  %>" 
         | 
| 15 | 
            +
                        style="display: block; margin: 0 auto 0 auto;" />
         | 
| 16 | 
            +
            		    <% end %>
         | 
| 17 | 
            +
            			</div>
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            		  <%= yield %>
         | 
| 20 | 
            +
            			<% if @email_params.enable_email_links %>
         | 
| 21 | 
            +
            				<p style="text-align: center;">
         | 
| 22 | 
            +
            					<strong>
         | 
| 23 | 
            +
            						<%= t("email.get_mobile_app_line", 
         | 
| 24 | 
            +
                          client_name: @email_params.client_name) %>
         | 
| 25 | 
            +
            					</strong> 
         | 
| 26 | 
            +
            				</p>
         | 
| 27 | 
            +
            				<table style="margin-left: auto; margin-right: auto; 
         | 
| 28 | 
            +
                    border-collapse: collapse;">
         | 
| 29 | 
            +
                      <tr>
         | 
| 30 | 
            +
                        <% if @email_params.ios_itunes_app_id.present? %>
         | 
| 31 | 
            +
                          <td style="padding: 0; margin: 0;">
         | 
| 32 | 
            +
                            <a href="<%= "https://itunes.apple.com/us/app/id#{@email_params.ios_itunes_app_id}" %>">
         | 
| 33 | 
            +
                              <% apple_logo_file_name = 
         | 
| 34 | 
            +
                                "apple_app_store_logo_#{I18n.locale}.png" %>
         | 
| 35 | 
            +
                              <% attachments.inline[apple_logo_file_name] =
         | 
| 36 | 
            +
                                File.read(
         | 
| 37 | 
            +
                                  File.expand_path("images/#{apple_logo_file_name}", 
         | 
| 38 | 
            +
                                    __dir__)
         | 
| 39 | 
            +
                                )
         | 
| 40 | 
            +
                              %>
         | 
| 41 | 
            +
                              <%= image_tag attachments[apple_logo_file_name].url, 
         | 
| 42 | 
            +
                                style: "width: 168px; height: 50px; margin-right: 8px;" %>
         | 
| 43 | 
            +
                            </a>
         | 
| 44 | 
            +
                          </td>
         | 
| 45 | 
            +
                        <% end %>
         | 
| 46 | 
            +
                        <% if @email_params.android_bundle_identifier.present? %>
         | 
| 47 | 
            +
                          <td style="padding: 0; margin: 0;">
         | 
| 48 | 
            +
                            <a href="<%= 
         | 
| 49 | 
            +
                              "http://play.google.com/store/apps/details?id="\
         | 
| 50 | 
            +
                              "#{@email_params.android_bundle_identifier}" %>">
         | 
| 51 | 
            +
                              <% google_logo_file_name = 
         | 
| 52 | 
            +
                                "google_app_store_logo_#{I18n.locale}.png" %>
         | 
| 53 | 
            +
                              <% attachments.inline[google_logo_file_name] =
         | 
| 54 | 
            +
                                File.read(
         | 
| 55 | 
            +
                                  File.expand_path("images/#{google_logo_file_name}", 
         | 
| 56 | 
            +
                                    __dir__)
         | 
| 57 | 
            +
                                )
         | 
| 58 | 
            +
                              %>
         | 
| 59 | 
            +
                              <%= image_tag attachments[google_logo_file_name].url, 
         | 
| 60 | 
            +
                                style: "width: 168px; height: 50px;" %>
         | 
| 61 | 
            +
                            </a>
         | 
| 62 | 
            +
                          </td>
         | 
| 63 | 
            +
                        <% end %>
         | 
| 64 | 
            +
                      </tr>
         | 
| 65 | 
            +
            				</table>
         | 
| 66 | 
            +
            			<% end %>
         | 
| 67 | 
            +
            		</div>
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            		<div style="margin-top: 50px; border-top: 1px solid #D3D3D3; 
         | 
| 70 | 
            +
                background-color: white;">
         | 
| 71 | 
            +
            			<div class="footer_container" style="width: 90%;">
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            				<p class="unsuscribe" style="text-decoration: none; color: #656A71; 
         | 
| 74 | 
            +
                    font-family: 'open sans', helvetica, arial, sans-serif; 
         | 
| 75 | 
            +
                    font-size: 14px; font-weight: 100;"> 
         | 
| 76 | 
            +
                      <%%asm_preferences_url%>
         | 
| 77 | 
            +
            			  </p>
         | 
| 78 | 
            +
            				<p class="copywrite" style="text-decoration: none; color: #656A71;
         | 
| 79 | 
            +
                    font-family: 'open sans', helvetica, arial, sans-serif;
         | 
| 80 | 
            +
                    font-size: 14px; font-weight: 100;"> 
         | 
| 81 | 
            +
            		      <%= t("email.copyright_notice") %>
         | 
| 82 | 
            +
                    </p>
         | 
| 83 | 
            +
            		 	</div>
         | 
| 84 | 
            +
            		</div>
         | 
| 85 | 
            +
            	</body>
         | 
| 86 | 
            +
            </html>
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            require 'sendgrid-ruby'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module VisitWidgetEmail
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                class SendDynamicTemplateEmail
         | 
| 6 | 
            +
                  include SendGrid
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(template_id, to, from = nil, dynamic_data = {}, locale = "en", attachments=[])
         | 
| 9 | 
            +
                    @template_id = template_id
         | 
| 10 | 
            +
                    @to = to
         | 
| 11 | 
            +
                    @from = from
         | 
| 12 | 
            +
                    @dynamic_data = dynamic_data
         | 
| 13 | 
            +
                    @locale = locale
         | 
| 14 | 
            +
                    @attachments = attachments
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                  
         | 
| 17 | 
            +
                  def execute
         | 
| 18 | 
            +
                    validate()
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    data = {
         | 
| 21 | 
            +
                      "personalizations": [
         | 
| 22 | 
            +
                        {
         | 
| 23 | 
            +
                          "to": [
         | 
| 24 | 
            +
                            {
         | 
| 25 | 
            +
                              "email": @to
         | 
| 26 | 
            +
                            }
         | 
| 27 | 
            +
                          ],
         | 
| 28 | 
            +
                          "dynamic_template_data": @dynamic_data
         | 
| 29 | 
            +
                        }
         | 
| 30 | 
            +
                      ],
         | 
| 31 | 
            +
                      "template_id": @template_id
         | 
| 32 | 
            +
                    }
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    if @from.present?
         | 
| 35 | 
            +
                      data[:from] = {
         | 
| 36 | 
            +
                        "email": @from
         | 
| 37 | 
            +
                      }
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    if @attachments.present?
         | 
| 41 | 
            +
                      data[:attachments] = @attachments
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    send_grid = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
         | 
| 45 | 
            +
                    
         | 
| 46 | 
            +
                    response = send_grid.client.mail._("send").post(request_body: data)
         | 
| 47 | 
            +
                    error_message = "none"
         | 
| 48 | 
            +
                    if (response.body != "")
         | 
| 49 | 
            +
                      error = response.parsed_body[:errors].length > 0 ? response.parsed_body[:errors][0] : nil
         | 
| 50 | 
            +
                      error_message = error.nil? ? "" : error[:message]
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    # issue in certain environments with the api key, include small partial to verify key used
         | 
| 54 | 
            +
                    Rails.logger.info("Email response - to: #{@to}, status: #{response.status_code}, "\
         | 
| 55 | 
            +
                      "error message: #{error_message}, key: #{ENV['SENDGRID_API_KEY'][0...8]}, "\
         | 
| 56 | 
            +
                      "from: #{@from}, template_id: #{@template_id}")
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    return response
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  private
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  def validate
         | 
| 64 | 
            +
                    if @template_id.nil?
         | 
| 65 | 
            +
                      raise Exception.new "\"template_id\" is required"
         | 
| 66 | 
            +
                    end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    if @to.nil?
         | 
| 69 | 
            +
                      raise Exception.new "\"to\" is required"
         | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                  
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            module VisitWidgetEmail
         | 
| 2 | 
            +
              module Commands
         | 
| 3 | 
            +
                class SendEmail
         | 
| 4 | 
            +
                  def initialize(mailer_params, client_id, locale, params)
         | 
| 5 | 
            +
                    @mailer_params = mailer_params.symbolize_keys
         | 
| 6 | 
            +
                    @client_id = client_id
         | 
| 7 | 
            +
                    @locale = locale
         | 
| 8 | 
            +
                    @params = params
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                  
         | 
| 11 | 
            +
                  def execute
         | 
| 12 | 
            +
                    I18n.with_locale(@locale) do
         | 
| 13 | 
            +
                      mailer_class= @mailer_params[:class_name].constantize
         | 
| 14 | 
            +
                      
         | 
| 15 | 
            +
                      params = [create_app_email_params] + @params
         | 
| 16 | 
            +
                      message_delivery = mailer_class.send(@mailer_params[:action],
         | 
| 17 | 
            +
                        *params)
         | 
| 18 | 
            +
                      message_delivery.deliver_now
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                  
         | 
| 22 | 
            +
                  private
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                  def create_app_email_params
         | 
| 25 | 
            +
                    query =  VisitWidgetEmail::Queries::GetEmailParamsFromClient.new
         | 
| 26 | 
            +
                    return query.execute(@client_id)
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            module VisitWidgetEmail
         | 
| 2 | 
            +
              class EmailParams
         | 
| 3 | 
            +
                attr_accessor :primary_color
         | 
| 4 | 
            +
                attr_accessor :host
         | 
| 5 | 
            +
                attr_accessor :logo_url
         | 
| 6 | 
            +
                attr_accessor :client_name
         | 
| 7 | 
            +
                attr_accessor :ios_itunes_app_id
         | 
| 8 | 
            +
                attr_accessor :android_bundle_identifier
         | 
| 9 | 
            +
                attr_accessor :enable_email_links
         | 
| 10 | 
            +
                attr_accessor :host_with_optional_env
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module VisitWidgetEmail
         | 
| 2 | 
            +
              class Settings
         | 
| 3 | 
            +
                def self.no_reply_email_address(email_params)
         | 
| 4 | 
            +
                  return "no-reply@#{email_params.host}"
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
                
         | 
| 7 | 
            +
                def self.unsubscribe_email_address
         | 
| 8 | 
            +
                  return "contact@visitwidget.com"
         | 
| 9 | 
            +
                end   
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                def self.default_domain
         | 
| 12 | 
            +
                  "visitwidget.com"
         | 
| 13 | 
            +
                end 
         | 
| 14 | 
            +
              end  
         | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            require "visit_widget_email/engine"
         | 
| 2 | 
            +
            require "visit_widget_email/settings"
         | 
| 3 | 
            +
            require "visit_widget_email/email_params"
         | 
| 4 | 
            +
            require "visit_widget_email/commands/send_email"
         | 
| 5 | 
            +
            require "visit_widget_email/commands/send_dynamic_template_email"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module VisitWidgetEmail
         | 
| 8 | 
            +
              # Your code goes here...
         | 
| 9 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,106 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: visit_widget_email
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.7.14
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Visit Widget
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2023-11-14 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rails
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '6.0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '6.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: sendgrid-ruby
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '6.6'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '6.6'
         | 
| 41 | 
            +
            description: Provides a email layout, mailer, and helper for emailsending in Visit
         | 
| 42 | 
            +
              Widget apps.
         | 
| 43 | 
            +
            email:
         | 
| 44 | 
            +
            - development@visitwidget.com
         | 
| 45 | 
            +
            executables: []
         | 
| 46 | 
            +
            extensions: []
         | 
| 47 | 
            +
            extra_rdoc_files: []
         | 
| 48 | 
            +
            files:
         | 
| 49 | 
            +
            - README.md
         | 
| 50 | 
            +
            - Rakefile
         | 
| 51 | 
            +
            - app/helpers/visit_widget_email/mailer_helper.rb
         | 
| 52 | 
            +
            - app/mailers/visit_widget_email/mailer.rb
         | 
| 53 | 
            +
            - app/mailers/visit_widget_email/mailer_defaults.rb
         | 
| 54 | 
            +
            - app/views/layouts/visit_widget_email/email.html.erb
         | 
| 55 | 
            +
            - app/views/layouts/visit_widget_email/images/apple_app_store_logo_de.png
         | 
| 56 | 
            +
            - app/views/layouts/visit_widget_email/images/apple_app_store_logo_en.png
         | 
| 57 | 
            +
            - app/views/layouts/visit_widget_email/images/apple_app_store_logo_es.png
         | 
| 58 | 
            +
            - app/views/layouts/visit_widget_email/images/apple_app_store_logo_fr.png
         | 
| 59 | 
            +
            - app/views/layouts/visit_widget_email/images/apple_app_store_logo_zn-CH.png
         | 
| 60 | 
            +
            - app/views/layouts/visit_widget_email/images/google_app_store_logo_de.png
         | 
| 61 | 
            +
            - app/views/layouts/visit_widget_email/images/google_app_store_logo_en.png
         | 
| 62 | 
            +
            - app/views/layouts/visit_widget_email/images/google_app_store_logo_es.png
         | 
| 63 | 
            +
            - app/views/layouts/visit_widget_email/images/google_app_store_logo_fr.png
         | 
| 64 | 
            +
            - app/views/layouts/visit_widget_email/images/google_app_store_logo_zn-CH.png
         | 
| 65 | 
            +
            - config/locales/de.yml
         | 
| 66 | 
            +
            - config/locales/en-GB.yml
         | 
| 67 | 
            +
            - config/locales/en.yml
         | 
| 68 | 
            +
            - config/locales/es.yml
         | 
| 69 | 
            +
            - config/locales/fr.yml
         | 
| 70 | 
            +
            - config/locales/it.yml
         | 
| 71 | 
            +
            - config/locales/nl.yml
         | 
| 72 | 
            +
            - config/locales/pt-BR.yml
         | 
| 73 | 
            +
            - config/locales/zh-CN.yml
         | 
| 74 | 
            +
            - lib/tasks/visit_widget_mailer_tasks.rake
         | 
| 75 | 
            +
            - lib/visit_widget_email.rb
         | 
| 76 | 
            +
            - lib/visit_widget_email/commands/send_dynamic_template_email.rb
         | 
| 77 | 
            +
            - lib/visit_widget_email/commands/send_email.rb
         | 
| 78 | 
            +
            - lib/visit_widget_email/email_params.rb
         | 
| 79 | 
            +
            - lib/visit_widget_email/engine.rb
         | 
| 80 | 
            +
            - lib/visit_widget_email/settings.rb
         | 
| 81 | 
            +
            - lib/visit_widget_email/version.rb
         | 
| 82 | 
            +
            homepage: https://github.com/visit-widget/visit_widget_email
         | 
| 83 | 
            +
            licenses:
         | 
| 84 | 
            +
            - Visit Widget LLC use only
         | 
| 85 | 
            +
            metadata: {}
         | 
| 86 | 
            +
            post_install_message:
         | 
| 87 | 
            +
            rdoc_options: []
         | 
| 88 | 
            +
            require_paths:
         | 
| 89 | 
            +
            - lib
         | 
| 90 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 91 | 
            +
              requirements:
         | 
| 92 | 
            +
              - - ">="
         | 
| 93 | 
            +
                - !ruby/object:Gem::Version
         | 
| 94 | 
            +
                  version: '0'
         | 
| 95 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 96 | 
            +
              requirements:
         | 
| 97 | 
            +
              - - ">="
         | 
| 98 | 
            +
                - !ruby/object:Gem::Version
         | 
| 99 | 
            +
                  version: '0'
         | 
| 100 | 
            +
            requirements: []
         | 
| 101 | 
            +
            rubygems_version: 3.2.3
         | 
| 102 | 
            +
            signing_key:
         | 
| 103 | 
            +
            specification_version: 4
         | 
| 104 | 
            +
            summary: Provides a email layout, mailer, and helper for emailsending in Visit Widget
         | 
| 105 | 
            +
              apps.
         | 
| 106 | 
            +
            test_files: []
         |