Class: Smtpcom::Sendapi::StatsSummary

Inherits:
ApiResource show all
Defined in:
lib/smtpcom/sendapi/stats_summary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApiResource

#_get, #_get_raw, #_post, build_from_response

Methods included from Request

included

Constructor Details

#initialize(start, finish, sender = nil, campaign = nil) ⇒ StatsSummary

Returns a new instance of StatsSummary.



6
7
8
9
10
11
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 6

def initialize(start, finish, sender = nil, campaign = nil)
  @start    = start
  @finish   = finish
  @sender   = sender
  @campaign = campaign
end

Instance Attribute Details

#campaignObject (readonly)

Returns the value of attribute campaign.



4
5
6
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 4

def campaign
  @campaign
end

#finishObject (readonly)

Returns the value of attribute finish.



4
5
6
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 4

def finish
  @finish
end

#senderObject (readonly)

Returns the value of attribute sender.



4
5
6
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 4

def sender
  @sender
end

#startObject (readonly)

Returns the value of attribute start.



4
5
6
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 4

def start
  @start
end

#totalObject (readonly)

Returns the value of attribute total.



4
5
6
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 4

def total
  @total
end

Instance Method Details

#allObject



13
14
15
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 13

def all
  format_response _get('/summarystats/get', prepare_params)
end

#csvObject



17
18
19
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 17

def csv
  _get_raw('/summarystatsexport/get', prepare_params.merge(headers: { 'Accept' => 'text/csv' }))
end

#prepare_paramsObject



21
22
23
24
25
26
27
28
29
# File 'lib/smtpcom/sendapi/stats_summary.rb', line 21

def prepare_params
  attributes = {
    DateFrom: @start.strftime("%m/%d/%Y"),
    DateTo:   @finish.strftime("%m/%d/%Y")
  }
  attributes[:Sender]     = @sender    if @sender
  attributes[:CampaignID] = @campaign  if @campaign
  attributes
end