Class: Chimp
- Inherits:
-
Object
- Object
- Chimp
- Defined in:
- lib/chimp.rb
Constant Summary collapse
- URL =
"https://%s.api.mailchimp.com/1.3/?method="
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(apikey, datacenter) ⇒ Chimp
constructor
A new instance of Chimp.
- #list_members(list_id, status = nil, opts = {}) ⇒ Object
- #lists ⇒ Object
- #subscribe(email, list_id, opts = {}) ⇒ Object
- #unsubscribe(email, list_id) ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/chimp.rb', line 8 def data @data end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/chimp.rb', line 7 def url @url end |
Class Method Details
.connect(apikey) ⇒ Object
10 11 12 13 14 |
# File 'lib/chimp.rb', line 10 def self.connect(apikey) datacenter = apikey[/-(.+)$/, 1] @current = new(apikey, datacenter) end |
.current ⇒ Object
16 17 18 |
# File 'lib/chimp.rb', line 16 def self.current @current || raise(RuntimeError, "No chimp connection defined.") end |
Instance Method Details
#list_members(list_id, status = nil, opts = {}) ⇒ Object
37 38 39 |
# File 'lib/chimp.rb', line 37 def list_members(list_id, status=nil, opts = {}) JSON(post("listMembers", id: list_id, status: status)) end |
#lists ⇒ Object
25 26 27 |
# File 'lib/chimp.rb', line 25 def lists JSON(post("lists")) end |
#subscribe(email, list_id, opts = {}) ⇒ Object
29 30 31 |
# File 'lib/chimp.rb', line 29 def subscribe(email, list_id, opts = {}) post("listSubscribe", opts.merge(email_address: email, id: list_id)) end |
#unsubscribe(email, list_id) ⇒ Object
33 34 35 |
# File 'lib/chimp.rb', line 33 def unsubscribe(email, list_id) post("listUnsubscribe", email_address: email, id: list_id) end |