class SoapyCake::AdminAddedit
rubocop:disable Metrics/ClassLength
Constants
- ALLOWED_CREATIVE_FILES_OPTS
- ALLOWED_CREATIVE_OPTS
- OFFER_DEFAULT_OPTIONS
- REQUIRED_NEW_OFFER_PARAMS
- REQUIRED_OFFER_CONTRACT_PARAMS
- REQUIRED_OFFER_PARAMS
Public Instance Methods
add_geo_targets(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 92 def add_geo_targets(opts) edit_geo_targets(opts.merge(add_edit_option: 'add')) end
add_offer(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 74 def add_offer(opts) require_params(opts, REQUIRED_NEW_OFFER_PARAMS) addedit_offer(opts.merge(offer_id: 0)) end
add_offer_contract(opts = {})
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 132 def add_offer_contract(opts = {}) addedit_offer_contract(opts.merge(offer_contract_id: 0)) end
add_offer_tier(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 159 def add_offer_tier(opts) addedit_offer_tier('add', opts) end
create_advertiser(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 173 def create_advertiser(opts) run Request.new(:admin, :addedit, :advertiser, opts.merge(advertiser_id: 0)) end
create_creative(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 197 def create_creative(opts) raise 'need offer_id to create creative' if opts[:offer_id].blank? raise 'cannot pass creative_id when creating creative' if opts[:creative_id].present? creative_opts = opts.select { |key, _| ALLOWED_CREATIVE_OPTS.include? key } create_result = addedit_creative(creative_opts) files_opts = opts.select { |key, _| ALLOWED_CREATIVE_FILES_OPTS.include? key } .merge(creative_id: create_result[:creative_id]) create_result.merge(addedit_creative_files(files_opts)).except(:message) end
edit_affiliate(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 167 def edit_affiliate(opts) require_params(opts, %i[affiliate_id vat_tax_required]) run Request.new(:admin, :addedit, :affiliate, opts) end
edit_contact(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 86 def edit_contact(opts) require_params(opts, %i[entity_id contact_id contact_email_address]) run Request.new(:admin, :addedit, :contact, opts) end
edit_geo_targets(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 96 def edit_geo_targets(opts) require_params(opts, %i[offer_contract_id allow_countries]) opts = if opts[:allow_countries] geo_targets_allow_options(opts) else geo_targets_redirect_options(opts) end opts[:add_edit_option] ||= 'replace' opts[:set_targeting_to_geo] = true run Request.new(:admin, :addedit, :geo_targets, opts) end
edit_offer(opts = {})
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 80 def edit_offer(opts = {}) validate_id(opts, :offer_id) addedit_offer(opts) end
edit_offer_contract(opts = {})
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 136 def edit_offer_contract(opts = {}) validate_id(opts, :offer_contract_id) addedit_offer_contract(opts) end
edit_offer_tier(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 163 def edit_offer_tier(opts) addedit_offer_tier('replace', opts) end
geo_targets_allow_options(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 111 def geo_targets_allow_options(opts) require_params(opts, %i[countries]) opts = opts.dup countries = Array(opts[:countries]) opts[:countries] = countries.join(',') opts[:redirect_site_offer_contract_ids] = ([-1] * countries.count).join(',') opts end
geo_targets_redirect_options(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 120 def geo_targets_redirect_options(opts) opts = opts.dup redirects = opts.delete(:redirects) unless redirects.is_a?(Hash) && redirects.keys.count.positive? raise Error, "Parameter 'redirects' must be a COUNTRY=>REDIRECT_OFFER_CONTRACT_ID hash!" end opts[:countries] = redirects.keys.join(',') opts[:redirect_site_offer_contract_ids] = redirects.values.join(',') opts end
remove_caps(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 150 def remove_caps(opts) require_params(opts, %i[cap_type_id]) opts = translate_values(opts) opts = opts.merge(cap_interval_id: 0, cap_amount: -1, send_alert_only: false) run Request.new(:admin, :addedit, :caps, opts) end
update_caps(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 142 def update_caps(opts) require_params(opts, %i[cap_type_id cap_interval_id cap_amount send_alert_only]) opts = translate_values(opts) run Request.new(:admin, :addedit, :caps, opts) end
Private Instance Methods
addedit_creative(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 212 def addedit_creative(opts) defaults = { creative_name: '', creative_status_id: 1, # Active: 1, Inactive: 2, Hidden: 3 creative_type_id: 3, # Link: 1, Image: 3, Flash: 4, HTML: 6, Email: 2, Text: 5, Video: 7 height: 0, notes: '', offer_link: '', third_party_name: '', width: 0 } run Request.new(:admin, :addedit, :creative, defaults.merge(opts)) end
addedit_creative_files(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 227 def addedit_creative_files(opts) run Request.new(:admin, :addedit, :creative_files, opts) end
addedit_offer(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 269 def addedit_offer(opts) require_params(opts, REQUIRED_OFFER_PARAMS) opts = translate_booleans(opts) opts = apply_tag_opts(opts) opts = translate_values(opts) run(Request.new(:admin, :addedit, :offer, default_offer_options.merge(opts)))[:success_info] end
addedit_offer_contract(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 279 def addedit_offer_contract(opts) require_params(opts, REQUIRED_OFFER_CONTRACT_PARAMS) opts = translate_values(opts) run Request.new(:admin, :addedit, :offer_contract, opts) end
addedit_offer_tier(add_edit_option, opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 231 def addedit_offer_tier(add_edit_option, opts) require_params(opts, %i[offer_id tier_id price_format_id offer_contract_id status_id]) opts = opts.merge(redirect_offer_contract_id: -1, add_edit_option: add_edit_option) opts = translate_values(opts) run Request.new(:admin, :addedit, :offer_tiers, opts) end
apply_tag_modification_type(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 248 def apply_tag_modification_type(opts) opts = opts.dup opts[:tags_modification_type] = if opts[:tags].to_s == '' 'remove_all' elsif opts.delete(:tags_replace) && opts[:offer_id].nonzero? 'replace' else 'add' end opts end
apply_tag_opts(opts)
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 240 def apply_tag_opts(opts) return opts unless opts[:tags] opts = apply_tag_modification_type(opts) opts[:tags] = Array(opts[:tags]).join(',') opts end
default_offer_options()
click to toggle source
# File lib/soapy_cake/admin_addedit.rb, line 261 def default_offer_options OFFER_DEFAULT_OPTIONS.merge( conversion_cap_behavior: const_lookup(:conversion_behavior_id, :system), conversion_behavior_on_redirect: const_lookup(:conversion_behavior_id, :system), expiration_date: future_expiration_date ) end