Class: Hominid::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/hominid/export.rb

Constant Summary collapse

MAILCHIMP_EXPORT_VERSION =

MailChimp Export API Documentation: apidocs.mailchimp.com/export/1.0/

"1.0"

Instance Method Summary collapse

Constructor Details

#initialize(api_key, config = {}) ⇒ Export

Initialize with an API key and config options

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hominid/export.rb', line 8

def initialize(api_key, config = {})
  raise ArgumentError.new('Your Mailchimp API key appears to be malformed.') unless api_key.include?('-')
  dc = api_key.split('-').last
  defaults = {
    :api_version        => MAILCHIMP_EXPORT_VERSION,
    :secure             => false
  }
  @config = defaults.merge(config).freeze
  protocol = @config[:secure] ? 'https' : 'http'
  @api_key = api_key
  @api_base = "#{protocol}://#{dc}.api.mailchimp.com/export/#{@config[:api_version]}"
end

Instance Method Details

#campaign_subscriber_activity(id, include_empty = false) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/hominid/export.rb', line 42

def campaign_subscriber_activity(id, include_empty = false)
  post_data = {
    :apikey => @api_key,
    :id => id,
    :include_empty => include_empty,
  }
  call('campaignSubscriberActivity', post_data)
end

#list(id, status = 'subscribed', segment = [], since = '1900-01-01 00:00:00') ⇒ Object

TODO: We’ll have to see how this progresses with regard to Mailchimp

adding methods to the Export API. It would be nice to have this
model follow the "method_missing" style of the others, but it
would require passing arguments in as a hash:

hominid_export.list({:id => 123, :status => 'unsubscribed'})

It's the only way to get the *args to map over to the params hash
if we use the "method_missing" approach. For now, this way seems
more intuitive to the end user.


32
33
34
35
36
37
38
39
40
# File 'lib/hominid/export.rb', line 32

def list(id, status = 'subscribed', segment = [], since = '1900-01-01 00:00:00')
  post_data = {
    :apikey => @api_key,
    :id => id,
    :status => status,
    :since => since
  }
  call('list', post_data)
end