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.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +15 -0
  3. data/.gitignore +55 -0
  4. data/.markdownlint.json +10 -0
  5. data/.rails-rubocop.yml +119 -0
  6. data/.rubocop.yml +8 -0
  7. data/.scss-lint.yml +188 -0
  8. data/CHANGELOG.md +244 -0
  9. data/Gemfile +9 -0
  10. data/README.md +115 -0
  11. data/Rakefile +53 -0
  12. data/app/assets/javascripts/workarea/storefront/mail_chimp/mail_chimp_tracking.js +15 -0
  13. data/app/controllers/workarea/storefront/application_controller.decorator +11 -0
  14. data/app/controllers/workarea/storefront/cart_items_controller.decorator +18 -0
  15. data/app/controllers/workarea/storefront/checkout/addresses_controller.decorator +13 -0
  16. data/app/controllers/workarea/storefront/checkout/shipping_controller.decorator +13 -0
  17. data/app/controllers/workarea/storefront/users/accounts_controller.decorator +37 -0
  18. data/app/models/workarea/catalog/product.decorator +7 -0
  19. data/app/models/workarea/mail_chimp/group.rb +39 -0
  20. data/app/models/workarea/mail_chimp/store.rb +26 -0
  21. data/app/models/workarea/order.decorator +9 -0
  22. data/app/models/workarea/user.decorator +31 -0
  23. data/app/services/workarea/mail_chimp/address.rb +28 -0
  24. data/app/services/workarea/mail_chimp/cart.rb +78 -0
  25. data/app/services/workarea/mail_chimp/order.rb +97 -0
  26. data/app/services/workarea/mail_chimp/product.rb +43 -0
  27. data/app/services/workarea/mail_chimp/variant.rb +43 -0
  28. data/app/view_models/workarea/storefront/user_view_model.decorator +16 -0
  29. data/app/views/workarea/storefront/mail_chimp/_ecommerce_javascript.html.haml +2 -0
  30. data/app/views/workarea/storefront/users/accounts/_edit.html.haml +12 -0
  31. data/app/views/workarea/storefront/users/accounts/_email_interests.html.haml +13 -0
  32. data/app/workers/workarea/mail_chimp/ecommerce/save_cart.rb +40 -0
  33. data/app/workers/workarea/mail_chimp/ecommerce/save_order.rb +31 -0
  34. data/app/workers/workarea/mail_chimp/ecommerce/save_product.rb +31 -0
  35. data/app/workers/workarea/mail_chimp/list_subscriber.rb +30 -0
  36. data/app/workers/workarea/mail_chimp/list_unsubscriber.rb +22 -0
  37. data/app/workers/workarea/mail_chimp/subscription_edit.rb +28 -0
  38. data/bin/rails +19 -0
  39. data/config/initializers/appends.rb +21 -0
  40. data/config/initializers/workarea.rb +14 -0
  41. data/config/locales/en.yml +15 -0
  42. data/lib/gibbon/request_decorator.rb +10 -0
  43. data/lib/integrations/workarea/mail_chimp/bogus_api_request.rb +30 -0
  44. data/lib/integrations/workarea/mail_chimp/bogus_gateway.rb +35 -0
  45. data/lib/integrations/workarea/mail_chimp/bogus_request.rb +78 -0
  46. data/lib/integrations/workarea/mail_chimp/gateway.rb +86 -0
  47. data/lib/integrations/workarea/mail_chimp/gateway/list.rb +47 -0
  48. data/lib/integrations/workarea/mail_chimp/gateway/members.rb +61 -0
  49. data/lib/integrations/workarea/mail_chimp/gateway/subscribe_argument_builder.rb +101 -0
  50. data/lib/tasks/mail_chimp.rake +71 -0
  51. data/lib/workarea/mail_chimp.rb +72 -0
  52. data/lib/workarea/mail_chimp/engine.rb +14 -0
  53. data/lib/workarea/mail_chimp/errors.rb +2 -0
  54. data/lib/workarea/mail_chimp/tasks/ecommerce.rb +43 -0
  55. data/lib/workarea/mail_chimp/version.rb +5 -0
  56. data/script/admin_ci +9 -0
  57. data/script/ci +11 -0
  58. data/script/core_ci +9 -0
  59. data/script/plugins_ci +9 -0
  60. data/script/storefront_ci +9 -0
  61. data/test/dummy/Rakefile +6 -0
  62. data/test/dummy/app/assets/config/manifest.js +4 -0
  63. data/test/dummy/app/assets/images/.keep +0 -0
  64. data/test/dummy/app/assets/javascripts/application.js +13 -0
  65. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  66. data/test/dummy/app/controllers/application_controller.rb +3 -0
  67. data/test/dummy/app/controllers/concerns/.keep +0 -0
  68. data/test/dummy/app/helpers/application_helper.rb +2 -0
  69. data/test/dummy/app/jobs/application_job.rb +2 -0
  70. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  71. data/test/dummy/app/models/concerns/.keep +0 -0
  72. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  74. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  75. data/test/dummy/bin/bundle +3 -0
  76. data/test/dummy/bin/rails +4 -0
  77. data/test/dummy/bin/rake +4 -0
  78. data/test/dummy/bin/setup +34 -0
  79. data/test/dummy/bin/update +29 -0
  80. data/test/dummy/config.ru +5 -0
  81. data/test/dummy/config/application.rb +23 -0
  82. data/test/dummy/config/boot.rb +5 -0
  83. data/test/dummy/config/cable.yml +9 -0
  84. data/test/dummy/config/environment.rb +5 -0
  85. data/test/dummy/config/environments/development.rb +56 -0
  86. data/test/dummy/config/environments/production.rb +86 -0
  87. data/test/dummy/config/environments/test.rb +43 -0
  88. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  89. data/test/dummy/config/initializers/assets.rb +11 -0
  90. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  91. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  92. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  93. data/test/dummy/config/initializers/inflections.rb +16 -0
  94. data/test/dummy/config/initializers/mime_types.rb +4 -0
  95. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  96. data/test/dummy/config/initializers/session_store.rb +3 -0
  97. data/test/dummy/config/initializers/workarea.rb +5 -0
  98. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/test/dummy/config/locales/en.yml +23 -0
  100. data/test/dummy/config/puma.rb +47 -0
  101. data/test/dummy/config/routes.rb +5 -0
  102. data/test/dummy/config/secrets.yml +22 -0
  103. data/test/dummy/config/spring.rb +6 -0
  104. data/test/dummy/db/seeds.rb +2 -0
  105. data/test/dummy/lib/assets/.keep +0 -0
  106. data/test/factories/mail_chimp.rb +50 -0
  107. data/test/integration/workarea/mailchimp/subscription_test.rb +52 -0
  108. data/test/integration/workarea/mailchimp/tracking_params_test.rb +50 -0
  109. data/test/integration/workarea/mailchimp/unsubscribe_test.rb +14 -0
  110. data/test/integration/workarea/storefront/mail_chimp_order_test.rb +106 -0
  111. data/test/integration/workarea/storefront/mail_chimp_product_test.rb +51 -0
  112. data/test/integration/workarea/storefront/mail_chimp_site_javascript_test.rb +25 -0
  113. data/test/lib/workarea/mailchimp/gateway/list_test.rb +48 -0
  114. data/test/lib/workarea/mailchimp/gateway_test.rb +196 -0
  115. data/test/lib/workarea/mailchimp/tasks/ecommerce_test.rb +40 -0
  116. data/test/services/workarea/mail_chimp/cart_test.rb +44 -0
  117. data/test/services/workarea/mail_chimp/order_test.rb +50 -0
  118. data/test/services/workarea/mail_chimp/product_test.rb +29 -0
  119. data/test/support/workarea/mail_chimp_api_config.rb +33 -0
  120. data/test/system/workarea/storefront/campaign_tracking_test.rb +14 -0
  121. data/test/system/workarea/storefront/group_test.rb +33 -0
  122. data/test/system/workarea/storefront/mail_chimp_accounts_system_test.rb +79 -0
  123. data/test/test_helper.rb +17 -0
  124. data/test/vcr_cassettes/get_default_list_interests.yml +104 -0
  125. data/test/vcr_cassettes/get_member_details_no_match.yml +51 -0
  126. data/test/vcr_cassettes/get_member_details_unsubscribed.yml +51 -0
  127. data/test/vcr_cassettes/interest_categories_read.yml +104 -0
  128. data/test/vcr_cassettes/mail_chimp/tasks/create_store-successful.yml +97 -0
  129. data/test/vcr_cassettes/mc_order_test.yml +381 -0
  130. data/test/vcr_cassettes/mc_product_test.yml +234 -0
  131. data/test/vcr_cassettes/subscribe_to_default_list.yml +254 -0
  132. data/test/vcr_cassettes/subscribe_to_default_list_interest_groups.yml +254 -0
  133. data/test/vcr_cassettes/subscribe_to_default_list_with_groupings.yml +254 -0
  134. data/test/vcr_cassettes/subscribe_to_default_list_with_user_details.yml +254 -0
  135. data/test/vcr_cassettes/unsubscribe_from_default_list.yml +53 -0
  136. data/test/vcr_cassettes/update_member_on_default_list_change_email.yml +254 -0
  137. data/test/vcr_cassettes/update_member_on_default_list_change_groupings.yml +254 -0
  138. data/test/workers/workarea/mail_chimp/ecommerce/save_cart_test.rb +28 -0
  139. data/test/workers/workarea/mail_chimp/ecommerce/save_order_test.rb +15 -0
  140. data/test/workers/workarea/mail_chimp/ecommerce/save_product_test.rb +15 -0
  141. data/workarea-mail_chimp.gemspec +20 -0
  142. metadata +212 -0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "workarea", source: "https://gems.weblinc.com"
6
+
7
+ group :test, :development do
8
+ gem "simplecov", require: false
9
+ end
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ Workarea Mail Chimp
2
+ ================================================================================
3
+
4
+ MailChimp plugin for the Worakrea e-commerce platform
5
+
6
+ This plugin creates a basic integration between the WebLinc platform and
7
+ MailChimp's v3 API
8
+
9
+ It requires a mailchimp access token which can be generated by following
10
+ MailChimp's OAuth2 Flow here: <http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/>
11
+
12
+ Scope and Dependencies
13
+ --------------------------------------------------------------------------------
14
+
15
+ This plugin currently wraps functionality for subscribing and unsubscribing users
16
+ by email, as well as retrieving interest groups (or categories) for users and lists
17
+
18
+ It is dependant on the [gibbon rubygem](https://github.com/amro/gibbon) which
19
+ provides a basic wrapper for the MailChimp v3 API.
20
+
21
+ Configuration
22
+ --------------------------------------------------------------------------------
23
+
24
+ This plugin requires gateway configuration in order to function.
25
+
26
+ In your secrets file:
27
+
28
+ mail_chimp:
29
+ :api_key: APIKEY
30
+ :default_list_id: LIST_ID
31
+ :list_preferences_id: LIST_PREFERENCES_ID
32
+
33
+ ### To find your default list ID, in the mailchimp admin:
34
+
35
+ 1. Go to the list you wish to use
36
+ 2. Click the settings dropdown menu
37
+ 3. Choose the 'List name and defaults' menu item
38
+ 4. You will find the List ID on this page, at the time of writing it is displayed
39
+ at the top left of the page.
40
+
41
+ ### To find your list preferences ID via the API playground:
42
+
43
+ 1. Visit [API playground](https://us16.api.mailchimp.com/playground/)
44
+ 2. Enter your API key
45
+ 3. Click on the 'Lists' Link
46
+ 4. Find the subresources dropdown for your default list
47
+ 5. Choose 'interest-categories' from the subresources dropdown
48
+ 6. Click the name of your interest group
49
+ 7. Use the ID field shown in the details section, the 'list_id' field should
50
+ correspond with your default_list_id
51
+
52
+ Testing & Maintenance
53
+ --------------------------------------------------------------------------------
54
+
55
+ Ensure that the gateway credentials within application secrets are set in
56
+ `spec/dummy/config/secrets.yml` for test mode
57
+
58
+ To get specs to pass, you will need to configure a MailChimp account with the
59
+ following data
60
+
61
+ * A group/category with the same information as what is configured in
62
+ `HelperMethods#email_all_interests_hash` in `spec/fixtures/helper_methods.rb`
63
+
64
+ * A user that was unsubscribed with the following email: `test-unsubscribed@weblinc.com`
65
+
66
+ * A subscribed user with the following email: `mdalton-simonpearce@weblinc.com`
67
+
68
+ The specs use VCR cassettes to record http requests, so maintainers will need to
69
+ flush the cassettes when modifying the requests.
70
+
71
+ Getting Started
72
+ --------------------------------------------------------------------------------
73
+
74
+ This gem contains a rails engine that must be mounted onto a host Rails application.
75
+
76
+ You must have access to a WebLinc gems server to use this gem. Add your gems
77
+ server credentials to Bundler:
78
+
79
+ bundle config gems.weblinc.com my_username:my_password
80
+
81
+ Or set the appropriate environment variable in a shell startup file:
82
+
83
+ export BUNDLE_GEMS__WEBLINC__COM='my_username:my_password'
84
+
85
+ Then add the gem to your application's Gemfile specifying the source:
86
+
87
+ # ...
88
+ gem 'workarea-mail_chimp', source: 'https://gems.weblinc.com'
89
+ # ...
90
+
91
+ Or use a source block:
92
+
93
+ # ...
94
+ source 'https://gems.weblinc.com' do
95
+ gem 'workarea-mail_chimp'
96
+ end
97
+ # ...
98
+
99
+ Update your application's bundle.
100
+
101
+ cd path/to/application
102
+ bundle
103
+
104
+ WebLinc Platform Documentation
105
+ --------------------------------------------------------------------------------
106
+
107
+ See [http://developer.weblinc.com](http://developer.weblinc.com) for Workarea
108
+ platform documentation.
109
+
110
+ Copyright & Licensing
111
+ --------------------------------------------------------------------------------
112
+
113
+ Copyright WebLinc 2015. All rights reserved.
114
+
115
+ For licensing, contact sales@weblinc.com.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require "bundler/setup"
4
+ rescue LoadError
5
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6
+ end
7
+
8
+ require "rdoc/task"
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = "rdoc"
12
+ rdoc.title = "Tasker"
13
+ rdoc.options << "--line-numbers"
14
+ rdoc.rdoc_files.include("README.md")
15
+ rdoc.rdoc_files.include("lib/**/*.rb")
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
19
+ load "rails/tasks/engine.rake"
20
+ load "rails/tasks/statistics.rake"
21
+ load "workarea/changelog.rake"
22
+
23
+ require "rake/testtask"
24
+
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.libs << "lib"
27
+ t.libs << "test"
28
+ t.pattern = "test/**/*_test.rb"
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
33
+
34
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
35
+ require "workarea/mail_chimp/version"
36
+
37
+ desc "Release version #{Workarea::MailChimp::VERSION} of the gem"
38
+ task :release do
39
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
40
+
41
+ #Rake::Task["workarea:changelog"].execute
42
+ #system "git add CHANGELOG.md"
43
+ #system 'git commit -m "Update CHANGELOG"'
44
+ #system "git push origin HEAD"
45
+
46
+ system "git tag -a v#{Workarea::MailChimp::VERSION} -m 'Tagging #{Workarea::MailChimp::VERSION}'"
47
+ system "git push --tags"
48
+
49
+ system "gem build workarea-mail_chimp.gemspec"
50
+ system "gem push workarea-mail_chimp-#{Workarea::MailChimp::VERSION}.gem"
51
+ system "gem push workarea-mail_chimp-#{Workarea::MailChimp::VERSION}.gem --host #{host}"
52
+ system "rm workarea-mail_chimp-#{Workarea::MailChimp::VERSION}.gem"
53
+ end
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @namespace WORKAREA.mailchimpTracking
3
+ */
4
+ WORKAREA.registerModule('mailchimpTracking', (function () {
5
+ 'use strict';
6
+
7
+ var setCookie = function() {
8
+ var tracking_value = WORKAREA.url.parse(document.URL).queryKey.mc_cid;
9
+
10
+ if (_.isUndefined(tracking_value)) { return; }
11
+
12
+ WORKAREA.cookie.create('mc_cid', tracking_value, 30);
13
+ };
14
+ setCookie();
15
+ }()));
@@ -0,0 +1,11 @@
1
+ module Workarea
2
+ module Storefront
3
+ decorate ApplicationController, with: :mail_chimp do
4
+ def current_order
5
+ super.tap do |order|
6
+ order.mail_chimp_campaign_id = cookies[:mc_cid]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Workarea
2
+ decorate Storefront::CartItemsController, with: :mail_chimp do
3
+ decorated do
4
+ after_action :sync_with_mailchimp, only: [:create, :update]
5
+ end
6
+
7
+ def destroy
8
+ super
9
+ Workarea::MailChimp::Ecommerce::SaveCart.perform_async(current_order.id, deleted_item_id: params[:id])
10
+ end
11
+
12
+ private
13
+
14
+ def sync_with_mailchimp
15
+ Workarea::MailChimp::Ecommerce::SaveCart.perform_async(current_order.id, { })
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Workarea
2
+ decorate Storefront::Checkout::AddressesController, with: :mail_chimp do
3
+ decorated do
4
+ after_action :sync_with_mailchimp, only: [:update_addresses]
5
+ end
6
+
7
+ private
8
+
9
+ def sync_with_mailchimp
10
+ Workarea::MailChimp::Ecommerce::SaveCart.perform_async(current_order.id)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Workarea
2
+ decorate Storefront::Checkout::ShippingController, with: :mail_chimp do
3
+ decorated do
4
+ after_action :sync_with_mailchimp, only: [:update_shipping]
5
+ end
6
+
7
+ private
8
+
9
+ def sync_with_mailchimp
10
+ Workarea::MailChimp::Ecommerce::SaveCart.perform_async(current_order.id)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module Workarea
2
+ decorate Storefront::Users::AccountsController, with: :mail_chimp do
3
+ decorated { before_action :set_email_interests, only: :edit }
4
+
5
+ private
6
+
7
+ def user_params
8
+ @user_params ||= super
9
+ .merge(params.permit(:email_signup, :groups))
10
+ .merge(sanitize_groups_param(params))
11
+ end
12
+
13
+ def sanitize_groups_param(params)
14
+ @sanitize_groups_param ||= Hash[
15
+ :groups,
16
+ params.fetch(:groups, []).map do |group|
17
+ {
18
+ _id: group[:id],
19
+ name: group[:name],
20
+ interests: group[:interests].to_unsafe_hash
21
+ }
22
+ end
23
+ ]
24
+ end
25
+
26
+ def set_email_interests
27
+ key = "mail_chimp_email_interests/#{Workarea::MailChimp.config.default_store[:list_id]}"
28
+ options = { expires_in: 1.hour }
29
+
30
+ options.merge!(force: true) if Rails.cache.read(key).nil?
31
+
32
+ @email_interests = Rails.cache.fetch(key, options) do
33
+ Workarea::MailChimp.gateway.list.interests
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Workarea
2
+ decorate Catalog::Product, with: :mail_chimp do
3
+ decorated do
4
+ field :exported_to_mail_chimp_at, type: Time
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ module Workarea
2
+ module MailChimp
3
+ class Group
4
+ include ApplicationDocument
5
+
6
+ field :_id, type: String
7
+ field :name, type: String
8
+ field :interests, type: Hash
9
+
10
+ embedded_in :user, class_name: "Workarea::User"
11
+
12
+ validate :id_or_name
13
+
14
+ def self.email_interests
15
+ MailChimp.gateway.get_default_list_interests.first
16
+ end
17
+
18
+ def to_hash
19
+ [_id, name, interests].hash
20
+ end
21
+
22
+ def to_s
23
+ "#{name} (#{id}) - #{interests}"
24
+ end
25
+
26
+ def ==(other)
27
+ self.name == other[:name] && self.interests == other[:interests]
28
+ end
29
+
30
+ private
31
+
32
+ def id_or_name
33
+ unless id.present? || name.present?
34
+ self.errors[:base] << "An ID or Name is Required."
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module Workarea
2
+ module MailChimp
3
+ class Store
4
+ include ApplicationDocument
5
+
6
+ field :mail_chimp_id, type: String
7
+ field :list_id, type: String
8
+ field :name, type: String
9
+ field :currency_code, type: String
10
+ field :connected_site, type: Hash
11
+
12
+ index mail_chimp_id: 1
13
+
14
+ def self.with_syncing_enabled(&block)
15
+ MailChimp.request.ecommerce.stores(Workarea::MailChimp.config.default_store[:id]).update(body: { is_syncing: true })
16
+ block.call
17
+ ensure
18
+ MailChimp.request.ecommerce.stores(Workarea::MailChimp.config.default_store[:id]).update(body: { is_syncing: false })
19
+ end
20
+
21
+ def site_script_fragment
22
+ connected_site.dig("site_script", "fragment")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ decorate Order, with: :mail_chimp do
3
+ decorated do
4
+ field :mail_chimp_campaign_id, type: String
5
+ field :exported_to_mail_chimp_at, type: Time
6
+ field :cart_exported_to_mail_chimp_at, type: Time
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ module Workarea
2
+ decorate User, with: :mail_chimp do
3
+ class_methods do
4
+ def default_groups
5
+ Workarea::MailChimp.gateway.interests
6
+ end
7
+ end
8
+
9
+ decorated do
10
+ before_validation :check_email_signup
11
+ before_save :default_groups_if_empty
12
+
13
+ field :email_signup, type: Boolean, default: false
14
+ embeds_many :groups, class_name: "Workarea::MailChimp::Group"
15
+ end
16
+
17
+ private
18
+
19
+ def check_email_signup
20
+ self.email_signup ||= Workarea::Email.signed_up?(self.email)
21
+ end
22
+
23
+ def default_groups_if_empty
24
+ return unless has_attribute?("email_signup")
25
+
26
+ if self.groups.empty? && self.email_signup?
27
+ self.groups = User.default_groups
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module Workarea
2
+ module MailChimp
3
+ class Address
4
+
5
+ attr_reader :address, :options
6
+
7
+ def initialize(address, options = {})
8
+ @address = address
9
+ @options = options
10
+ end
11
+
12
+ # @return Hash
13
+ def to_h
14
+ {
15
+ name: address.first_name + " " + address.last_name,
16
+ address1: address.street,
17
+ address2: address.street_2.to_s,
18
+ city: address.city,
19
+ province: address.region.to_s,
20
+ postal_code: address.postal_code.to_s,
21
+ country: address.country.alpha2,
22
+ phone: address.phone_number.to_s,
23
+ company: address.company.to_s
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end