workarea-listrak 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +36 -0
  3. data/.esvmrc +5 -0
  4. data/.gitignore +32 -0
  5. data/CHANGELOG.md +322 -0
  6. data/Gemfile +14 -0
  7. data/README.md +130 -0
  8. data/Rakefile +53 -0
  9. data/app/assets/javascripts/workarea/admin/modules/listrak/list_events_select.js +83 -0
  10. data/app/assets/javascripts/workarea/storefront/listrak/adapters/listrak_adapter.js +110 -0
  11. data/app/assets/javascripts/workarea/storefront/listrak/listrak_config.js.erb +13 -0
  12. data/app/assets/javascripts/workarea/storefront/listrak/modules/listrak.js +64 -0
  13. data/app/controllers/workarea/admin/listrak/configurations_controller.rb +30 -0
  14. data/app/controllers/workarea/admin/listrak/events_controller.rb +17 -0
  15. data/app/helpers/workarea/listrak/analytics/helper.rb +44 -0
  16. data/app/models/workarea/listrak/configuration.rb +19 -0
  17. data/app/queries/workarea/categorization.decorator +7 -0
  18. data/app/services/workarea/listrak/data_api/customers.rb +26 -0
  19. data/app/services/workarea/listrak/data_api/orders.rb +26 -0
  20. data/app/services/workarea/listrak/data_api/products.rb +26 -0
  21. data/app/services/workarea/listrak/data_api.rb +63 -0
  22. data/app/services/workarea/listrak/email_api/contacts.rb +73 -0
  23. data/app/services/workarea/listrak/email_api/events.rb +44 -0
  24. data/app/services/workarea/listrak/email_api/lists.rb +21 -0
  25. data/app/services/workarea/listrak/email_api/messages.rb +50 -0
  26. data/app/services/workarea/listrak/email_api/transactional_messages.rb +32 -0
  27. data/app/services/workarea/listrak/email_api.rb +71 -0
  28. data/app/services/workarea/listrak/models/address.rb +83 -0
  29. data/app/services/workarea/listrak/models/contact.rb +67 -0
  30. data/app/services/workarea/listrak/models/contact_form.rb +24 -0
  31. data/app/services/workarea/listrak/models/customer_form.rb +209 -0
  32. data/app/services/workarea/listrak/models/event.rb +45 -0
  33. data/app/services/workarea/listrak/models/event_form.rb +25 -0
  34. data/app/services/workarea/listrak/models/list.rb +204 -0
  35. data/app/services/workarea/listrak/models/message_form.rb +147 -0
  36. data/app/services/workarea/listrak/models/order_form.rb +352 -0
  37. data/app/services/workarea/listrak/models/order_item.rb +197 -0
  38. data/app/services/workarea/listrak/models/product_form.rb +369 -0
  39. data/app/services/workarea/listrak/models/transactional_message_form.rb +21 -0
  40. data/app/services/workarea/listrak/oauth.rb +45 -0
  41. data/app/services/workarea/listrak/transactional_message.rb +83 -0
  42. data/app/view_models/workarea/admin/listrak_configuration_view_model.rb +17 -0
  43. data/app/views/workarea/admin/listrak/configurations/edit.html.haml +28 -0
  44. data/app/views/workarea/admin/listrak/events/index.json.jbuilder +4 -0
  45. data/app/views/workarea/admin/shared/_listrak_configuration_link.html.haml +1 -0
  46. data/app/views/workarea/storefront/checkouts/_listrak.html.haml +2 -0
  47. data/app/workers/workarea/listrak/customer_exporter.rb +22 -0
  48. data/app/workers/workarea/listrak/order_exporter.rb +22 -0
  49. data/app/workers/workarea/listrak/product_exporter.rb +50 -0
  50. data/app/workers/workarea/listrak/subscribe_email_signup.rb +34 -0
  51. data/app/workers/workarea/listrak/unsubscribe_email_signup.rb +27 -0
  52. data/bin/rails +18 -0
  53. data/bin/rake +16 -0
  54. data/bin/rspec +16 -0
  55. data/bin/rubocop +16 -0
  56. data/config/initializers/append_points.rb +28 -0
  57. data/config/initializers/configuration.rb +8 -0
  58. data/config/locales/en.yml +17 -0
  59. data/config/routes.rb +10 -0
  60. data/docs/Listrak Technical Integration Guide.docx +0 -0
  61. data/lib/generators/workarea/listrak/message/USAGE +9 -0
  62. data/lib/generators/workarea/listrak/message/message_generator.rb +15 -0
  63. data/lib/generators/workarea/listrak/message/templates/message.rb.erb +24 -0
  64. data/lib/workarea/listrak/analytics.rb +17 -0
  65. data/lib/workarea/listrak/bogus_data_api/customers.rb +9 -0
  66. data/lib/workarea/listrak/bogus_data_api/orders.rb +9 -0
  67. data/lib/workarea/listrak/bogus_data_api/products.rb +9 -0
  68. data/lib/workarea/listrak/bogus_data_api/proxy_client.rb +29 -0
  69. data/lib/workarea/listrak/bogus_data_api.rb +46 -0
  70. data/lib/workarea/listrak/bogus_email_api/contacts.rb +8 -0
  71. data/lib/workarea/listrak/bogus_email_api/events.rb +23 -0
  72. data/lib/workarea/listrak/bogus_email_api/lists.rb +63 -0
  73. data/lib/workarea/listrak/bogus_email_api/proxy_client.rb +29 -0
  74. data/lib/workarea/listrak/bogus_email_api/transactional_messages.rb +9 -0
  75. data/lib/workarea/listrak/bogus_email_api.rb +51 -0
  76. data/lib/workarea/listrak/engine.rb +12 -0
  77. data/lib/workarea/listrak/error.rb +39 -0
  78. data/lib/workarea/listrak/version.rb +5 -0
  79. data/lib/workarea/listrak.rb +57 -0
  80. data/readme/listrak-admin.png +0 -0
  81. data/script/admin_ci +9 -0
  82. data/script/ci +11 -0
  83. data/script/core_ci +9 -0
  84. data/script/plugins_ci +9 -0
  85. data/script/storefront_ci +9 -0
  86. data/test/dummy/Rakefile +6 -0
  87. data/test/dummy/bin/bundle +3 -0
  88. data/test/dummy/bin/rails +4 -0
  89. data/test/dummy/bin/rake +4 -0
  90. data/test/dummy/bin/setup +34 -0
  91. data/test/dummy/bin/update +29 -0
  92. data/test/dummy/config/application.rb +18 -0
  93. data/test/dummy/config/boot.rb +5 -0
  94. data/test/dummy/config/cable.yml +9 -0
  95. data/test/dummy/config/environment.rb +5 -0
  96. data/test/dummy/config/environments/development.rb +54 -0
  97. data/test/dummy/config/environments/production.rb +86 -0
  98. data/test/dummy/config/environments/test.rb +43 -0
  99. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  100. data/test/dummy/config/initializers/assets.rb +11 -0
  101. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  102. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  103. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  104. data/test/dummy/config/initializers/inflections.rb +16 -0
  105. data/test/dummy/config/initializers/mime_types.rb +4 -0
  106. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  107. data/test/dummy/config/initializers/session_store.rb +3 -0
  108. data/test/dummy/config/initializers/workarea.rb +5 -0
  109. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  110. data/test/dummy/config/locales/en.yml +23 -0
  111. data/test/dummy/config/puma.rb +47 -0
  112. data/test/dummy/config/routes.rb +5 -0
  113. data/test/dummy/config/secrets.yml +38 -0
  114. data/test/dummy/config/spring.rb +6 -0
  115. data/test/dummy/config.ru +5 -0
  116. data/test/dummy/db/seeds.rb +2 -0
  117. data/test/dummy/public/404.html +67 -0
  118. data/test/dummy/public/422.html +67 -0
  119. data/test/dummy/public/500.html +66 -0
  120. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  121. data/test/dummy/public/apple-touch-icon.png +0 -0
  122. data/test/dummy/public/favicon.ico +0 -0
  123. data/test/factories/workarea/factories/listrak.rb +15 -0
  124. data/test/helpers/workarea/listrak/analytics/helper_test.rb +38 -0
  125. data/test/integration/workarea/admin/listrak/configuration_integration_test.rb +26 -0
  126. data/test/integration/workarea/admin/listrak/events_integration_test.rb +21 -0
  127. data/test/lib/generators/workarea/listrak/message_generator_test.rb +26 -0
  128. data/test/queries/workarea/categorization_test.decorator +15 -0
  129. data/test/services/workarea/listrak/data_api/customers_test.rb +35 -0
  130. data/test/services/workarea/listrak/data_api/orders_test.rb +24 -0
  131. data/test/services/workarea/listrak/data_api/products_test.rb +27 -0
  132. data/test/services/workarea/listrak/email_api/contacts_test.rb +55 -0
  133. data/test/services/workarea/listrak/email_api/events_test.rb +51 -0
  134. data/test/services/workarea/listrak/email_api/lists_test.rb +45 -0
  135. data/test/services/workarea/listrak/email_api/messages_test.rb +28 -0
  136. data/test/services/workarea/listrak/email_api/transactional_messages_test.rb +50 -0
  137. data/test/services/workarea/listrak/oauth_test.rb +27 -0
  138. data/test/services/workarea/listrak/transactional_message_test.rb +48 -0
  139. data/test/support/workarea/listrak/test_order_confirmation_email.rb +116 -0
  140. data/test/support/workarea/listrak/vcr_config.rb +31 -0
  141. data/test/system/workarea/listrak_system_test.rb +75 -0
  142. data/test/test_helper.rb +16 -0
  143. data/test/vcr_cassettes/listrak/data_api/customers_import-successful.yml +88 -0
  144. data/test/vcr_cassettes/listrak/data_api/orders_import-successful.yml +90 -0
  145. data/test/vcr_cassettes/listrak/data_api/products_import-successful.yml +88 -0
  146. data/test/vcr_cassettes/listrak/email_api/contacts_get-successful.yml +87 -0
  147. data/test/vcr_cassettes/listrak/email_api/contacts_upsert-already_unsubscribed.yml +90 -0
  148. data/test/vcr_cassettes/listrak/email_api/contacts_upsert-successful.yml +87 -0
  149. data/test/vcr_cassettes/listrak/email_api/events_create-invalid_parameter.yml +90 -0
  150. data/test/vcr_cassettes/listrak/email_api/events_create-successful.yml +87 -0
  151. data/test/vcr_cassettes/listrak/email_api/events_get-successful.yml +88 -0
  152. data/test/vcr_cassettes/listrak/email_api/lists_all-successful.yml +88 -0
  153. data/test/vcr_cassettes/listrak/email_api/messages_create-successful.yml +88 -0
  154. data/test/vcr_cassettes/listrak/email_api/transactional_messages_create-successful.yml +89 -0
  155. data/test/vcr_cassettes/listrak/oauth-successful.yml +44 -0
  156. data/test/vcr_cassettes/listrak/oauth-unsuccessful.yml +46 -0
  157. data/test/vcr_cassettes/listrak/system_tests/footer_email_signup-successful.yml +171 -0
  158. data/test/vcr_cassettes/listrak/system_tests/footer_email_signup_overrides_unsubscribe.yml +255 -0
  159. data/test/vcr_cassettes/listrak/system_tests/unsubscribing.yml +593 -0
  160. data/test/workers/workarea/listrak/order_exporter_test.rb +31 -0
  161. data/test/workers/workarea/listrak/product_exporter_test.rb +62 -0
  162. data/workarea-listrak.gemspec +16 -0
  163. metadata +223 -0
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ module Admin
3
+ class ListrakConfigurationViewModel < ApplicationViewModel
4
+ def all_lists
5
+ @all_lists ||= Workarea::Listrak.email.lists.all
6
+ end
7
+
8
+ def event_options
9
+ events.map { |event| [event.name, event.id] }
10
+ end
11
+
12
+ def events
13
+ @events ||= Workarea::Listrak.email.events.all default_list_id
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ - @page_title = t('workarea.admin.listrak_configuration.edit.title')
2
+
3
+ .view
4
+ .view__header
5
+ .view__heading
6
+ = link_to "↑ #{t('workarea.admin.dashboards.settings.settings_dashboard')}", settings_dashboards_path
7
+ %h1= t('workarea.admin.listrak_configuration.edit.title')
8
+
9
+ .view__container
10
+ = form_tag listrak_configuration_path, method: :patch, data: { unsaved_changes: '' } do
11
+ .property
12
+ = label_tag 'default_list_id', t('workarea.admin.listrak_configuration.edit.default_list'), class: 'property__name'
13
+ = select_tag 'default_list_id', options_from_collection_for_select(@configuration.all_lists, 'id', 'name', @configuration.default_list_id)
14
+
15
+ .property
16
+ = label_tag 'external_event_ids[]', class: 'property__name' do
17
+ %span= t('workarea.admin.listrak_configuration.edit.external_events')
18
+
19
+ = link_to "#event_ids", data: { tooltip: '' } do
20
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.content.form.tooltip.title'))
21
+ #event_ids.tooltip-content= t('workarea.admin.listrak_configuration.edit.event_itds_tooltip')
22
+
23
+ = select_tag "external_event_ids[]", options_for_select(@configuration.event_options, @configuration.external_event_ids), multiple: true, data: { listrak_events_select: "" }
24
+
25
+
26
+ .workflow-bar
27
+ .grid.grid--auto.grid--right.grid--middle
28
+ .grid__cell= button_tag t('workarea.admin.listrak_configuration.edit.button'), value: 'save_settings', class: 'workflow-bar__button workflow-bar__button--update'
@@ -0,0 +1,4 @@
1
+ json.results @events do |event|
2
+ json.label event.name
3
+ json.value event.id
4
+ end
@@ -0,0 +1 @@
1
+ %li{ class: "primary-nav__item" }= link_to t('workarea.admin.shared.primary_nav.listrak_configuration_title'), edit_listrak_configuration_path, class: navigation_link_classes(edit_listrak_configuration_path)
@@ -0,0 +1,2 @@
1
+ - if Workarea.config.listrak[:merchant_id].present?
2
+ %img{ src: "https://fp.listrakbi.com/fp/#{Workarea.config.listrak[:merchant_id]}.jpg", height: "1", width: "1" }
@@ -0,0 +1,22 @@
1
+ module Workarea
2
+ module Listrak
3
+ class CustomerExporter
4
+ include Sidekiq::Worker
5
+ include Sidekiq::CallbacksWorker
6
+
7
+ sidekiq_options(
8
+ enqueue_on: {
9
+ Workarea::User => :save
10
+ }
11
+ )
12
+
13
+ def perform(user_id)
14
+ user = Workarea::User.find user_id
15
+
16
+ customer_form = Listrak::Models::CustomerForm.new user
17
+
18
+ Listrak.data.customers.import [customer_form]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Workarea
2
+ module Listrak
3
+ class OrderExporter
4
+ include Sidekiq::Worker
5
+ include Sidekiq::CallbacksWorker
6
+
7
+ sidekiq_options(
8
+ enqueue_on: {
9
+ Workarea::Order => :place
10
+ }
11
+ )
12
+
13
+ def perform(order_id)
14
+ order = Workarea::Order.find order_id
15
+
16
+ order_form = Listrak::Models::OrderForm.new order
17
+
18
+ Listrak.data.orders.import [order_form]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ module Workarea
2
+ module Listrak
3
+ class ProductExporter
4
+ include Sidekiq::Worker
5
+ include Sidekiq::CallbacksWorker
6
+
7
+ sidekiq_options(
8
+ enqueue_on: {
9
+ Catalog::Product => :save,
10
+ Shipping::Sku => :save,
11
+ Pricing::Sku => :save,
12
+ Pricing::Price => :save,
13
+ with: -> { ProductExporter.perform_with(self) }
14
+ }
15
+ )
16
+
17
+ def self.perform_with(model)
18
+ case model.class.name
19
+ when "Workarea::Pricing::Price"
20
+ [model.sku.class.name, model.sku.id]
21
+ else
22
+ [model.class.name, model.id]
23
+ end
24
+ end
25
+
26
+ def perform(class_name, id)
27
+ product, skus =
28
+ if class_name == "Workarea::Catalog::Product"
29
+ prod = Catalog::Product.find(id)
30
+ [prod, prod.skus]
31
+ else
32
+ [Catalog::Product.find_by_sku(id), [id]]
33
+ end
34
+
35
+ return unless product.present?
36
+
37
+ inventory = Inventory::Collection.new product.skus
38
+ pricing = Inventory::Collection.new product.skus
39
+
40
+ listrak_products = skus.map do |sku|
41
+ Listrak::Models::ProductForm.new product,
42
+ pricing_sku: pricing.for_sku(sku),
43
+ inventory_sku: inventory.for_sku(sku)
44
+ end
45
+
46
+ Workarea::Listrak.data.products.import(listrak_products)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ module Workarea
2
+ module Listrak
3
+ class SubscribeEmailSignup
4
+ include Sidekiq::Worker
5
+ include Sidekiq::CallbacksWorker
6
+
7
+ sidekiq_options(
8
+ enqueue_on: {
9
+ Email::Signup => :create
10
+ },
11
+ queue: "low",
12
+ retry: true
13
+ )
14
+
15
+ def perform(id)
16
+ signup = Email::Signup.find id
17
+ list_id = Listrak.configuration.default_list_id
18
+ event_ids = Array.wrap(Listrak.configuration.external_event_ids).to_csv(row_sep: nil).presence
19
+
20
+ contact = Listrak::Models::ContactForm.new(
21
+ email: signup.email,
22
+ subscription_state: 'Subscribed'
23
+ )
24
+
25
+ options = {
26
+ overrideUnsubscribe: true,
27
+ eventIds: event_ids
28
+ }.compact
29
+
30
+ Listrak.email.contacts.upsert list_id, contact, options
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ module Workarea
2
+ module Listrak
3
+ class UnsubscribeEmailSignup
4
+ include Sidekiq::Worker
5
+ include Sidekiq::CallbacksWorker
6
+
7
+ sidekiq_options(
8
+ enqueue_on: {
9
+ Email::Signup => :destroy,
10
+ with: -> { [email] }
11
+ },
12
+ queue: "low",
13
+ retry: true
14
+ )
15
+
16
+ def perform(email)
17
+ contact = Listrak::Models::ContactForm.new(
18
+ email: email,
19
+ subscription_state: 'Unsubscribed'
20
+ )
21
+
22
+ list_id = Listrak.configuration.default_list_id
23
+ Listrak.email.contacts.upsert list_id, contact, overrideUnsubscribe: true
24
+ end
25
+ end
26
+ end
27
+ end
data/bin/rails ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path("../..", __FILE__)
6
+ ENGINE_PATH = File.expand_path("../../lib/workarea/listrak/engine", __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
10
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
11
+
12
+ require "action_controller/railtie"
13
+ require "action_view/railtie"
14
+ require "action_mailer/railtie"
15
+ require "rails/test_unit/railtie"
16
+ require "sprockets/railtie"
17
+
18
+ require "rails/engine/commands"
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,28 @@
1
+ # Analytics adapter for Listrak tag management
2
+ Workarea::Plugin.append_javascripts(
3
+ "storefront.modules",
4
+ "workarea/storefront/listrak/adapters/listrak_adapter",
5
+ "workarea/storefront/listrak/modules/listrak"
6
+ )
7
+
8
+ # Pass configuration for the Listrak adapter to the client-side
9
+ Workarea::Plugin.append_javascripts(
10
+ "storefront.config",
11
+ "workarea/storefront/listrak/listrak_config"
12
+ )
13
+
14
+ Workarea::Plugin.append_javascripts(
15
+ "admin.modules",
16
+ "workarea/admin/modules/listrak/list_events_select"
17
+ )
18
+
19
+ # Tracking pixel for checkout conversion tracking
20
+ Workarea::Plugin.append_javascripts(
21
+ "storefront.checkout_confirmation",
22
+ "workarea/storefront/checkouts/listrak"
23
+ )
24
+
25
+ Workarea.append_partials(
26
+ "admin.settings_menu",
27
+ "workarea/admin/shared/listrak_configuration_link"
28
+ )
@@ -0,0 +1,8 @@
1
+ Workarea.configure do |config|
2
+ config.listrak = ActiveSupport::Configurable::Configuration.new
3
+
4
+ config.listrak.analytics = {
5
+ merchant_id: nil,
6
+ email_capture_ids: nil
7
+ }
8
+ end
@@ -0,0 +1,17 @@
1
+ en:
2
+ workarea:
3
+ admin:
4
+ listrak_configuration:
5
+ edit:
6
+ flash_messages:
7
+ updated: Listrak configuration has been updated
8
+ save_error: There was a problem updating the configuration
9
+ title: Listrak Configuration
10
+ default_list: Default List
11
+ external_events: External Events
12
+ events_select_placeholder: Choose external events
13
+ event_itds_tooltip: External event ids to trigger when subscribing the customer
14
+ button: Save Listrak Configuration
15
+ shared:
16
+ primary_nav:
17
+ listrak_configuration_title: Listrak Configuration
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ Workarea::Admin::Engine.routes.draw do
2
+ scope '(:locale)', constraints: Workarea::I18n.routes_constraint do
3
+ namespace :listrak do
4
+ resource :configuration, only: [:edit, :update]
5
+ resources :lists, only: [] do
6
+ resources :events, only: :index
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates the class that kicks off a new transactional email to
3
+ Listrak for delivery.
4
+
5
+ Example:
6
+ rails generate workarea:listrak:message BackorderConfirmation
7
+
8
+ This will create:
9
+ app/messages/workarea/backorder_confirmation_message.rb
@@ -0,0 +1,15 @@
1
+ module Workarea
2
+ module Listrak
3
+ # Generate new Message classes for your host app (or plugin).
4
+ class MessageGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_agent
8
+ template(
9
+ "message.rb.erb",
10
+ "app/messages/workarea/#{file_name}_message.rb"
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module Workarea
2
+ class <%= class_name %>Message
3
+ include Listrak::TransactionalMessage
4
+
5
+ # message_id 45678
6
+ # message_attributes(
7
+ # name: 12345
8
+ # )
9
+ #
10
+ # def initialize(order)
11
+ # @order = order
12
+ # end
13
+ #
14
+ # def name
15
+ # "#{@order.first_name} #{@order.last_name}"
16
+ # end
17
+
18
+ private
19
+
20
+ def email_address
21
+ # TODO
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ module Listrak
3
+ module Analytics
4
+ # Shorthand for analytics module specific configuration.
5
+ def self.config
6
+ Workarea.config.listrak.analytics
7
+ end
8
+
9
+ def self.javascript_config
10
+ {
11
+ merchantId: config[:merchant_id],
12
+ emailIds: config[:email_capture_ids]
13
+ }.compact.to_json
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusDataApi::Customers
4
+ def import(_customers)
5
+ return "12345"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusDataApi::Orders
4
+ def import(_orders)
5
+ return "12345"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusDataApi::Products
4
+ def import(_products)
5
+ return "12345"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusDataApi
4
+ class ProxyClient
5
+ attr_reader :client_name, :client
6
+
7
+ def initialize(client_name, client)
8
+ @client_name = client_name
9
+ @client = client
10
+ end
11
+
12
+ def method_missing(method, *args)
13
+ if client.respond_to?(method)
14
+ if BogusDataApi.store_requests
15
+ BogusDataApi.requests[client_name][method] << args
16
+ end
17
+ client.send(method, *args)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def respond_to_missing?(method, include_all = false)
24
+ client.respond_to?(method) || super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ module Workarea
2
+ module Listrak
3
+ # @!visibility private
4
+ class BogusDataApi
5
+ require 'workarea/listrak/bogus_data_api/proxy_client'
6
+ require 'workarea/listrak/bogus_data_api/products'
7
+ require 'workarea/listrak/bogus_data_api/customers'
8
+ require 'workarea/listrak/bogus_data_api/orders'
9
+
10
+ thread_cattr_accessor :requests, :store_requests
11
+
12
+ def self.reset_requests!
13
+ self.requests = Hash.new do |client_hash, client_class|
14
+ client_hash[client_class] = Hash.new do |method_hash, method_name|
15
+ method_hash[method_name] = []
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.total_request_count
21
+ self.requests.sum do |client, method_calls|
22
+ method_calls.sum { |_method, calls| calls.size }
23
+ end
24
+ end
25
+
26
+ self.store_requests = false
27
+ self.reset_requests!
28
+
29
+ def method_missing(method)
30
+ client_class = client(method)
31
+
32
+ if client_class
33
+ ProxyClient.new(method, client_class.new)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def client(client_name)
42
+ BogusDataApi.const_get(client_name.to_s.camelize) rescue nil
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusEmailApi::Contacts
4
+ def upsert(_list_id, _contact_form, _options = {})
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusEmailApi::Events
4
+ def all(_list_id)
5
+ events = [
6
+ {
7
+ "eventId" => 12714,
8
+ "eventName" => "Test",
9
+ "eventGroupId" => 0,
10
+ "status" => "Active"
11
+ },
12
+ {
13
+ "eventId" => 12715,
14
+ "eventName" => "footer signup",
15
+ "eventGroupId" => 0,
16
+ "status" => "Active"
17
+ }
18
+ ]
19
+ events.map { |event| Listrak::Models::Event.new event }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusEmailApi::Lists
4
+ def all
5
+ lists = [
6
+ {
7
+ "listId" => 349956,
8
+ "listName" => "My First List",
9
+ "folderId" => 0,
10
+ "ipPoolId" => 11,
11
+ "bounceDomainAlias" => "",
12
+ "bounceHandling" => "Standard",
13
+ "bounceUnsubscribeCount" => 5,
14
+ "createDate" => "2015-08-31T16:02:41.65",
15
+ "enableBrowserLink" => false,
16
+ "enableDoubleOptIn" => false,
17
+ "enableDynamicContent" => false,
18
+ "enableGoogleAnalytics" => false,
19
+ "enableInternationalization" => false,
20
+ "enableListHygiene" => true,
21
+ "enableListRemovalHeader" => true,
22
+ "enableListRemovalLink" => true,
23
+ "enableListrakAnalytics" => false,
24
+ "enableSpamScorePersonalization" => false,
25
+ "enableToNamePersonalization" => false,
26
+ "fromEmail" => "",
27
+ "fromName" => "",
28
+ "googleTrackingDomains" => [],
29
+ "linkDomainAlias" => "",
30
+ "mediaDomainAlias" => ""
31
+ },
32
+ {
33
+ "listId" => 349984,
34
+ "listName" => "gem-testing",
35
+ "folderId" => 0,
36
+ "ipPoolId" => 11,
37
+ "bounceDomainAlias" => "",
38
+ "bounceHandling" => "Standard",
39
+ "bounceUnsubscribeCount" => 5,
40
+ "createDate" => "2015-09-02T14:42:38.91",
41
+ "enableBrowserLink" => false,
42
+ "enableDoubleOptIn" => false,
43
+ "enableDynamicContent" => false,
44
+ "enableGoogleAnalytics" => false,
45
+ "enableInternationalization" => false,
46
+ "enableListHygiene" => true,
47
+ "enableListRemovalHeader" => true,
48
+ "enableListRemovalLink" => true,
49
+ "enableListrakAnalytics" => false,
50
+ "enableSpamScorePersonalization" => false,
51
+ "enableToNamePersonalization" => false,
52
+ "fromEmail" => "mac@weblinc.com",
53
+ "fromName" => "WebLinc Developer",
54
+ "googleTrackingDomains" => [],
55
+ "linkDomainAlias" => "",
56
+ "mediaDomainAlias" => ""
57
+ }
58
+ ]
59
+ lists.map { |list| Listrak::Models::List.new list }
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,29 @@
1
+ module Workarea
2
+ module Listrak
3
+ class BogusEmailApi
4
+ class ProxyClient
5
+ attr_reader :client_name, :client
6
+
7
+ def initialize(client_name, client)
8
+ @client_name = client_name
9
+ @client = client
10
+ end
11
+
12
+ def method_missing(method, *args)
13
+ if client.respond_to?(method)
14
+ if BogusEmailApi.store_requests
15
+ BogusEmailApi.requests[client_name][method] << args
16
+ end
17
+ client.send(method, *args)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def respond_to_missing?(method, include_all = false)
24
+ client.respond_to?(method) || super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end