Class: YandexDirect::AdGroup
- Inherits:
-
Object
- Object
- YandexDirect::AdGroup
- Defined in:
- lib/services/ad_group.rb
Constant Summary collapse
- SERVICE =
'adgroups'
Instance Attribute Summary collapse
-
#campaign_id ⇒ Object
Returns the value of attribute campaign_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#negative_keywords ⇒ Object
Returns the value of attribute negative_keywords.
-
#region_ids ⇒ Object
Returns the value of attribute region_ids.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tracking_params ⇒ Object
Returns the value of attribute tracking_params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ AdGroup
constructor
A new instance of AdGroup.
- #parameters ⇒ Object
- #update_parameters ⇒ Object
Constructor Details
#initialize(params) ⇒ AdGroup
Returns a new instance of AdGroup.
5 6 7 8 9 10 11 12 13 |
# File 'lib/services/ad_group.rb', line 5 def initialize(params) @name = params[:name] @id = params[:id] @status = params[:status] @campaign_id = params[:campaign_id] @region_ids = params[:region_ids] @negative_keywords = {"Items": params[:negative_keywords]} if params[:negative_keywords].present? @tracking_params = params[:tracking_params] end |
Instance Attribute Details
#campaign_id ⇒ Object
Returns the value of attribute campaign_id.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def campaign_id @campaign_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def name @name end |
#negative_keywords ⇒ Object
Returns the value of attribute negative_keywords.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def negative_keywords @negative_keywords end |
#region_ids ⇒ Object
Returns the value of attribute region_ids.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def region_ids @region_ids end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def status @status end |
#tracking_params ⇒ Object
Returns the value of attribute tracking_params.
3 4 5 |
# File 'lib/services/ad_group.rb', line 3 def tracking_params @tracking_params end |
Class Method Details
.add(params) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/services/ad_group.rb', line 27 def self.add(params) if params.kind_of?(Array) batch_add(params) else params.id = YandexDirect.request(SERVICE, 'add', {"AdGroups": [params.parameters]})["AddResults"].first["Id"] params end end |
.list(params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/services/ad_group.rb', line 15 def self.list(params) selection_criteria = {"Types": ["TEXT_AD_GROUP"]} selection_criteria["CampaignIds"] = params[:campaign_ids] if params[:campaign_ids].present? selection_criteria["Ids"] = params[:ids] if params[:ids].present? ad_groups = YandexDirect.request(SERVICE, 'get', { "SelectionCriteria": selection_criteria, "FieldNames": ['Id', 'Name', 'CampaignId', 'Status', 'RegionIds', 'TrackingParams', 'NegativeKeywords'] })["AdGroups"] (ad_groups || []).map{|c| new({ name: c["Name"], id: c["Id"], status: c["Status"], campaign_id: c["CampaignId"], region_ids: c["RegionIds"], tracking_params: c["TrackingParams"], negative_keywords: c["NegativeKeywords"]})} end |
.update(params) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/services/ad_group.rb', line 36 def self.update(params) if params.kind_of?(Array) batch_update(params) else params.id = YandexDirect.request(SERVICE, 'update', {"AdGroups": [params.update_parameters]})["UpdateResults"].first["Id"] params end end |
Instance Method Details
#parameters ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/services/ad_group.rb', line 45 def parameters hash = {"Name": @name, "CampaignId": @campaign_id, "RegionIds": @region_ids || [0], "TrackingParams": @tracking_params } hash["NegativeKeywords"] = @negative_keywords if @negative_keywords.present? hash end |
#update_parameters ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/services/ad_group.rb', line 55 def update_parameters hash = {"Name": @name, "RegionIds": @region_ids || [0], "TrackingParams": @tracking_params, "Id": @id } hash["NegativeKeywords"] = @negative_keywords if @negative_keywords.present? hash end |