Class: CleverElements::List
Constant Summary collapse
- Attributes =
[:id, :name, :description, :subscriber_count, :unsubscriber_count]
Class Attribute Summary collapse
-
.default_id ⇒ Object
Returns the value of attribute default_id.
Class Method Summary collapse
Instance Method Summary collapse
- #build_subscriber(attributes = {}) ⇒ Object
- #create ⇒ Object
- #create_subscriber(attributes = {}) ⇒ Object
- #create_subscriber_doi(attributes = {}) ⇒ Object
- #destroy ⇒ Object
-
#initialize(attributes = {}) ⇒ List
constructor
A new instance of List.
- #subscriber ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ List
Returns a new instance of List.
58 59 60 61 62 63 64 |
# File 'lib/clever_elements/list.rb', line 58 def initialize attributes = {} attributes = attributes.symbolize_keys Attributes.each do |attribute| instance_variable_set "@#{attribute}", attributes[attribute] end end |
Class Attribute Details
.default_id ⇒ Object
Returns the value of attribute default_id.
7 8 9 |
# File 'lib/clever_elements/list.rb', line 7 def default_id @default_id end |
Class Method Details
.all ⇒ Object
42 43 44 45 46 |
# File 'lib/clever_elements/list.rb', line 42 def all ids.map do |id| find(id) end end |
.find(id = default_id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/clever_elements/list.rb', line 9 def find id = default_id response = proxy.get_list_details :listID => id return nil if response[:list_id].nil? description = response[:description] description = String === description ? description : '' attributes = { :id => response[:list_id], :name => response[:list_name], :description => description, :subscriber_count => response[:list_subscriber], :unsubscriber_count => response[:list_unsubscriber] } new attributes end |
.first ⇒ Object
48 49 50 51 52 |
# File 'lib/clever_elements/list.rb', line 48 def first first_id = ids.first first_id && find(first_id) end |
.ids ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/clever_elements/list.rb', line 26 def ids response = proxy.get_list ids = if Array === response[:item] response[:item].map do |id_response| id_response[:list_id] end elsif Hash === response[:item] [response[:item][:list_id]] else [] end rescue Savon::SOAP::Fault [] end |
Instance Method Details
#build_subscriber(attributes = {}) ⇒ Object
102 103 104 105 106 |
# File 'lib/clever_elements/list.rb', line 102 def build_subscriber attributes = {} CleverElements::Subscriber.new(attributes.merge(:list_id => id)).tap do |subscriber| assign_list_to_subscriber subscriber end end |
#create ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/clever_elements/list.rb', line 66 def create return true if id response = proxy.add_list list_attributes if response == '200' @id = self.class.ids.last true end rescue Savon::SOAP::Fault false end |
#create_subscriber(attributes = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/clever_elements/list.rb', line 108 def create_subscriber attributes = {} subscriber = build_subscriber attributes if subscriber.create subscriber else false end end |
#create_subscriber_doi(attributes = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/clever_elements/list.rb', line 118 def create_subscriber_doi attributes = {} subscriber = build_subscriber attributes if subscriber.create_doi subscriber else false end end |
#destroy ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/clever_elements/list.rb', line 79 def destroy response = proxy.delete_list :listID => id if response == '200' @id = nil true else false end rescue Savon::SOAP::Fault false end |
#subscriber ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/clever_elements/list.rb', line 92 def subscriber return [] unless id @subscriber ||= CleverElements::Subscriber.all(id).tap do |s| s.each do |subscriber| assign_list_to_subscriber subscriber end end end |