Class: MaleChimp::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/malechimp/subscriber.rb

Constant Summary collapse

DEFAULT_FIELDS =
%w(first_name last_name email id)
MERGE_FIELD_SIZE =

Another bullshit constraint imposed by MaleChimp

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields = {}) {|_self| ... } ⇒ Subscriber

Returns a new instance of Subscriber.

Yields:

  • (_self)

Yield Parameters:



22
23
24
25
26
27
28
29
30
# File 'lib/malechimp/subscriber.rb', line 22

def initialize(fields={})
  # Setup our default fields hash
  @fields = DEFAULT_FIELDS.inject({}) do |h,f|
    h[f] = '' # Default values to be blank
    h         # Gotta yield this for inject to work
  end
  @fields.merge!(fields)
  yield self if block_given?
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



7
8
9
# File 'lib/malechimp/subscriber.rb', line 7

def fields
  @fields
end

Instance Method Details

#merge_fieldsObject

Guess what guys? Chimp wants all upper case field names and no spaces for merge fields. Fine, we’ll give ‘em that!



34
35
36
37
38
39
40
# File 'lib/malechimp/subscriber.rb', line 34

def merge_fields
  fields.inject({}) do |hash, field|
    key, value = encode_merge_field(field)
    hash[key] = value
    hash
  end
end