Class: Smtpcom::Sendapi::ClicksReport

Inherits:
ApiResource show all
Defined in:
lib/smtpcom/sendapi/clicks_report.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, url = nil) ⇒ ClicksReport

Returns a new instance of ClicksReport.



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

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

Instance Attribute Details

#campaignObject (readonly)

Returns the value of attribute campaign.



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

def campaign
  @campaign
end

#finishObject (readonly)

Returns the value of attribute finish.



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

def finish
  @finish
end

#senderObject (readonly)

Returns the value of attribute sender.



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

def sender
  @sender
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#all(count = 100, page = 1) ⇒ Object



14
15
16
17
18
# File 'lib/smtpcom/sendapi/clicks_report.rb', line 14

def all(count = 100, page = 1)
  response = _get(list_url, prepare_params(count, page))
  @total = response['Total']
  format_response response['Data']
end

#csv(count = 100, page = 1) ⇒ Object



20
21
22
# File 'lib/smtpcom/sendapi/clicks_report.rb', line 20

def csv(count = 100, page = 1)
  _get_raw(csv_url, prepare_params(count, page).merge(headers: { 'Accept' => 'text/csv' }))
end

#csv_urlObject



28
29
30
# File 'lib/smtpcom/sendapi/clicks_report.rb', line 28

def csv_url
  @url ? '/clicksbyurlexport/get' : '/clicksexport/get'
end

#list_urlObject



24
25
26
# File 'lib/smtpcom/sendapi/clicks_report.rb', line 24

def list_url
  @url ? '/clicksbyurl/get' : '/clicks/get'
end

#prepare_params(count, page) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/smtpcom/sendapi/clicks_report.rb', line 32

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