Module: EffectiveMailchimp

Includes:
EffectiveGem
Defined in:
lib/effective_mailchimp.rb,
lib/effective_mailchimp/engine.rb,
lib/effective_mailchimp/version.rb,
lib/generators/effective_mailchimp/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

VERSION =
'0.9.1'.freeze

Class Method Summary collapse

Class Method Details

.apiObject



18
19
20
# File 'lib/effective_mailchimp.rb', line 18

def self.api
  Effective::MailchimpApi.new(api_key: api_key)
end

.api_blank?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/effective_mailchimp.rb', line 30

def self.api_blank?
  api_key.blank?
end

.api_present?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/effective_mailchimp.rb', line 26

def self.api_present?
  api_key.present?
end

.config_keysObject



8
9
10
11
12
13
14
# File 'lib/effective_mailchimp.rb', line 8

def self.config_keys
  [
    :mailchimp_lists_table_name, :mailchimp_list_members_table_name, :mailchimp_categories_table_name, :mailchimp_interests_table_name,
    :layout,
    :api_key, :sandbox_mode, :user_class_name
  ]
end

.lists_blank?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/effective_mailchimp.rb', line 38

def self.lists_blank?
  Effective::MailchimpList.all.count == 0
end

.lists_present?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/effective_mailchimp.rb', line 34

def self.lists_present?
  Effective::MailchimpList.all.count > 0
end

.merge_fieldsObject



53
54
55
56
57
# File 'lib/effective_mailchimp.rb', line 53

def self.merge_fields
  merge_fields = self.User().new.mailchimp_merge_fields
  raise('expected a Hash of merge fields') unless merge_fields.kind_of?(Hash)
  merge_fields
end

.permitted_paramsObject



59
60
61
# File 'lib/effective_mailchimp.rb', line 59

def self.permitted_params
  [ :mailchimp_user_form_action, mailchimp_list_members_attributes: [:id, :mailchimp_list_id, :subscribed, interests: []] ]
end

.sandbox_mode?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/effective_mailchimp.rb', line 22

def self.sandbox_mode?
  !!sandbox_mode
end

.supressed(&block) ⇒ Object



68
69
70
71
72
73
# File 'lib/effective_mailchimp.rb', line 68

def self.supressed(&block)
  Thread.current[:effective_mailchimp_supressed] = true
  value = yield
  Thread.current[:effective_mailchimp_supressed] = nil
  value
end

.supressed=(value) ⇒ Object

Used to supress any background jobs during import processes



64
65
66
# File 'lib/effective_mailchimp.rb', line 64

def self.supressed=(value)
  Thread.current[:effective_mailchimp_supressed] = value
end

.supressed?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/effective_mailchimp.rb', line 75

def self.supressed?
  Thread.current[:effective_mailchimp_supressed] == true
end

.UserObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/effective_mailchimp.rb', line 42

def self.User
  klass = user_class_name.constantize if user_class_name.present?
  klass ||= Tenant.User if defined?(Tenant)
  klass ||= '::User'.safe_constantize

  raise('unable to determine User klass. Please set config.user_class_name') unless klass.kind_of?(Class)
  raise('expecting an effective_mailchimp_user User class') unless klass.respond_to?(:effective_mailchimp_user)

  klass
end