workarea-mail_chimp 3.0.2
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/.editorconfig +15 -0
- data/.gitignore +55 -0
- data/.markdownlint.json +10 -0
- data/.rails-rubocop.yml +119 -0
- data/.rubocop.yml +8 -0
- data/.scss-lint.yml +188 -0
- data/CHANGELOG.md +244 -0
- data/Gemfile +9 -0
- data/README.md +115 -0
- data/Rakefile +53 -0
- data/app/assets/javascripts/workarea/storefront/mail_chimp/mail_chimp_tracking.js +15 -0
- data/app/controllers/workarea/storefront/application_controller.decorator +11 -0
- data/app/controllers/workarea/storefront/cart_items_controller.decorator +18 -0
- data/app/controllers/workarea/storefront/checkout/addresses_controller.decorator +13 -0
- data/app/controllers/workarea/storefront/checkout/shipping_controller.decorator +13 -0
- data/app/controllers/workarea/storefront/users/accounts_controller.decorator +37 -0
- data/app/models/workarea/catalog/product.decorator +7 -0
- data/app/models/workarea/mail_chimp/group.rb +39 -0
- data/app/models/workarea/mail_chimp/store.rb +26 -0
- data/app/models/workarea/order.decorator +9 -0
- data/app/models/workarea/user.decorator +31 -0
- data/app/services/workarea/mail_chimp/address.rb +28 -0
- data/app/services/workarea/mail_chimp/cart.rb +78 -0
- data/app/services/workarea/mail_chimp/order.rb +97 -0
- data/app/services/workarea/mail_chimp/product.rb +43 -0
- data/app/services/workarea/mail_chimp/variant.rb +43 -0
- data/app/view_models/workarea/storefront/user_view_model.decorator +16 -0
- data/app/views/workarea/storefront/mail_chimp/_ecommerce_javascript.html.haml +2 -0
- data/app/views/workarea/storefront/users/accounts/_edit.html.haml +12 -0
- data/app/views/workarea/storefront/users/accounts/_email_interests.html.haml +13 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_cart.rb +40 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_order.rb +31 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_product.rb +31 -0
- data/app/workers/workarea/mail_chimp/list_subscriber.rb +30 -0
- data/app/workers/workarea/mail_chimp/list_unsubscriber.rb +22 -0
- data/app/workers/workarea/mail_chimp/subscription_edit.rb +28 -0
- data/bin/rails +19 -0
- data/config/initializers/appends.rb +21 -0
- data/config/initializers/workarea.rb +14 -0
- data/config/locales/en.yml +15 -0
- data/lib/gibbon/request_decorator.rb +10 -0
- data/lib/integrations/workarea/mail_chimp/bogus_api_request.rb +30 -0
- data/lib/integrations/workarea/mail_chimp/bogus_gateway.rb +35 -0
- data/lib/integrations/workarea/mail_chimp/bogus_request.rb +78 -0
- data/lib/integrations/workarea/mail_chimp/gateway.rb +86 -0
- data/lib/integrations/workarea/mail_chimp/gateway/list.rb +47 -0
- data/lib/integrations/workarea/mail_chimp/gateway/members.rb +61 -0
- data/lib/integrations/workarea/mail_chimp/gateway/subscribe_argument_builder.rb +101 -0
- data/lib/tasks/mail_chimp.rake +71 -0
- data/lib/workarea/mail_chimp.rb +72 -0
- data/lib/workarea/mail_chimp/engine.rb +14 -0
- data/lib/workarea/mail_chimp/errors.rb +2 -0
- data/lib/workarea/mail_chimp/tasks/ecommerce.rb +43 -0
- data/lib/workarea/mail_chimp/version.rb +5 -0
- data/script/admin_ci +9 -0
- data/script/ci +11 -0
- data/script/core_ci +9 -0
- data/script/plugins_ci +9 -0
- data/script/storefront_ci +9 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +56 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/factories/mail_chimp.rb +50 -0
- data/test/integration/workarea/mailchimp/subscription_test.rb +52 -0
- data/test/integration/workarea/mailchimp/tracking_params_test.rb +50 -0
- data/test/integration/workarea/mailchimp/unsubscribe_test.rb +14 -0
- data/test/integration/workarea/storefront/mail_chimp_order_test.rb +106 -0
- data/test/integration/workarea/storefront/mail_chimp_product_test.rb +51 -0
- data/test/integration/workarea/storefront/mail_chimp_site_javascript_test.rb +25 -0
- data/test/lib/workarea/mailchimp/gateway/list_test.rb +48 -0
- data/test/lib/workarea/mailchimp/gateway_test.rb +196 -0
- data/test/lib/workarea/mailchimp/tasks/ecommerce_test.rb +40 -0
- data/test/services/workarea/mail_chimp/cart_test.rb +44 -0
- data/test/services/workarea/mail_chimp/order_test.rb +50 -0
- data/test/services/workarea/mail_chimp/product_test.rb +29 -0
- data/test/support/workarea/mail_chimp_api_config.rb +33 -0
- data/test/system/workarea/storefront/campaign_tracking_test.rb +14 -0
- data/test/system/workarea/storefront/group_test.rb +33 -0
- data/test/system/workarea/storefront/mail_chimp_accounts_system_test.rb +79 -0
- data/test/test_helper.rb +17 -0
- data/test/vcr_cassettes/get_default_list_interests.yml +104 -0
- data/test/vcr_cassettes/get_member_details_no_match.yml +51 -0
- data/test/vcr_cassettes/get_member_details_unsubscribed.yml +51 -0
- data/test/vcr_cassettes/interest_categories_read.yml +104 -0
- data/test/vcr_cassettes/mail_chimp/tasks/create_store-successful.yml +97 -0
- data/test/vcr_cassettes/mc_order_test.yml +381 -0
- data/test/vcr_cassettes/mc_product_test.yml +234 -0
- data/test/vcr_cassettes/subscribe_to_default_list.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_interest_groups.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_with_groupings.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_with_user_details.yml +254 -0
- data/test/vcr_cassettes/unsubscribe_from_default_list.yml +53 -0
- data/test/vcr_cassettes/update_member_on_default_list_change_email.yml +254 -0
- data/test/vcr_cassettes/update_member_on_default_list_change_groupings.yml +254 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_cart_test.rb +28 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_order_test.rb +15 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_product_test.rb +15 -0
- data/workarea-mail_chimp.gemspec +20 -0
- metadata +212 -0
| @@ -0,0 +1,101 @@ | |
| 1 | 
            +
            module Workarea
         | 
| 2 | 
            +
              module MailChimp
         | 
| 3 | 
            +
                class Gateway::SubscribeArgumentBuilder
         | 
| 4 | 
            +
                  attr_reader :email, :options, :default_list_id, :email_interests_id
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize(email, options, default_list_id, email_interests_id)
         | 
| 7 | 
            +
                    @email = email
         | 
| 8 | 
            +
                    @options = options
         | 
| 9 | 
            +
                    @default_list_id = default_list_id
         | 
| 10 | 
            +
                    @email_interests_id = email_interests_id
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def build
         | 
| 14 | 
            +
                    args = get_args(email, options[:user], default_list_options)
         | 
| 15 | 
            +
                    merge_new_email(args, options)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  private
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def merge_new_email(args, options)
         | 
| 21 | 
            +
                      return args unless options[:new_email].present?
         | 
| 22 | 
            +
                      args.merge(merge_vars: { email: options[:new_email] })
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def default_list_options
         | 
| 26 | 
            +
                      {
         | 
| 27 | 
            +
                        id: default_list_id,
         | 
| 28 | 
            +
                        double_optin: false,
         | 
| 29 | 
            +
                        send_welcome: true,
         | 
| 30 | 
            +
                        replace_interests: true,
         | 
| 31 | 
            +
                        update_existing: true, # updating existing so we can make same API
         | 
| 32 | 
            +
                        # call for new subscribers and existing subscribers
         | 
| 33 | 
            +
                        email_type: "html" # other option is "text"
         | 
| 34 | 
            +
                      }
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def get_args(email, user = nil, options = {})
         | 
| 38 | 
            +
                      group_merge = merge_groups({}, user)
         | 
| 39 | 
            +
                      user_details_merge = merge_user_details({}, user)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                      { email_address: email }.
         | 
| 42 | 
            +
                        merge(options).
         | 
| 43 | 
            +
                        merge(merge_fields: user_details_merge).
         | 
| 44 | 
            +
                        merge(group_merge)
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    def merge_user_details(merge_vars, user)
         | 
| 48 | 
            +
                      return merge_vars unless user.present?
         | 
| 49 | 
            +
                      merge_vars[:FNAME] = user.first_name if user.first_name.present?
         | 
| 50 | 
            +
                      merge_vars[:LNAME] = user.last_name if user.last_name.present?
         | 
| 51 | 
            +
                      merge_vars
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    def merge_groups(merge_vars, user)
         | 
| 55 | 
            +
                      if user&.groups.present?
         | 
| 56 | 
            +
                        merge_vars.merge(interests: build_merged_groups(user.groups))
         | 
| 57 | 
            +
                      else
         | 
| 58 | 
            +
                        merge_vars.merge(interests: build_merged_groups(all_groups))
         | 
| 59 | 
            +
                      end
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    def build_merged_groups(groups)
         | 
| 63 | 
            +
                      hash = groups.first.interests.each_with_object({}) do |(id, _int), hsh|
         | 
| 64 | 
            +
                        hsh[id] = true
         | 
| 65 | 
            +
                      end
         | 
| 66 | 
            +
                      all_interests.each do |id, int|
         | 
| 67 | 
            +
                        hash[id] = false unless hash.keys.include?(id)
         | 
| 68 | 
            +
                      end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                      hash
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                    def all_groups
         | 
| 74 | 
            +
                      [default_group(group_interests)]
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    def all_interests
         | 
| 78 | 
            +
                      group_interests.inject({}) { |aggregate, int| aggregate.merge(int.interests) }
         | 
| 79 | 
            +
                    end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                    def default_group(groups)
         | 
| 82 | 
            +
                      default = groups.detect do |group|
         | 
| 83 | 
            +
                        group.id == email_interests_id
         | 
| 84 | 
            +
                      end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                      default || groups.first
         | 
| 87 | 
            +
                    end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                    def group_interests
         | 
| 90 | 
            +
                      key = "mail_chimp_email_interests/#{Workarea::MailChimp.config.default_store[:list_id]}"
         | 
| 91 | 
            +
                      options = { expires_in: 1.hour }
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                      options.merge!(force: true) if Rails.cache.read(key).nil?
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                      Rails.cache.fetch(key, options) do
         | 
| 96 | 
            +
                        Workarea::MailChimp.gateway.list.interests
         | 
| 97 | 
            +
                      end
         | 
| 98 | 
            +
                    end
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
            end
         | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            require 'workarea/mail_chimp/tasks/ecommerce'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            namespace :workarea do
         | 
| 4 | 
            +
              namespace :mail_chimp do
         | 
| 5 | 
            +
                desc 'Seed MailChimp data'
         | 
| 6 | 
            +
                task install: :environment do
         | 
| 7 | 
            +
                  Rake::Task['workarea:mail_chimp:seed_store'].execute
         | 
| 8 | 
            +
                  Rake::Task['workarea:mail_chimp:seed_products'].execute
         | 
| 9 | 
            +
                  Rake::Task['workarea:mail_chimp:seed_orders'].execute
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                desc 'Create Default Store for MailChimp Ecommerce'
         | 
| 13 | 
            +
                task seed_store: :environment do
         | 
| 14 | 
            +
                  puts 'Creating Store ...'
         | 
| 15 | 
            +
                  Workarea::MailChimp::Tasks::Ecommerce.create_store
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                desc 'Export full products to MailChimp'
         | 
| 19 | 
            +
                task seed_products: :environment do
         | 
| 20 | 
            +
                  puts 'Creating Products...'
         | 
| 21 | 
            +
                  raise RuntimeError.new("No Store ID set in configuration!") unless Workarea::MailChimp.config.default_store[:id].present?
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  Workarea::Catalog::Product.purchasable.each do |product|
         | 
| 24 | 
            +
                    next if product.variants.empty?
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    mc_product = Workarea::MailChimp::Product.new(product)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    request = Workarea::MailChimp.request
         | 
| 29 | 
            +
                    store_id = Workarea::MailChimp.config.default_store[:id]
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    if product.exported_to_mail_chimp_at.present?
         | 
| 32 | 
            +
                      puts "Updating #{product.name}"
         | 
| 33 | 
            +
                      request.ecommerce.stores(store_id).products(product.id.to_s).update(body: mc_product.to_h)
         | 
| 34 | 
            +
                    else
         | 
| 35 | 
            +
                      puts "Creating #{product.name}"
         | 
| 36 | 
            +
                      request.ecommerce.stores(store_id).products.create(body: mc_product.to_h)
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                      product.update_attributes!(exported_to_mail_chimp_at: Time.current)
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                desc 'Export full orders to MailChimp'
         | 
| 44 | 
            +
                task seed_orders: :environment do
         | 
| 45 | 
            +
                  puts 'Creating Orders...'
         | 
| 46 | 
            +
                  raise RuntimeError.new("No Store ID set in configuration!") unless Workarea::MailChimp.config.default_store[:id].present?
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  # turn on the syncing feature of MC - this will stop users from getting unwanted emails
         | 
| 49 | 
            +
                  puts "Enable store sync"
         | 
| 50 | 
            +
                  Workarea::MailChimp::Store.with_syncing_enabled do
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    Workarea::Order.placed.each do |order|
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                      request = Workarea::MailChimp.request
         | 
| 55 | 
            +
                      store_id = Workarea::MailChimp.config.default_store[:id]
         | 
| 56 | 
            +
                      mc_order = Workarea::MailChimp::Order.new(order)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                      if order.exported_to_mail_chimp_at.present?
         | 
| 59 | 
            +
                        puts "Updating #{order.id}"
         | 
| 60 | 
            +
                        request.ecommerce.stores(store_id).orders(order.id.to_s).update(body: mc_order.to_h)
         | 
| 61 | 
            +
                      else
         | 
| 62 | 
            +
                        puts "Creating #{order.id}"
         | 
| 63 | 
            +
                        request.ecommerce.stores(store_id).orders.create(body: mc_order.to_h)
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                        order.update_attributes!(exported_to_mail_chimp_at: Time.current)
         | 
| 66 | 
            +
                      end
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
            end
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            require "workarea"
         | 
| 2 | 
            +
            require "workarea/storefront"
         | 
| 3 | 
            +
            require "workarea/admin"
         | 
| 4 | 
            +
            require "gibbon"
         | 
| 5 | 
            +
            require 'gibbon/request_decorator'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Workarea
         | 
| 8 | 
            +
              module MailChimp
         | 
| 9 | 
            +
                def self.credentials
         | 
| 10 | 
            +
                  (Rails.application.secrets.mail_chimp || {}).deep_symbolize_keys
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def self.api_key
         | 
| 14 | 
            +
                  credentials[:api_key]
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.config
         | 
| 18 | 
            +
                  Workarea.config.mail_chimp
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def self.default_list_id
         | 
| 22 | 
            +
                  Workarea.config[:default_list_id]
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def self.list_prefrences_id
         | 
| 26 | 
            +
                  Workarea.config[:default_list_id]
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def self.config
         | 
| 30 | 
            +
                  Workarea.config.mail_chimp
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def self.current_store
         | 
| 34 | 
            +
                  return unless config&.default_store && config.default_store[:id].present?
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  Store.find_by(mail_chimp_id: config.default_store[:id]) rescue nil
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def self.initialize_gateway
         | 
| 40 | 
            +
                  if Rails.application.secrets.mail_chimp.present?
         | 
| 41 | 
            +
                    secrets = Rails.application.secrets.mail_chimp.deep_symbolize_keys
         | 
| 42 | 
            +
                    Workarea.config.gateways.mail_chimp = Workarea::MailChimp::Gateway.new(
         | 
| 43 | 
            +
                      secrets[:default_list_id],
         | 
| 44 | 
            +
                      secrets[:list_preferences_id]
         | 
| 45 | 
            +
                    )
         | 
| 46 | 
            +
                  else
         | 
| 47 | 
            +
                    Workarea.config.gateways.mail_chimp = Workarea::MailChimp::BogusGateway.new
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def self.gateway
         | 
| 52 | 
            +
                  if credentials.present?
         | 
| 53 | 
            +
                    Workarea::MailChimp::Gateway.new
         | 
| 54 | 
            +
                  else
         | 
| 55 | 
            +
                    Workarea::MailChimp::BogusGateway.new
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                # Returns a single use gibbon request object
         | 
| 60 | 
            +
                def self.request
         | 
| 61 | 
            +
                  if Workarea::MailChimp.api_key.present?
         | 
| 62 | 
            +
                    Gibbon::Request.new(api_key: Workarea::MailChimp.api_key)
         | 
| 63 | 
            +
                  else
         | 
| 64 | 
            +
                    Workarea::MailChimp::BogusRequest.new(api_key: 'test-us1')
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            require "workarea/mail_chimp/version"
         | 
| 71 | 
            +
            require "workarea/mail_chimp/errors"
         | 
| 72 | 
            +
            require "workarea/mail_chimp/engine"
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module Workarea
         | 
| 2 | 
            +
              module MailChimp
         | 
| 3 | 
            +
                class Engine < ::Rails::Engine
         | 
| 4 | 
            +
                  include Workarea::Plugin
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  isolate_namespace Workarea::MailChimp
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  %w(lib/integrations).each do |path|
         | 
| 9 | 
            +
                    config.autoload_paths << "#{config.root}/#{path}"
         | 
| 10 | 
            +
                    config.eager_load_paths << "#{config.root}/#{path}"
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            module Workarea
         | 
| 2 | 
            +
              module MailChimp
         | 
| 3 | 
            +
                module Tasks
         | 
| 4 | 
            +
                  module Ecommerce
         | 
| 5 | 
            +
                    extend self
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                    # Creates an ecommerce store in Mail Chimp
         | 
| 8 | 
            +
                    def create_store
         | 
| 9 | 
            +
                      raise RuntimeError.new("No list id defined in store configuration!") unless Workarea::MailChimp.config.default_store[:list_id].present?
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                      if Workarea::MailChimp::Store.where(mail_chimp_id: Workarea::MailChimp.config.default_store[:id]).exists?
         | 
| 12 | 
            +
                        raise RuntimeError, "Mailchimp store with id #{Workarea::MailChimp.config.default_store[:id]} already exists"
         | 
| 13 | 
            +
                      end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                      request = Workarea::MailChimp.request
         | 
| 16 | 
            +
                      begin
         | 
| 17 | 
            +
                        response = request.ecommerce.stores.create(body: Workarea::MailChimp.config.default_store)
         | 
| 18 | 
            +
                      rescue Gibbon::MailChimpError => error
         | 
| 19 | 
            +
                        raise RuntimeError, error.detail
         | 
| 20 | 
            +
                      end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      Workarea::MailChimp::Store.create!(
         | 
| 23 | 
            +
                        mail_chimp_id: response.body["id"],
         | 
| 24 | 
            +
                        list_id: response.body["list_id"],
         | 
| 25 | 
            +
                        name: response.body["name"],
         | 
| 26 | 
            +
                        currency_code: response.body["currency_code"],
         | 
| 27 | 
            +
                        connected_site: response.body.dig("connected_site"),
         | 
| 28 | 
            +
                      )
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                      connected_site_id = response.body.dig("connected_site", "site_foreign_id")
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                      Workarea::MailChimp
         | 
| 33 | 
            +
                        .request
         | 
| 34 | 
            +
                        .connected_sites
         | 
| 35 | 
            +
                        .add_path_part(connected_site_id)
         | 
| 36 | 
            +
                        .actions
         | 
| 37 | 
            +
                        .send('verify-script-installation')
         | 
| 38 | 
            +
                        .create
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
    
        data/script/admin_ci
    ADDED
    
    
    
        data/script/ci
    ADDED
    
    
    
        data/script/core_ci
    ADDED
    
    
    
        data/script/plugins_ci
    ADDED
    
    
    
        data/test/dummy/Rakefile
    ADDED
    
    
| 
            File without changes
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            // This is a manifest file that'll be compiled into application.js, which will include all the files
         | 
| 2 | 
            +
            // listed below.
         | 
| 3 | 
            +
            //
         | 
| 4 | 
            +
            // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
         | 
| 5 | 
            +
            // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
         | 
| 6 | 
            +
            //
         | 
| 7 | 
            +
            // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
         | 
| 8 | 
            +
            // compiled file. JavaScript code in this file should be added after the last require_* statement.
         | 
| 9 | 
            +
            //
         | 
| 10 | 
            +
            // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
         | 
| 11 | 
            +
            // about supported directives.
         | 
| 12 | 
            +
            //
         | 
| 13 | 
            +
            //= require_tree .
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            /*
         | 
| 2 | 
            +
             * This is a manifest file that'll be compiled into application.css, which will include all the files
         | 
| 3 | 
            +
             * listed below.
         | 
| 4 | 
            +
             *
         | 
| 5 | 
            +
             * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
         | 
| 6 | 
            +
             * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
         | 
| 7 | 
            +
             *
         | 
| 8 | 
            +
             * You're free to add application-wide styles to this file and they'll appear at the bottom of the
         | 
| 9 | 
            +
             * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
         | 
| 10 | 
            +
             * files in this directory. Styles in this file should be added after the last require_* statement.
         | 
| 11 | 
            +
             * It is generally better to create a new file per style scope.
         | 
| 12 | 
            +
             *
         | 
| 13 | 
            +
             *= require_tree .
         | 
| 14 | 
            +
             *= require_self
         | 
| 15 | 
            +
             */
         | 
| 
            File without changes
         |