Class: YandexDirect::Add
- Inherits:
-
Object
- Object
- YandexDirect::Add
- Defined in:
- lib/services/add.rb
Constant Summary collapse
- SERVICE =
'ads'
Instance Attribute Summary collapse
-
#ad_group_id ⇒ Object
Returns the value of attribute ad_group_id.
-
#ad_image_hash ⇒ Object
Returns the value of attribute ad_image_hash.
-
#campaign_id ⇒ Object
Returns the value of attribute campaign_id.
-
#display_url_path ⇒ Object
Returns the value of attribute display_url_path.
-
#extension_ids ⇒ Object
Returns the value of attribute extension_ids.
-
#href ⇒ Object
Returns the value of attribute href.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mobile ⇒ Object
Returns the value of attribute mobile.
-
#sitelink_set_id ⇒ Object
Returns the value of attribute sitelink_set_id.
-
#state ⇒ Object
Returns the value of attribute state.
-
#status ⇒ Object
Returns the value of attribute status.
-
#status_clarification ⇒ Object
Returns the value of attribute status_clarification.
-
#text ⇒ Object
Returns the value of attribute text.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
-
#v_card_id ⇒ Object
Returns the value of attribute v_card_id.
Class Method Summary collapse
- .add(params) ⇒ Object
- .archive(ids) ⇒ Object
- .delete(ids) ⇒ Object
- .list(params) ⇒ Object
- .moderate(ids) ⇒ Object
- .resume(ids) ⇒ Object
- .stop(ids) ⇒ Object
- .unarchive(ids) ⇒ Object
- .update(params) ⇒ Object
Instance Method Summary collapse
- #add_parameters(add_type) ⇒ Object
-
#initialize(params) ⇒ Add
constructor
A new instance of Add.
- #new_text_add_parameters ⇒ Object
- #text_add_parameters ⇒ Object
- #update_parameters(add_type) ⇒ Object
Constructor Details
#initialize(params) ⇒ Add
Returns a new instance of Add.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/services/add.rb', line 6 def initialize(params) @ad_group_id = params[:ad_group_id] @id = params[:id] @status = params[:status] @campaign_id = params[:campaign_id] @negative_keywords = params[:negative_keywords] = params[:utm_tags] @state = params[:state] @type = params[:type] || "TEXT_AD" @status_clarification = params[:status_clarification] @text = params[:text] @title = params[:title] @href = params[:href] @display_url_path = params[:display_url_path] @ad_image_hash = params[:ad_image_hash] @extension_ids = params[:extension_ids] @mobile = params[:mobile] @v_card_id = params[:v_card_id] @extension_ids = params[:extension_ids] @mobile = params[:mobile] @sitelink_set_id = params[:sitelink_set_id] end |
Instance Attribute Details
#ad_group_id ⇒ Object
Returns the value of attribute ad_group_id.
3 4 5 |
# File 'lib/services/add.rb', line 3 def ad_group_id @ad_group_id end |
#ad_image_hash ⇒ Object
Returns the value of attribute ad_image_hash.
3 4 5 |
# File 'lib/services/add.rb', line 3 def ad_image_hash @ad_image_hash end |
#campaign_id ⇒ Object
Returns the value of attribute campaign_id.
3 4 5 |
# File 'lib/services/add.rb', line 3 def campaign_id @campaign_id end |
#display_url_path ⇒ Object
Returns the value of attribute display_url_path.
3 4 5 |
# File 'lib/services/add.rb', line 3 def display_url_path @display_url_path end |
#extension_ids ⇒ Object
Returns the value of attribute extension_ids.
3 4 5 |
# File 'lib/services/add.rb', line 3 def extension_ids @extension_ids end |
#href ⇒ Object
Returns the value of attribute href.
3 4 5 |
# File 'lib/services/add.rb', line 3 def href @href end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/services/add.rb', line 3 def id @id end |
#mobile ⇒ Object
Returns the value of attribute mobile.
3 4 5 |
# File 'lib/services/add.rb', line 3 def mobile @mobile end |
#sitelink_set_id ⇒ Object
Returns the value of attribute sitelink_set_id.
3 4 5 |
# File 'lib/services/add.rb', line 3 def sitelink_set_id @sitelink_set_id end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/services/add.rb', line 3 def state @state end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/services/add.rb', line 3 def status @status end |
#status_clarification ⇒ Object
Returns the value of attribute status_clarification.
3 4 5 |
# File 'lib/services/add.rb', line 3 def status_clarification @status_clarification end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/services/add.rb', line 3 def text @text end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/services/add.rb', line 3 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/services/add.rb', line 3 def type @type end |
#v_card_id ⇒ Object
Returns the value of attribute v_card_id.
3 4 5 |
# File 'lib/services/add.rb', line 3 def v_card_id @v_card_id end |
Class Method Details
.add(params) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/services/add.rb', line 44 def self.add(params) if params.kind_of?(Array) batch_add(params) else special_parameters = params.new_text_add_parameters if params.type == "TEXT_AD" params.id = YandexDirect.request(SERVICE, 'add', {"Ads": [params.add_parameters(special_parameters)]})["AddResults"].first["Id"] params end end |
.archive(ids) ⇒ Object
69 70 71 72 |
# File 'lib/services/add.rb', line 69 def self.archive(ids) ids = [ids] unless params.kind_of?(Array) action('archieve', ids) end |
.delete(ids) ⇒ Object
89 90 91 92 |
# File 'lib/services/add.rb', line 89 def self.delete(ids) ids = [ids] unless params.kind_of?(Array) action('delete', ids) end |
.list(params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/services/add.rb', line 29 def self.list(params) selection_criteria = {"Types": ["TEXT_AD"]} selection_criteria["CampaignIds"] = params[:campaign_ids] if params[:campaign_ids].present? selection_criteria["AdGroupIds"] = params[:ad_group_ids] if params[:ad_group_ids].present? selection_criteria["Ids"] = params[:ids] if params[:ids].present? ads = YandexDirect.request(SERVICE, 'get', { "SelectionCriteria": selection_criteria, "FieldNames": ['AdGroupId', 'CampaignId', 'State', 'Status', 'StatusClarification', 'Type', 'Id'], "TextAdFieldNames": ['SitelinkSetId', 'Text', 'Title', 'Href'] })["Ads"] (ads || []).map{|c| new({ ad_group_id: c["AdGroupId"], id: c["Id"], status: c["Status"], campaign_id: c["CampaignId"], state: c["State"], type: c["Type"], status_clarification: c["StatusClarification"], sitelink_set_id: c["TextAd"]["SitelinkSetId"], text: c["TextAd"]["Text"], title: c["TextAd"]["Title"], href: c["TextAd"]["Href"]})} end |
.moderate(ids) ⇒ Object
84 85 86 87 |
# File 'lib/services/add.rb', line 84 def self.moderate(ids) ids = [ids] unless params.kind_of?(Array) action('moderate', ids) end |
.resume(ids) ⇒ Object
79 80 81 82 |
# File 'lib/services/add.rb', line 79 def self.resume(ids) ids = [ids] unless params.kind_of?(Array) action('resume', ids) end |
.stop(ids) ⇒ Object
74 75 76 77 |
# File 'lib/services/add.rb', line 74 def self.stop(ids) ids = [ids] unless params.kind_of?(Array) action('suspend', ids) end |
.unarchive(ids) ⇒ Object
64 65 66 67 |
# File 'lib/services/add.rb', line 64 def self.unarchive(ids) ids = [ids] unless params.kind_of?(Array) action('unarchieve', ids) end |
.update(params) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/services/add.rb', line 54 def self.update(params) if params.kind_of?(Array) batch_update(params) else special_parameters = params.text_add_parameters if params.type == "TEXT_AD" params.id = YandexDirect.request(SERVICE, 'update', {"Ads": [params.update_parameters(special_parameters)]})["UpdateResults"].first["Id"] params end end |
Instance Method Details
#add_parameters(add_type) ⇒ Object
94 95 96 97 98 |
# File 'lib/services/add.rb', line 94 def add_parameters(add_type) hash = {"AdGroupId": @ad_group_id} hash[add_type.first] = add_type.last hash end |
#new_text_add_parameters ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/services/add.rb', line 106 def new_text_add_parameters hash = {"Text": @text, "Title": @title, "Href": @href, "Mobile": @mobile || "NO", "AdExtensionIds": @extension_ids || [] } hash["DisplayUrlPath"] = @display_url_path if @display_url_path.present? hash["VCardId"] = @v_card_id if @v_card_id.present? hash["AdImageHash"] = @ad_image_hash if @ad_image_hash.present? hash["SitelinkSetId"] = @sitelink_set_id if @sitelink_set_id.present? ["TextAd", hash] end |
#text_add_parameters ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/services/add.rb', line 120 def text_add_parameters hash = {"Text": @text, "Title": @title, "Href": @href, } hash["DisplayUrlPath"] = @display_url_path if @display_url_path.present? hash["AdImageHash"] = @ad_image_hash if @ad_image_hash.present? hash["CalloutSetting"]["AdExtensions"] = @extension_ids.map{|e| {"AdExtensionId": e, "Operation": "SET"}} if @extension_ids.present? hash["VCardId"] = @v_card_id if @v_card_id.present? hash["SitelinkSetId"] = @sitelink_set_id if @sitelink_set_id.present? ["TextAd", hash] end |
#update_parameters(add_type) ⇒ Object
100 101 102 103 104 |
# File 'lib/services/add.rb', line 100 def update_parameters(add_type) hash = {"Id": @id} hash[add_type.first] = add_type.last hash end |