Class: Hominid::List
- Inherits:
-
Base
- Object
- Base
- Hominid::List
show all
- Defined in:
- lib/hominid/list.rb
Constant Summary
Constants inherited
from Base
Base::MAILCHIMP_API_VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#create_group(group) ⇒ Object
(also: #interest_group_add)
-
#create_tag(tag, name, required = false) ⇒ Object
(also: #merge_var_add)
-
#delete_group(group) ⇒ Object
(also: #interest_group_del)
-
#delete_tag(tag) ⇒ Object
(also: #merge_var_del)
-
#groups ⇒ Object
(also: #interest_groups)
-
#initialize(*args) ⇒ List
constructor
-
#member_info(email) ⇒ Object
-
#members(status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100) ⇒ Object
-
#merge_tags ⇒ Object
(also: #merge_vars)
-
#subscribe(email, options = {}) ⇒ Object
-
#subscribe_many(subscribers, options = {}) ⇒ Object
(also: #batch_subscribe)
-
#unsubscribe(current_email, options = {}) ⇒ Object
-
#unsubscribe_many(emails, options = {}) ⇒ Object
(also: #batch_unsubscribe)
-
#update_member(current_email, merge_tags = {}, email_type = "html", replace_interests = true) ⇒ Object
Methods inherited from Base
#add_api_key, #api_keys, #apply_defaults_to, #call, #clean_merge_tags, #expire_api_key
Constructor Details
#initialize(*args) ⇒ List
Returns a new instance of List.
11
12
13
14
15
16
17
|
# File 'lib/hominid/list.rb', line 11
def initialize(*args)
options = args.last.is_a?(Hash) ? args.last : {}
raise StandardError.new('Please provide a List ID.') unless options[:id]
@list_id = options.delete(:id)
@attributes = options.delete(:attributes)
super(options)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9
10
11
|
# File 'lib/hominid/list.rb', line 9
def attributes
@attributes
end
|
#list_id ⇒ Object
8
9
10
|
# File 'lib/hominid/list.rb', line 8
def list_id
@list_id
end
|
Class Method Details
.all ⇒ Object
19
20
21
22
|
# File 'lib/hominid/list.rb', line 19
def self.all
new(:id => 0).call("lists").to_a.collect { |list| List.new(:id => list.delete('id'), :attributes => list) }
end
|
.find(id_or_web_id) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/hominid/list.rb', line 39
def self.find(id_or_web_id)
all = self.all
list = self.find_by_id(id_or_web_id.to_s).to_a + self.find_by_web_id(id_or_web_id.to_i).to_a
return list.blank? ? nil : list.first
end
|
.find_by_id(id) ⇒ Object
34
35
36
37
|
# File 'lib/hominid/list.rb', line 34
def self.find_by_id(id)
all.find { |list| (list.list_id == id.to_s) }
end
|
.find_by_name(name) ⇒ Object
24
25
26
27
|
# File 'lib/hominid/list.rb', line 24
def self.find_by_name(name)
all.find { |list| list.attributes['name'] =~ /#{name}/ }
end
|
.find_by_web_id(web_id) ⇒ Object
29
30
31
32
|
# File 'lib/hominid/list.rb', line 29
def self.find_by_web_id(web_id)
all.find { |list| (list.attributes['web_id'] == web_id.to_i) }
end
|
Instance Method Details
#create_group(group) ⇒ Object
Also known as:
interest_group_add
46
47
48
49
|
# File 'lib/hominid/list.rb', line 46
def create_group(group)
call("listInterestGroupAdd", @list_id, group)
end
|
#create_tag(tag, name, required = false) ⇒ Object
Also known as:
merge_var_add
52
53
54
55
|
# File 'lib/hominid/list.rb', line 52
def create_tag(tag, name, required = false)
call("listMergeVarAdd", @list_id, tag, name, required)
end
|
#delete_group(group) ⇒ Object
Also known as:
interest_group_del
58
59
60
61
|
# File 'lib/hominid/list.rb', line 58
def delete_group(group)
call("listInterestGroupDel", @list_id, group)
end
|
#delete_tag(tag) ⇒ Object
Also known as:
merge_var_del
64
65
66
67
|
# File 'lib/hominid/list.rb', line 64
def delete_tag(tag)
call("listMergeVarDel", @list_id, tag)
end
|
#groups ⇒ Object
Also known as:
interest_groups
70
71
72
73
|
# File 'lib/hominid/list.rb', line 70
def groups()
call("listInterestGroups", @list_id)
end
|
#member_info(email) ⇒ Object
77
78
79
80
|
# File 'lib/hominid/list.rb', line 77
def member_info(email)
call("listMemberInfo", @list_id, email)
end
|
#members(status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/hominid/list.rb', line 82
def members(status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
call("listMembers", @list_id, status, since, start, limit)
end
|
95
96
97
98
|
# File 'lib/hominid/list.rb', line 95
def merge_tags()
call("listMergeVars", @list_id)
end
|
#subscribe(email, options = {}) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/hominid/list.rb', line 101
def subscribe(email, options = {})
merge_tags = clean_merge_tags options[:merge_tags]
options = apply_defaults_to({:email_type => "html"}.merge(options))
call(
"listSubscribe",
@list_id,
email,
merge_tags,
*options.values_at(
:email_type,
:double_opt_in,
:update_existing,
:replace_interests,
:send_welcome
)
)
end
|
#subscribe_many(subscribers, options = {}) ⇒ Object
Also known as:
batch_subscribe
120
121
122
123
124
125
126
|
# File 'lib/hominid/list.rb', line 120
def subscribe_many(subscribers, options = {})
subscribers = subscribers.collect { |subscriber| clean_merge_tags(subscriber) }
options = apply_defaults_to({:update_existing => true}.merge(options))
call("listBatchSubscribe", @list_id, subscribers, *options.values_at(:double_opt_in, :update_existing, :replace_interests))
end
|
#unsubscribe(current_email, options = {}) ⇒ Object
129
130
131
132
133
|
# File 'lib/hominid/list.rb', line 129
def unsubscribe(current_email, options = {})
options = apply_defaults_to({:delete_member => true}.merge(options))
call("listUnsubscribe", @list_id, current_email, *options.values_at(:delete_member, :send_goodbye, :send_notify))
end
|
#unsubscribe_many(emails, options = {}) ⇒ Object
Also known as:
batch_unsubscribe
135
136
137
138
139
140
|
# File 'lib/hominid/list.rb', line 135
def unsubscribe_many(emails, options = {})
options = apply_defaults_to({:delete_member => true}.merge(options))
call("listBatchUnsubscribe", @list_id, emails, *options.values_at(:delete_member, :send_goodbye, :send_notify))
end
|
#update_member(current_email, merge_tags = {}, email_type = "html", replace_interests = true) ⇒ Object
143
144
145
146
|
# File 'lib/hominid/list.rb', line 143
def update_member(current_email, merge_tags = {}, email_type = "html", replace_interests = true)
call("listUpdateMember", @list_id, current_email, merge_tags, email_type, replace_interests)
end
|