Class: Chimpactions::List

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/chimpactions/list.rb

Overview

The List class does all kinds of things with your MailChimp lists.

Defined Under Namespace

Classes: Stats

Constant Summary collapse

@@socket =

The system-wide single socket to the MailChimp mothership.

Chimpactions.socket

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

#method_missing

Constructor Details

#initialize(raw) ⇒ List

Create a new List object

Parameters:

  • raw (Hash)

    MailChimp API data return see Chimpactions::Subscriber



21
22
23
24
25
# File 'lib/chimpactions/list.rb', line 21

def initialize(raw)
  @raw = raw
  @stats = Stats.new(@raw.delete('stats'))
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chimpactions::Utility

Instance Attribute Details

#statsList::Stats (readonly)

Returns:



17
18
19
# File 'lib/chimpactions/list.rb', line 17

def stats
  @stats
end

Class Method Details

.new_socketObject

Receiver for Observer pattern. Sets the class level socket to the current Chimpactions module socket.



12
13
14
# File 'lib/chimpactions/list.rb', line 12

def self.new_socket
  @@socket = Chimpactions.socket
end

Instance Method Details

#dataHash

The raw list data.

Returns:

  • (Hash)


29
30
31
# File 'lib/chimpactions/list.rb', line 29

def data
  @raw
end

#merge_varsObject

The available merge varaibles for the List.



65
66
67
# File 'lib/chimpactions/list.rb', line 65

def merge_vars
  @merge_vars ||= @@socket.listMergeVars(:id => id)
end

#remove_webhook(opts) ⇒ true, Hash

removes the specified url webhook for this List

Parameters:

  • _REQUIRED_ (Hash)

    : :url => ‘a valid, currently used url’

Returns:

  • (true, Hash)

    true if ok, otherwise an error hash



91
92
93
# File 'lib/chimpactions/list.rb', line 91

def remove_webhook(opts)
  @@socket.listWebhookDel({:id => id}.merge(opts) ) == "true"
end

#set_webhook(opts) ⇒ true, Hash

Sets a webhook for this List

Parameters:

  • _REQUIRED_ (Hash)

    : :url => ‘a valid url’

Returns:

  • (true, Hash)

    true if ok, otherwise an error hash



84
85
86
# File 'lib/chimpactions/list.rb', line 84

def set_webhook(opts)
  @@socket.listWebhookAdd({:id => id}.merge(opts) ) == "true"
end

#webhook?boolean

Checks if there are ANY webhooks for this list

Returns:

  • (boolean)


71
72
73
# File 'lib/chimpactions/list.rb', line 71

def webhook?
  @@socket.listWebhooks(:id => id).empty? ? false : true
end

#webhooksHash, false

Retrieves webhooks for this List

Returns:

  • (Hash, false)


77
78
79
# File 'lib/chimpactions/list.rb', line 77

def webhooks
  @@socket.listWebhooks(:id => id)
end