Module: CampaignMonitor::Helpers

Included in:
CampaignMonitor, Campaign, Client, List, Subscriber
Defined in:
lib/campaign_monitor/helpers.rb

Instance Method Summary collapse

Instance Method Details

#formatted_timestamp(datetime, format = timestamp_format) ⇒ Object



22
23
24
# File 'lib/campaign_monitor/helpers.rb', line 22

def formatted_timestamp(datetime, format=timestamp_format)
  datetime.strftime(format)
end

#handle_response(response) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/campaign_monitor/helpers.rb', line 4

def handle_response(response)      
  return [] if response.empty?

  if response["Code"].to_i == 0
    # success!
    yield(response)
  elsif response["Code"].to_i == 100
    raise InvalidAPIKey
  else
    # error!
    raise ApiError, response["Code"] + ": " + response["Message"]
  end      
end

#timestamp_formatObject



18
19
20
# File 'lib/campaign_monitor/helpers.rb', line 18

def timestamp_format
  '%Y-%m-%d %H:%M:%S'
end