Class: MonkeyParty::List

Inherits:
Base
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/monkey_party/list.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, default_options, get, #initialize

Constructor Details

This class inherits a constructor from MonkeyParty::Base

Class Method Details

.allObject



67
68
69
70
71
72
73
74
# File 'lib/monkey_party/list.rb', line 67

def all
  response = get("/", :query => {
    :apikey => api_key,
    :method => "lists"
  })

  parse(response.body)
end

.find_by_name(name) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/monkey_party/list.rb', line 76

def find_by_name(name)
  all.each do |list|
    return list if list.name.downcase == name.downcase
  end

  return nil
end

Instance Method Details

#create_subscribers(array_of_subscribers, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/monkey_party/list.rb', line 12

def create_subscribers(array_of_subscribers, options = {})
  options = {
    :double_optin => true,
    :update_existing => false,
    :replace_interests => true
  }.merge(options)
  
  batch_hash = {}
  index = 0
  array_of_subscribers.each do |s|
    batch_hash["batch[#{index}]"] = s.to_mailchimp_hash
    index += 1
  end

  response = self.class.get("/", :query => {
     :apikey            => self.class.api_key,
     :id                => self.id,
     :method            => "listBatchSubscribe",
  }.merge(options).merge(batch_hash))

  #response[1] is the error count
  if !response["MCAPI"].nil? && 
    attach_errors_to_subscribers(array_of_subscribers, response.body)
  end

  array_of_subscribers
end

#destroy_subscribers(array_of_unsubscribers, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/monkey_party/list.rb', line 40

def destroy_subscribers(array_of_unsubscribers, options = {})
  options = {
    :delete_member => false,
    :send_goodbye  => true,
    :send_notify   => false
  }.merge(options)

  batch_hash = {}
  index = 0
  array_of_unsubscribers.each do |s|
    batch_hash["emails[#{index}]"] = s.email
  end

  response = self.class.get("/", :query => {
    :apikey => self.class.api_key,
    :id => self.id,
    :method => "listBatchUnsubscribe"
  }.merge(options).merge(batch_hash))

  if !response["MCAPI"].nil?
    attach_errors_to_subscribers(array_of_unsubscribers, response.body)
  end

  array_of_unsubscribers
end