Class: Smtpcom::Sendapi::OpensReport

Inherits:
ApiResource show all
Defined in:
lib/smtpcom/sendapi/opens_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) ⇒ OpensReport

Returns a new instance of OpensReport.



6
7
8
9
10
11
# File 'lib/smtpcom/sendapi/opens_report.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/opens_report.rb', line 4

def campaign
  @campaign
end

#finishObject (readonly)

Returns the value of attribute finish.



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

def finish
  @finish
end

#senderObject (readonly)

Returns the value of attribute sender.



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

def sender
  @sender
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

Instance Method Details

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



13
14
15
16
17
# File 'lib/smtpcom/sendapi/opens_report.rb', line 13

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

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



19
20
21
# File 'lib/smtpcom/sendapi/opens_report.rb', line 19

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

#prepare_params(count, page) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/smtpcom/sendapi/opens_report.rb', line 23

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
end