Sha256: ea2fbc15ddd6da4d2c7b8c03a18c88544c225fd10aeafa63fe2e73b27c11eda7

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'createsend'
require 'json'

class Subscriber
  attr_reader :list_id
  attr_reader :email_address

  def initialize(list_id, email_address)
    @list_id = list_id
    @email_address = email_address
  end

  def self.get(list_id, email_address)
    options = { :query => { :email => email_address } }
    response = CreateSend.get "/subscribers/#{list_id}.json", options
    Hashie::Mash.new(response)
  end

  def self.add(list_id, email_address, name, custom_fields, resubscribe)
    options = { :body => {
      :EmailAddress => email_address,
      :Name => name,
      :CustomFields => custom_fields,
      :Resubscribe => resubscribe }.to_json }
    response = CreateSend.post "/subscribers/#{list_id}.json", options
    response.parsed_response
  end

  def self.import(list_id, subscribers, resubscribe)
    options = { :body => {
      :Subscribers => subscribers,
      :Resubscribe => resubscribe }.to_json }
    response = CreateSend.post "/subscribers/#{list_id}/import.json", options
    Hashie::Mash.new(response)
  end

  def unsubscribe
    options = { :body => {
      :EmailAddress => @email_address }.to_json }
    CreateSend.post "/subscribers/#{@list_id}/unsubscribe.json", options
  end

  def history
    options = { :query => { :email => @email_address } }
    response = CreateSend.get "/subscribers/#{@list_id}/history.json", options
    response.map{|item| Hashie::Mash.new(item)}
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
createsend-0.0.1 lib/subscriber.rb