Class: Smtpcom::Sendapi::Campaign

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

Constant Summary collapse

MAPPINGS =
{
  id:         :CampaignID,
  name:       :CampaignName,
  opens:      :Opens,
  clicks:     :Clicks,
  delivered:  :Delivered,
  bounced:    :Bounced
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiResource

#_get, #_get_raw, #_post, build_from_response, #initialize, #prepare_params

Methods included from Request

included

Constructor Details

This class inherits a constructor from Smtpcom::Sendapi::ApiResource

Instance Attribute Details

#bouncedObject (readonly)

Returns the value of attribute bounced.



14
15
16
# File 'lib/smtpcom/sendapi/campaign.rb', line 14

def bounced
  @bounced
end

#clicksObject (readonly)

Returns the value of attribute clicks.



14
15
16
# File 'lib/smtpcom/sendapi/campaign.rb', line 14

def clicks
  @clicks
end

#deliveredObject (readonly)

Returns the value of attribute delivered.



14
15
16
# File 'lib/smtpcom/sendapi/campaign.rb', line 14

def delivered
  @delivered
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#opensObject (readonly)

Returns the value of attribute opens.



14
15
16
# File 'lib/smtpcom/sendapi/campaign.rb', line 14

def opens
  @opens
end

Class Method Details

.allObject



17
18
19
20
21
# File 'lib/smtpcom/sendapi/campaign.rb', line 17

def all
  _get('/campaigns/get')['Data'].map do |row|
    build_from_response row
  end
end

.find(id) ⇒ Object



23
24
25
# File 'lib/smtpcom/sendapi/campaign.rb', line 23

def find(id)
  all.find { |c| c.id == id }
end

Instance Method Details

#deleteObject



39
40
41
# File 'lib/smtpcom/sendapi/campaign.rb', line 39

def delete
  _post('/campaigns/delete', { CampaignID: @id }, :formatted)
end

#saveObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/smtpcom/sendapi/campaign.rb', line 28

def save
  attrs = { CampaignName: @name }
  res = if @id
          _get '/campaigns/update', attrs.merge(CampaignID: @id), :formatted
        else
          _post '/campaigns/add', attrs, :formatted
        end
  @id = res[:id]
  res
end