Class: YandexDirect::Campaign
- Inherits:
-
Object
- Object
- YandexDirect::Campaign
- Defined in:
- lib/services/campaign.rb
Constant Summary collapse
- SERVICE =
'campaigns'
Instance Attribute Summary collapse
-
#bid_percent ⇒ Object
Returns the value of attribute bid_percent.
-
#blocked_ips ⇒ Object
Returns the value of attribute blocked_ips.
-
#daily_budget_amount ⇒ Object
Returns the value of attribute daily_budget_amount.
-
#daily_budget_mode ⇒ Object
Returns the value of attribute daily_budget_mode.
-
#email ⇒ Object
Returns the value of attribute email.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#excluded_sites ⇒ Object
Returns the value of attribute excluded_sites.
-
#id ⇒ Object
Returns the value of attribute id.
-
#limit_percent ⇒ Object
Returns the value of attribute limit_percent.
-
#name ⇒ Object
Returns the value of attribute name.
-
#negative_keywords ⇒ Object
Returns the value of attribute negative_keywords.
-
#network_strategy ⇒ Object
Returns the value of attribute network_strategy.
-
#owner_name ⇒ Object
Returns the value of attribute owner_name.
-
#search_strategy ⇒ Object
Returns the value of attribute search_strategy.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#state ⇒ Object
Returns the value of attribute state.
-
#status ⇒ Object
Returns the value of attribute status.
-
#target_hours ⇒ Object
Returns the value of attribute target_hours.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Campaign
constructor
A new instance of Campaign.
- #parameters(campaign_type) ⇒ Object
- #text_campaign_parameters ⇒ Object
Constructor Details
#initialize(params) ⇒ Campaign
Returns a new instance of Campaign.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/services/campaign.rb', line 7 def initialize(params) @name = params[:name] @id = params[:id] @status = params[:status] @state = params[:state] @start_date = params[:start_date] @time_zone = params[:time_zone] @negative_keywords = {"Items": params[:negative_keywords]} if params[:negative_keywords].present? @email = params[:email] @owner_name = params[:owner_name] @limit_percent = params[:limit_percent] @bid_percent = params[:bid_percent] @end_date = params[:end_date] @daily_budget_amount = params[:daily_budget_amount] @daily_budget_mode = params[:daily_budget_mode] @blocked_ips = params[:blocked_ips] @excluded_sites = params[:excluded_sites] @search_strategy = params[:search_strategy] @network_strategy = params[:network_strategy] @target_hours = params[:target_hours] @type == params[:type] || "TEXT_CAMPAIGN" end |
Instance Attribute Details
#bid_percent ⇒ Object
Returns the value of attribute bid_percent.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def bid_percent @bid_percent end |
#blocked_ips ⇒ Object
Returns the value of attribute blocked_ips.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def blocked_ips @blocked_ips end |
#daily_budget_amount ⇒ Object
Returns the value of attribute daily_budget_amount.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def daily_budget_amount @daily_budget_amount end |
#daily_budget_mode ⇒ Object
Returns the value of attribute daily_budget_mode.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def daily_budget_mode @daily_budget_mode end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def email @email end |
#end_date ⇒ Object
Returns the value of attribute end_date.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def end_date @end_date end |
#excluded_sites ⇒ Object
Returns the value of attribute excluded_sites.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def excluded_sites @excluded_sites end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def id @id end |
#limit_percent ⇒ Object
Returns the value of attribute limit_percent.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def limit_percent @limit_percent end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def name @name end |
#negative_keywords ⇒ Object
Returns the value of attribute negative_keywords.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def negative_keywords @negative_keywords end |
#network_strategy ⇒ Object
Returns the value of attribute network_strategy.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def network_strategy @network_strategy end |
#owner_name ⇒ Object
Returns the value of attribute owner_name.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def owner_name @owner_name end |
#search_strategy ⇒ Object
Returns the value of attribute search_strategy.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def search_strategy @search_strategy end |
#start_date ⇒ Object
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def start_date @start_date end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def state @state end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def status @status end |
#target_hours ⇒ Object
Returns the value of attribute target_hours.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def target_hours @target_hours end |
#time_zone ⇒ Object
Returns the value of attribute time_zone.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def time_zone @time_zone end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/services/campaign.rb', line 3 def type @type end |
Class Method Details
.add(params) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/services/campaign.rb', line 45 def self.add(params) if params.kind_of?(Array) batch_add(params) else special_parameters = params.text_campaign_parameters if params.type.blank? || params.type == "TEXT_CAMPAIGN" params.id = YandexDirect.request(SERVICE, 'add', {"Campaigns": [params.parameters(special_parameters)]})["AddResults"].first["Id"] params end end |
.list ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/services/campaign.rb', line 30 def self.list YandexDirect.request(SERVICE, 'get', { "SelectionCriteria": { "Types": ["TEXT_CAMPAIGN"], "States": ["OFF", "ON"], "Statuses": ["ACCEPTED", "DRAFT", "MODERATION"] }, "FieldNames": ['Id', 'Name', 'State', 'Status', 'TimeTargeting', 'NegativeKeywords', 'ClientInfo', 'Type'], "TextCampaignFieldNames": ["BiddingStrategy"] })["Campaigns"].map{|c| new({ name: c["Name"], id: c["Id"], status: c["Status"], state: c["State"], type: c["Type"], target_hours: c["TimeTargeting"]["Schedule"]["Items"], owner_name: c["ClientInfo"], negative_keywords: (c["NegativeKeywords"].present? ? c["NegativeKeywords"]["Items"] : nil), search_strategy: c["TextCampaign"]["BiddingStrategy"]["Search"]["BiddingStrategyType"], network_strategy: c["TextCampaign"]["BiddingStrategy"]["Network"]["BiddingStrategyType"]})} end |
.update(params) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/services/campaign.rb', line 55 def self.update(params) if params.kind_of?(Array) batch_update(params) else special_parameters = params.text_campaign_parameters if params.type.blank? || params.type == "TEXT_CAMPAIGN" params.id = YandexDirect.request(SERVICE, 'update', {"Campaigns": [params.parameters(special_parameters)]})["UpdateResults"].first["Id"] params end end |
Instance Method Details
#parameters(campaign_type) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/services/campaign.rb', line 65 def parameters(campaign_type) hash = {"Name": @name, "ClientInfo": @owner_name, "Notification": { "EmailSettings": { "Email": @email, "SendAccountNews": "YES", "SendWarnings": "YES" } }, "TimeTargeting": { "Schedule": { "Items": @target_hours }, "ConsiderWorkingWeekends": "YES", "HolidaysSchedule": { "SuspendOnHolidays": "NO", "BidPercent": 100, "StartHour": 0, "EndHour": 24 } }, "TimeZone": @time_zone } hash["NegativeKeywords"] = @negative_keywords if @negative_keywords.present? hash["DailyBudget"] = {"Amount": @daily_budget_amount, "Mode": @daily_budget_mode} if @daily_budget_mode.present? && @daily_budget_amount.present? hash["BlockedIps"] = {"Items": @blocked_ips} if @blocked_ips.present? hash["ExcludedSites"] = {"Items": @excluded_sites} if @excluded_sites.present? hash["Id"] = @id if @id.present? && @id != 0 hash["StartDate"] = @start_date if @start_date.present? hash["EndDate"] = @end_date if @end_date.present? hash[campaign_type.first] = campaign_type.last hash end |
#text_campaign_parameters ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/services/campaign.rb', line 100 def text_campaign_parameters ["TextCampaign", {"BiddingStrategy": { "Search": { "BiddingStrategyType": @search_strategy }, "Network": { "BiddingStrategyType": @network_strategy, "NetworkDefault": { "LimitPercent": @limit_percent, "BidPercent": @bid_percent } } } } ] end |