class SoapyCake::Campaigns

Constants

ALL_PARAMS

TODO: Figure out what `static_suppression` is for and whether it needs to be in the list.

NO_CHANGE_VALUES

Public Instance Methods

create(opts = {}) click to toggle source
# File lib/soapy_cake/campaigns.rb, line 42
def create(opts = {})
  response = addedit_campaign(opts.merge(campaign_id: 0))
  response.fetch(:success_info).fetch(:campaign_id)
end
get(opts = {}) click to toggle source
# File lib/soapy_cake/campaigns.rb, line 38
def get(opts = {})
  client.run Request.new(:admin, :export, :campaigns, opts)
end
patch(campaign_id, opts = {}) click to toggle source

The default for `display_link_type_id` is “Fallback” in Cake, which doesn't have an ID and, hence, cannot be set via the API. In order to not change it, it has to be absent from the request.

# File lib/soapy_cake/campaigns.rb, line 60
def patch(campaign_id, opts = {})
  campaign = get(campaign_id: campaign_id).first
  opts = NO_CHANGE_VALUES
    .merge(
      affiliate_id: campaign.fetch(:affiliate).fetch(:affiliate_id),
      media_type_id: campaign.fetch(:media_type).fetch(:media_type_id),
      offer_contract_id: campaign.fetch(:offer_contract).fetch(:offer_contract_id),
      offer_id: campaign.fetch(:offer).fetch(:offer_id),
      payout: campaign.fetch(:payout).fetch(:amount),
      payout_update_option: 'do_not_change',
      pixel_html: campaign.dig(:pixel_info, :pixel_html) || '',
      postback_url: campaign.dig(:pixel_info, :postback_url) || '',
      redirect_domain: campaign.fetch(:redirect_domain, ''),
      test_link: campaign[:test_link] || '',
      unique_key_hash: campaign.dig(:pixel_info, :hash_type, :hash_type_id) || 'none',
      third_party_name: campaign.fetch(:third_party_name, '')
    )
    .merge(opts)
  update(campaign_id, opts)
  nil
end
update(campaign_id, opts = {}) click to toggle source
# File lib/soapy_cake/campaigns.rb, line 47
def update(campaign_id, opts = {})
  opts = opts.merge(campaign_id: campaign_id)
  opts = opts.merge(payout.options(opts))
  opts = opts.merge(expiration_date.options(opts))
  opts = NO_CHANGE_VALUES.merge(opts)
  require_params(opts, ALL_PARAMS)
  addedit_campaign(opts)
  nil
end

Private Instance Methods

addedit_campaign(opts) click to toggle source
# File lib/soapy_cake/campaigns.rb, line 96
def addedit_campaign(opts)
  opts = translate_booleans(opts)
  opts = translate_values(opts)
  client.run Request.new(:admin, :addedit, :campaign, opts)
end
client() click to toggle source
# File lib/soapy_cake/campaigns.rb, line 102
def client
  @client ||= Client.new
end
expiration_date() click to toggle source
# File lib/soapy_cake/campaigns.rb, line 88
def expiration_date
  ModificationType.new(
    :expiration_date,
    :expiration_date_modification_type,
    Time.utc(1970, 1, 1)
  )
end
payout() click to toggle source
# File lib/soapy_cake/campaigns.rb, line 84
def payout
  ModificationType.new(:payout, :payout_update_option, 0)
end