class ExpressPigeon::Lists

Public Class Methods

new() click to toggle source
# File lib/expresspigeon-ruby/lists.rb, line 6
def initialize
  @endpoint = 'lists'
end

Public Instance Methods

all() click to toggle source

Query all lists. returns: array of hashes each representing a list for this user

# File lib/expresspigeon-ruby/lists.rb, line 17
def all
  get @endpoint
end
create(list_name, from_name, reply_to) click to toggle source
# File lib/expresspigeon-ruby/lists.rb, line 10
def create(list_name, from_name, reply_to)
  post @endpoint, {:name => list_name, :from_name => from_name, :reply_to => reply_to}
end
csv(list_id ID of a list to download) click to toggle source

Downloads a list as CSV file

# File lib/expresspigeon-ruby/lists.rb, line 54
def csv(list_id, &block)
  get "#{@endpoint}/#{list_id}/csv", &block
end
delete(list_id) click to toggle source

Removes a list with a given id. A list must be enabled and has no dependent subscriptions and/or scheduled campaigns.

param list_id: Id of list to be removed.
returns response hash with status, code, and message
# File lib/expresspigeon-ruby/lists.rb, line 48
def delete(list_id)
  del "#{@endpoint}/#{list_id}"
end
update(list_id, params = {}) click to toggle source

:returns: EpResponse with status, code, message, and updated list

# File lib/expresspigeon-ruby/lists.rb, line 31
def update(list_id, params = {})
  post @endpoint, {:id => list_id, :name => params[:name], :from_name => params[:from_name], :reply_to => params[:reply_to]}
end
upload(list_id, file_name) click to toggle source
# File lib/expresspigeon-ruby/lists.rb, line 58
def upload(list_id, file_name)
  path = "#{@root ? @root : ROOT}/#{@endpoint}/#{list_id}/upload"
  begin
    resp = RestClient.post(path,
                          {:contacts_file => File.new(file_name)},
                          {:'X-auth-key' => get_auth_key})
    res = resp.body
  rescue RestClient::ExceptionWithResponse => err
    res = err.response # this happens even if everything is OK, but the HTTP code is 404, or something... strange
  end
  parsed = JSON.parse(res)
  if parsed.kind_of? Hash
    MetaResponse.new parsed
  else
    parsed
  end
end
upload_status(list_id) click to toggle source

:returns: status of upload

# File lib/expresspigeon-ruby/lists.rb, line 39
def upload_status(list_id)
  get "#{@endpoint}/upload_status/#{list_id}"
end