Exemple #1
0
class _BulkAdGroupAdExtensionAssociation(_BulkAdExtensionAssociation):
    """ This abstract class provides properties that are shared by all bulk ad group ad extension association classes. """

    def __init__(self,
                 ad_extension_id_to_entity_id_association=None,
                 status=None,
                 editorial_status=None):
        super(_BulkAdGroupAdExtensionAssociation, self).__init__(
            ad_extension_id_to_entity_id_association,
            status,
            editorial_status,
        )
        self._ad_group_name = None
        self._campaign_name = None

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, '_campaign_name', v)
        )
    ]

    def process_mappings_from_row_values(self, row_values):
        super(_BulkAdGroupAdExtensionAssociation, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, _BulkAdGroupAdExtensionAssociation._MAPPINGS)

    @property
    def ad_group_name(self):
        """ The name of the ad group that the ad extension is associated.

        Corresponds to the 'AdGroup' field in the bulk file.

        :rtype str
        """

        return self._ad_group_name

    @property
    def campaign_name(self):
        """ The name of the campaign containing the ad group that the ad extension is associated.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name
Exemple #2
0
class _BulkNegativeSiteIdentifier(_BulkEntityIdentifier):
    def __init__(self, status=None, entity_id=None, entity_name=None):
        self._status = status
        self._entity_id = entity_id
        self._entity_name = entity_name

    @property
    def status(self):
        return self._status

    @property
    def entity_id(self):
        return self._entity_id

    @property
    def entity_name(self):
        return self._entity_name

    @property
    def _parent_column_name(self):
        raise NotImplementedError()

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c._status),
            csv_to_field=lambda c, v: setattr(c, '_status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: None if c._entity_id == 0 else bulk_str(c._entity_id),
            csv_to_field=lambda c, v: setattr(c, '_entity_id', int(v) if v else 0)
        ),
        _DynamicColumnNameMapping(
            header_func=lambda c: c._parent_column_name,
            field_to_csv=lambda c: c._entity_name,
            csv_to_field=lambda c, v: setattr(c, '_entity_name', v)
        )
    ]

    @property
    def is_delete_row(self):
        return self._status == 'Deleted'

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, _BulkNegativeSiteIdentifier._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkNegativeSiteIdentifier._MAPPINGS)
class BulkProductAd(_BulkAd):
    """ Represents a product ad.

    This class exposes the :attr:`product_ad` property that can be read and written as fields of the Product Ad record in a bulk file.

    For more information, see Product Ad at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkProductAd, self).__init__(ad_group_id, campaign_name,
                                            ad_group_name, ad)
        self.product_ad = ad

    @property
    def product_ad(self):
        """ The product ad.

        See Product Ad at: https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad

    @product_ad.setter
    def product_ad(self, product_ad):
        if product_ad is not None and not isinstance(product_ad, ProductAd):
            raise ValueError('Not an instance of ProductAd')
        self._ad = product_ad

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.PromotionalText,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.product_ad.PromotionalText, c.product_ad.Id),
                           csv_to_field=lambda c, v: setattr(
                               c.product_ad, 'PromotionalText', v
                               if v else '')),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.product_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductAd')
        self.product_ad.Type = 'Product'
        super(BulkProductAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkProductAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.product_ad, 'product_ad')
        super(BulkProductAd,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkProductAd._MAPPINGS)
Exemple #4
0
class BulkCalloutAdExtension(_BulkAdExtensionBase):
    """ Represents a callout ad extension.

    This class exposes the :attr:`callout_ad_extension` property that can be read and written
    as fields of the Callout Ad Extension record in a bulk file.

    For more information, see Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, ad_extension=None):
        if ad_extension and not isinstance(ad_extension, _CalloutAdExtension):
            raise ValueError(
                'The type of ad_extension is: {0}, should be: {1}'.format(
                    type(ad_extension), 'CalloutAdExtension'))
        super(BulkCalloutAdExtension, self).__init__(account_id=account_id,
                                                     ad_extension=ad_extension)

    @property
    def callout_ad_extension(self):
        """ The callout ad extension.

        see Callout Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad_extension

    @callout_ad_extension.setter
    def callout_ad_extension(self, value):
        self._ad_extension = value

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.CalloutText,
                           field_to_csv=lambda c: c.callout_ad_extension.Text,
                           csv_to_field=lambda c, v: setattr(
                               c.callout_ad_extension, 'Text', v))
    ]

    def process_mappings_from_row_values(self, row_values):
        self.callout_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'CalloutAdExtension')
        self.callout_ad_extension.Type = 'CalloutAdExtension'
        super(BulkCalloutAdExtension,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCalloutAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.callout_ad_extension,
                                         'callout_ad_extension')
        super(BulkCalloutAdExtension,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCalloutAdExtension._MAPPINGS)
Exemple #5
0
class BulkCampaignLabel(_BulkLabelAssociation):
    """ Represents a campaign label.

    Defines an association record between a Campaign and a Label that can be uploaded and downloaded in a bulk file.

    For more information, see Campaign Label at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, label_association=None, status=None, campaign=None):
        super(BulkCampaignLabel, self).__init__(label_association, status)
        self._campaign = campaign

    @property
    def campaign(self):
        """ The campaign name of the Campaign Management Service.

        A subset of Label properties are available in the Ad Group record.
        """

        return self._campaign

    @campaign.setter
    def campaign(self, value):
        self._campaign = value

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Campaign,
                           field_to_csv=lambda c: c.campaign,
                           csv_to_field=lambda c, v: setattr(c, 'campaign', v))
    ]

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        super(BulkCampaignLabel,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkCampaignLabel._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        super(BulkCampaignLabel,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkCampaignLabel._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignLabel, self).read_additional_data(stream_reader)
Exemple #6
0
class BulkCampaignNegativeDynamicSearchAdTarget(_SingleRecordBulkEntity):
    """ Represents a Campaign Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`negative_campaign_criterion` property that can be read and written as fields of the
    Campaign Negative Dynamic Search Ad Target record in a bulk file.

    For more information, see Campaign Negative Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836839.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 campaign_name=None,
                 status=None,
                 negative_campaign_criterion=None):
        super(BulkCampaignNegativeDynamicSearchAdTarget, self).__init__()

        self._campaign_name = campaign_name
        self._status = status
        self._negative_campaign_criterion = negative_campaign_criterion


    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: c.status,
            csv_to_field=lambda c, v: setattr(c, 'status', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.negative_campaign_criterion.CampaignId),
            csv_to_field=lambda c, v: setattr(c.negative_campaign_criterion, 'CampaignId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(c.negative_campaign_criterion),
            csv_to_field=lambda c, v: csv_to_field_WebpageParameter_CriterionName(c.negative_campaign_criterion, v)
        ),
        _ComplexBulkMapping(
            entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(c.negative_campaign_criterion, v),
            csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(v, c.negative_campaign_criterion)
        )
    ]

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def status(self):
        """ The status of the Campaign Criterion

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def negative_campaign_criterion(self):
        """ Defines a Campaign Criterion """

        return self._negative_campaign_criterion

    @negative_campaign_criterion.setter
    def negative_campaign_criterion(self, negative_campaign_criterion):
        self._negative_campaign_criterion = negative_campaign_criterion

    def process_mappings_from_row_values(self, row_values):
        self._negative_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeCampaignCriterion')
        self._negative_campaign_criterion.Type = 'NegativeCampaignCriterion'
        self._negative_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('Webpage')
        self._negative_campaign_criterion.Criterion.Type = 'Webpage'

        row_values.convert_to_entity(self, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.negative_campaign_criterion, 'negative_campaign_criterion')
        self.convert_to_values(row_values, BulkCampaignNegativeDynamicSearchAdTarget._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignNegativeDynamicSearchAdTarget, self).read_additional_data(stream_reader)
class BulkResponsiveSearchAd(_BulkAd):
    """ Represents a Responsive Search Ad.

    This class exposes the :attr:`responsive_search_ad` property that can be read and written as fields of the Responsive Search Ad record in a bulk file.

    For more information, see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkResponsiveSearchAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self._ad = ad

    @property
    def responsive_search_ad(self):
        """ The responsive search ad.

        see Responsive Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.
        """

        return self._ad

    @responsive_search_ad.setter
    def responsive_search_ad(self, rsa):
        if rsa is not None and not isinstance(rsa, ResponsiveSearchAd):
            raise ValueError('Not an instance of ResponsiveSearchAd')
        self._ad = rsa

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Path1,
            field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Path1),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path1', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Path2,
            field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Path2),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Path2', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Domain,
            field_to_csv=lambda c: bulk_optional_str(c.responsive_search_ad.Domain),
            csv_to_field=lambda c, v: setattr(c.responsive_search_ad, 'Domain', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Headline,
            field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(c.responsive_search_ad.Headlines),
            csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(c.responsive_search_ad.Headlines, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Description,
            field_to_csv=lambda c: field_to_csv_Rsa_TextAssetLinks(c.responsive_search_ad.Descriptions),
            csv_to_field=lambda c, v: csv_to_field_Rsa_TextAssetLinks(c.responsive_search_ad.Descriptions ,v)
        )
    ]

    def process_mappings_from_row_values(self, row_values):
        self.responsive_search_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveSearchAd')
        self.responsive_search_ad.Type = 'ResponsiveSearch'
        super(BulkResponsiveSearchAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkResponsiveSearchAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.responsive_search_ad, 'responsive_search_ad')
        super(BulkResponsiveSearchAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkResponsiveSearchAd._MAPPINGS)
Exemple #8
0
class BulkCampaignProfileCriterion(_SingleRecordBulkEntity):
    """ The base class for campaign level profile criterion that can be read or written in a bulk file.

    This class exposes the :attr:`biddable_campaign_criterion` property that can be read and written in a bulk file.

    For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(
        self,
        biddable_campaign_criterion=None,
        campaign_name=None,
    ):
        super(BulkCampaignProfileCriterion, self).__init__()

        self._biddable_campaign_criterion = biddable_campaign_criterion
        self._campaign_name = campaign_name

    _MAPPINGS = [
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.Status),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'Status', v
                               if v else None)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.CampaignId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'CampaignId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.BidAdjustment,
            field_to_csv=lambda c: field_to_csv_BidAdjustment(
                c.biddable_campaign_criterion),
            csv_to_field=lambda c, v: csv_to_field_BidAdjustment(
                c.biddable_campaign_criterion,
                float(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Profile,
            field_to_csv=lambda c: c.profile_name,
            csv_to_field=lambda c, v: setattr(c, 'profile_name', v)),
        _SimpleBulkMapping(
            _StringTable.ProfileId,
            field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.
                                            Criterion.ProfileId),
            csv_to_field=lambda c, v: setattr(
                c.biddable_campaign_criterion.Criterion, 'ProfileId',
                int(v) if v else None)),
    ]

    @property
    def biddable_campaign_criterion(self):
        """ Defines a Campaign Criterion """

        return self._biddable_campaign_criterion

    @biddable_campaign_criterion.setter
    def biddable_campaign_criterion(self, biddable_campaign_criterion):
        self._biddable_campaign_criterion = biddable_campaign_criterion

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_campaign_criterion,
                                         'biddable_campaign_criterion')
        self.convert_to_values(row_values,
                               BulkCampaignProfileCriterion._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BiddableCampaignCriterion')
        self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion'
        self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'ProfileCriterion')
        self._biddable_campaign_criterion.Criterion.ProfileType = self.profile_type(
        )
        self._biddable_campaign_criterion.Criterion.Type = 'ProfileCriterion'
        self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BidMultiplier')
        self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier'
        row_values.convert_to_entity(self,
                                     BulkCampaignProfileCriterion._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignProfileCriterion,
              self).read_additional_data(stream_reader)

    @abstractmethod
    def profile_type(self):
        pass
class BulkExperiment(_SingleRecordBulkEntity):
    """ Represents an experiment.

    This class exposes the property :attr:`experiment` that can be read and written as fields of the Experiment record
    in a bulk file.

    For more information, see Experiment at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, experiment=None):
        super(BulkExperiment, self).__init__()
        self._experiment = experiment

    @property
    def experiment(self):
        """ The experiment.
        """
        return self._experiment

    @experiment.setter
    def experiment(self, experiment):
        self._experiment = experiment

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.experiment.Id),
            csv_to_field=lambda c, v: setattr(c.experiment, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: c.experiment.ExperimentStatus,
            csv_to_field=lambda c, v: setattr(c.experiment, 'ExperimentStatus',
                                              v)),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: c.experiment.Name,
            csv_to_field=lambda c, v: setattr(c.experiment, 'Name', v)),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: bulk_date_str(c.experiment.StartDate),
            csv_to_field=lambda c, v: setattr(c.experiment, 'StartDate',
                                              parse_date(v))),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: bulk_date_str(c.experiment.EndDate),
            csv_to_field=lambda c, v: setattr(c.experiment, 'EndDate',
                                              parse_date(v))),
        _SimpleBulkMapping(
            header=_StringTable.TrafficSplitPercent,
            field_to_csv=lambda c: bulk_str(c.experiment.TrafficSplitPercent),
            csv_to_field=lambda c, v: setattr(c.experiment,
                                              'TrafficSplitPercent',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.BaseCampaignId,
            field_to_csv=lambda c: bulk_str(c.experiment.BaseCampaignId),
            csv_to_field=lambda c, v: setattr(c.experiment, 'BaseCampaignId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ExperimentCampaignId,
            field_to_csv=lambda c: bulk_str(c.experiment.ExperimentCampaignId),
            csv_to_field=lambda c, v: setattr(c.experiment,
                                              'ExperimentCampaignId',
                                              int(v) if v else None)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.experiment = _CAMPAIGN_OBJECT_FACTORY_V12.create('Experiment')
        row_values.convert_to_entity(self, BulkExperiment._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self._experiment, 'Experiment')
        self.convert_to_values(row_values, BulkExperiment._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkExperiment, self).read_additional_data(stream_reader)
class BulkImageAdExtension(_BulkAdExtensionBase):
    """ Represents a image ad extension.

    This class exposes the :attr:`image_ad_extension` property that can be read and written
    as fields of the Image Ad Extension record in a bulk file.

    For more information, see Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, ad_extension=None):
        if ad_extension and not isinstance(ad_extension, _ImageAdExtension):
            raise ValueError(
                'The type of ad_extension is: {0}, should be: {1}'.format(
                    type(ad_extension), 'ImageAdExtension'))
        super(BulkImageAdExtension, self).__init__(account_id=account_id,
                                                   ad_extension=ad_extension)

    @property
    def image_ad_extension(self):
        """ The image ad extension.

        see Image Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad_extension

    @image_ad_extension.setter
    def image_ad_extension(self, value):
        self._ad_extension = value

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.DestinationUrl,
            field_to_csv=lambda c: bulk_optional_str(
                c.image_ad_extension.DestinationUrl, c.image_ad_extension.Id),
            csv_to_field=lambda c, v: setattr(
                c.image_ad_extension, 'DestinationUrl', v if v else '')),
        _SimpleBulkMapping(
            header=_StringTable.AltText,
            field_to_csv=lambda c: c.image_ad_extension.AlternativeText,
            csv_to_field=lambda c, v: setattr(c.image_ad_extension,
                                              'AlternativeText', v)),
        _SimpleBulkMapping(
            header=_StringTable.MediaIds,
            #field_to_csv=lambda c: bulk_str(c.image_ad_extension.ImageMediaIds),
            field_to_csv=lambda c: field_to_csv_MediaIds(c.image_ad_extension),
            #csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'ImageMediaIds', int(v))
            csv_to_field=lambda c, v: csv_to_field_MediaIds(
                c.image_ad_extension, v)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.image_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'ImageAdExtension')
        self.image_ad_extension.Type = 'ImageAdExtension'
        super(BulkImageAdExtension,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkImageAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.image_ad_extension,
                                         'image_ad_extension')
        super(BulkImageAdExtension,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkImageAdExtension._MAPPINGS)
class BulkAdGroupDynamicSearchAdTarget(_SingleRecordBulkEntity):
    """ Represents a Ad Group Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the
    Ad Group Dynamic Search Ad Target record in a bulk file.

    For more information, see Ad Group Dynamic Search Ad Target at https://go.microsoft.com/fwlink/?linkid=836837.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self,
                 campaign_name=None,
                 ad_group_name=None,
                 status=None,
                 biddable_ad_group_criterion=None):
        super(BulkAdGroupDynamicSearchAdTarget, self).__init__()

        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._status = status
        self._biddable_ad_group_criterion = biddable_ad_group_criterion
        self._performance_data = None

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(header=_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_ad_group_criterion.AdGroupId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'AdGroupId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)),
        _SimpleBulkMapping(header=_StringTable.Bid,
                           field_to_csv=lambda c: fixed_bid_bulk_str(
                               c.biddable_ad_group_criterion.CriterionBid),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'CriterionBid',
                               parse_fixed_bid(v))),
        _SimpleBulkMapping(
            header=_StringTable.Name,
            field_to_csv=lambda c: field_to_csv_WebpageParameter_CriterionName(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v:
            csv_to_field_WebpageParameter_CriterionName(
                c.biddable_ad_group_criterion, v)),
        _ComplexBulkMapping(
            entity_to_csv=lambda c, v: entity_to_csv_DSAWebpageParameter(
                c.biddable_ad_group_criterion, v),
            csv_to_entity=lambda v, c: csv_to_entity_DSAWebpageParameter(
                v, c.biddable_ad_group_criterion)),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_optional_str(
                c.biddable_ad_group_criterion.TrackingUrlTemplate, c.
                biddable_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'TrackingUrlTemplate', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(
                c.biddable_ad_group_criterion, v)),
    ]

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def status(self):
        """ The status of the Ad Group Criterion

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def biddable_ad_group_criterion(self):
        """ Defines a Ad Group Criterion """

        return self._biddable_ad_group_criterion

    @biddable_ad_group_criterion.setter
    def biddable_ad_group_criterion(self, biddable_ad_group_criterion):
        self._biddable_ad_group_criterion = biddable_ad_group_criterion

    @property
    def performance_data(self):
        return self._performance_data

    def process_mappings_from_row_values(self, row_values):
        self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BiddableAdGroupCriterion')
        self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'
        self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'Webpage')
        self._biddable_ad_group_criterion.Criterion.Type = 'Webpage'
        self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'FixedBid')
        self._biddable_ad_group_criterion.CriterionBid.Type = 'FixedBid'

        row_values.convert_to_entity(
            self, BulkAdGroupDynamicSearchAdTarget._MAPPINGS)

        self._performance_data = PerformanceData.read_from_row_values_or_null(
            row_values)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_ad_group_criterion,
                                         'biddable_ad_group_criterion')
        self.convert_to_values(row_values,
                               BulkAdGroupDynamicSearchAdTarget._MAPPINGS)

        PerformanceData.write_to_row_values_if_not_null(
            self._performance_data, row_values)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupDynamicSearchAdTarget,
              self).read_additional_data(stream_reader)
class BulkRemarketingList(_SingleRecordBulkEntity):
    """ Represents an Remarketing List that can be read or written in a bulk file.

    This class exposes the :attr:`remarketing_list` property that can be read and written as fields of the
    Remarketing List record in a bulk file.

    For more information, see Remarketing List at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(
        self,
        remarketing_list=None,
        status=None,
    ):
        super(BulkRemarketingList, self).__init__()

        self._remarketing_list = remarketing_list
        self._status = status

    _MAPPINGS = [
        _SimpleBulkMapping(header=_StringTable.Status,
                           field_to_csv=lambda c: c.status,
                           csv_to_field=lambda c, v: setattr(c, 'status', v)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Id),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.ParentId),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'ParentId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Audience,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Name),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Name', v)),
        _SimpleBulkMapping(
            _StringTable.Description,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Description),
            csv_to_field=lambda c, v: setattr(c.remarketing_list,
                                              'Description', v)),
        _SimpleBulkMapping(_StringTable.MembershipDuration,
                           field_to_csv=lambda c: bulk_str(c.remarketing_list.
                                                           MembershipDuration),
                           csv_to_field=lambda c, v: setattr(
                               c.remarketing_list, 'MembershipDuration',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Scope,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.Scope),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'Scope', v
                                              if v else None)),
        _SimpleBulkMapping(
            _StringTable.TagId,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.TagId),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'TagId',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.RemarketingRule,
            field_to_csv=lambda c: field_to_csv_RemarketingRule(
                c.remarketing_list),
            csv_to_field=lambda c, v: csv_to_field_RemarketingRule(
                c.remarketing_list, v)),
        _SimpleBulkMapping(
            _StringTable.AudienceSearchSize,
            field_to_csv=lambda c: bulk_str(c.remarketing_list.SearchSize),
            csv_to_field=lambda c, v: setattr(c.remarketing_list, 'SearchSize',
                                              int(v) if v else None)),
    ]

    @property
    def remarketing_list(self):
        """ Defines a Remarketing List """

        return self._remarketing_list

    @remarketing_list.setter
    def remarketing_list(self, remarketing_list):
        self._remarketing_list = remarketing_list

    @property
    def status(self):
        """ The status of the Remarketing List

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.remarketing_list,
                                         'remarketing_list')
        self.convert_to_values(row_values, BulkRemarketingList._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._remarketing_list = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'RemarketingList')
        row_values.convert_to_entity(self, BulkRemarketingList._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkRemarketingList, self).read_additional_data(stream_reader)
Exemple #13
0
class BulkKeyword(_SingleRecordBulkEntity):
    """ Represents a keyword that can be read or written in a bulk file.

    This class exposes the :attr:`keyword` property that can be read and written as fields of the Keyword record in a bulk file.
    Properties of this class and of classes that it is derived from, correspond to fields of the Keyword record in a bulk file.
    For more information, see Keyword at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self, ad_group_id=None, campaign_name=None, ad_group_name=None, keyword=None):
        super(BulkKeyword, self).__init__()
        self._ad_group_id = ad_group_id
        self._keyword = keyword
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._performance_data = None
        self._quality_score_data = None
        self._bid_suggestions = None

    @property
    def ad_group_id(self):
        """ The identifier of the ad group that contains the keyword.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._ad_group_id

    @ad_group_id.setter
    def ad_group_id(self, ad_group_id):
        self._ad_group_id = ad_group_id

    @property
    def keyword(self):
        """ Defines a keyword within an ad group.

        See Keyword at https://docs.microsoft.com/en-us/bingads/campaign-management-service/keyword?view=bingads-12
        """

        return self._keyword

    @keyword.setter
    def keyword(self, keyword):
        self._keyword = keyword

    @property
    def campaign_name(self):
        """ The name of the campaign that contains the keyword.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the ad group that contains the keyword.

        Corresponds to the 'Ad Group' field in the bulk file.

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def quality_score_data(self):
        """ The quality score data for the keyword.

        :rtype: QualityScoreData
        """

        return self._quality_score_data

    @property
    def performance_data(self):
        """ The historical performance data for the keyword.

        :rtype: PerformanceData
        """

        return self._performance_data

    @property
    def bid_suggestions(self):
        """ The bid suggestion data for the keyword.

        :rtype: BidSuggestionData
        """

        return self._bid_suggestions

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.keyword.Status),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Status',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Id',
                int(v) if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_group_id),
            csv_to_field=lambda c, v: setattr(
                c,
                '_ad_group_id',
                int(v) if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, '_campaign_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Keyword,
            field_to_csv=lambda c: c.keyword.Text,
            csv_to_field=lambda c, v: setattr(c.keyword, 'Text', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EditorialStatus,
            field_to_csv=lambda c: bulk_str(c.keyword.EditorialStatus),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'EditorialStatus',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.MatchType,
            field_to_csv=lambda c: bulk_str(c.keyword.MatchType),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'MatchType',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.DestinationUrl,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.DestinationUrl, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'DestinationUrl',
                v if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Bid,
            field_to_csv=lambda c: keyword_bid_bulk_str(c.keyword.Bid, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Bid',
                parse_keyword_bid(v)
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param1,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param1, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param1',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param2,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param2, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param2',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.Param3,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.Param3, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(
                c.keyword,
                'Param3',
                v if v else ''
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalUrls, c.keyword.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.keyword.FinalMobileUrls, c.keyword.Id),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.keyword.FinalMobileUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.keyword.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.keyword, 'TrackingUrlTemplate', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.keyword),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.keyword, v)
        ),
        _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrlSuffix,
            field_to_csv=lambda c: bulk_optional_str(c.keyword.FinalUrlSuffix, c.keyword.Id),
            csv_to_field=lambda c, v: setattr(c.keyword, 'FinalUrlSuffix', v)
        ),
    ]

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self._keyword, 'keyword')
        self.convert_to_values(row_values, BulkKeyword._MAPPINGS)
        if not exclude_readonly_data:
            QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values)
            PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values)

    def process_mappings_from_row_values(self, row_values):
        self._keyword = _CAMPAIGN_OBJECT_FACTORY_V12.create('Keyword')
        row_values.convert_to_entity(self, BulkKeyword._MAPPINGS)
        self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values)
        self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)

    def read_additional_data(self, stream_reader):
        success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion)

        while success:
            if self._bid_suggestions is None:
                self._bid_suggestions = BidSuggestionData()

            if isinstance(next_bid_suggestion, BulkKeywordBestPositionBid):
                self._bid_suggestions.best_position = next_bid_suggestion
            elif isinstance(next_bid_suggestion, BulkKeywordMainLineBid):
                self._bid_suggestions.main_line = next_bid_suggestion
            elif isinstance(next_bid_suggestion, BulkKeywordFirstPageBid):
                self._bid_suggestions.first_page = next_bid_suggestion

            success, next_bid_suggestion = stream_reader.try_read(BulkKeywordBidSuggestion)

    def write_additional_data(self, row_writer):
        if self.bid_suggestions is not None:
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.best_position, row_writer)
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.main_line, row_writer)
            BulkKeywordBidSuggestion.write_if_not_null(self.bid_suggestions.first_page, row_writer)
Exemple #14
0
class _BulkAdExtensionIdentifier(_BulkEntityIdentifier):
    def __init__(self,
                 account_id=None,
                 ad_extension_id=None,
                 status=None,
                 version=None):
        super(_BulkAdExtensionIdentifier, self).__init__()

        self._account_id = account_id
        self._ad_extension_id = ad_extension_id
        self._status = status
        self._version = version

    @property
    def account_id(self):
        return self._account_id

    @account_id.setter
    def account_id(self, account_id):
        self._account_id = account_id

    @property
    def ad_extension_id(self):
        return self._ad_extension_id

    @ad_extension_id.setter
    def ad_extension_id(self, ad_extension_id):
        self._ad_extension_id = ad_extension_id

    @property
    def status(self):
        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def version(self):
        return self._version

    @version.setter
    def version(self, version):
        self._version = version

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.status),
            csv_to_field=lambda c, v: setattr(c, 'status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id),
            csv_to_field=lambda c, v: setattr(c, 'ad_extension_id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Version,
            field_to_csv=lambda c: bulk_str(c.version),
            csv_to_field=lambda c, v: setattr(c, 'version', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.account_id),
            csv_to_field=lambda c, v: setattr(c, 'account_id', int(v) if v else None)
        ),
    ]

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, _BulkAdExtensionIdentifier._MAPPINGS)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkAdExtensionIdentifier._MAPPINGS)

    def __eq__(self, other):
        raise NotImplementedError()

    @property
    def is_delete_row(self):
        return self._status == 'Deleted'
Exemple #15
0
class _BulkAdExtensionAssociation(_SingleRecordBulkEntity):
    """ This class provides properties that are shared by all bulk ad extension association classes.

    For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127.
    """

    def __init__(self,
                 ad_extension_id_to_entity_id_association=None,
                 status=None,
                 editorial_status=None):
        super(_BulkAdExtensionAssociation, self).__init__()

        self._status = status
        self._ad_extension_id_to_entity_id_association = ad_extension_id_to_entity_id_association
        self._editorial_status = editorial_status
        self._performance_data = None

    @property
    def ad_extension_id_to_entity_id_association(self):
        """ Defines an association relationship between an ad extension and a supported entity, for example a campaign or ad group.

        :rtype: AdExtensionIdToEntityIdAssociation
        """

        return self._ad_extension_id_to_entity_id_association

    @ad_extension_id_to_entity_id_association.setter
    def ad_extension_id_to_entity_id_association(self, value):
        self._ad_extension_id_to_entity_id_association = value

    @property
    def status(self):
        """ The status of the ad extension association.

        The value is Active if the EntityId and AdExtensionId are associated. The value is Deleted if the association is removed.
        Corresponds to the 'Status' field in the bulk file.

        :rtype: str
        """

        return self._status

    @status.setter
    def status(self, status):
        self._status = status

    @property
    def editorial_status(self):
        """ The editorial status of the ad extension and associated entity.

        For more information, see AdExtensionEditorialStatus at https://go.microsoft.com/fwlink/?linkid=846127.
        Corresponds to the 'Editorial Status' field in the bulk file.

        :rtype: str
        """

        return self._editorial_status

    @editorial_status.setter
    def editorial_status(self, editorial_status):
        self._editorial_status = editorial_status

    @property
    def performance_data(self):
        return self._performance_data

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.AdExtensionId),
            csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'AdExtensionId', int(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.status),
            csv_to_field=lambda c, v: setattr(c, '_status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_extension_id_to_entity_id_association.EntityId),
            csv_to_field=lambda c, v: setattr(c.ad_extension_id_to_entity_id_association, 'EntityId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EditorialStatus,
            field_to_csv=lambda c: c.editorial_status,
            csv_to_field=lambda c, v: setattr(c, '_editorial_status', v if v else None)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self._ad_extension_id_to_entity_id_association = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdExtensionIdToEntityIdAssociation')
        row_values.convert_to_entity(self, _BulkAdExtensionAssociation._MAPPINGS)
        self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(
            self._ad_extension_id_to_entity_id_association,
            'ad_extension_id_to_entity_id_association'
        )
        self.convert_to_values(row_values, _BulkAdExtensionAssociation._MAPPINGS)
        if not exclude_readonly_data:
            PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values)

    def read_additional_data(self, stream_reader):
        super(_BulkAdExtensionAssociation, self).read_additional_data(stream_reader)
Exemple #16
0
class _BulkAdExtensionBase(_SingleRecordBulkEntity):
    """ This class provides properties that are shared by all bulk ad extension classes.

    *See also:*

    * :class:`.BulkCallAdExtension`
    * :class:`.BulkImageAdExtension`
    * :class:`.BulkLocationAdExtension`
    * :class:`.BulkSiteLinkAdExtension`
    """

    def __init__(self, account_id=None, ad_extension=None):
        super(_BulkAdExtensionBase, self).__init__()

        self._account_id = account_id
        self._ad_extension = ad_extension

    @property
    def account_id(self):
        """ The ad extension's parent account identifier.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._account_id

    @account_id.setter
    def account_id(self, account_id):
        self._account_id = account_id

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Status),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Id),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Version,
            field_to_csv=lambda c: bulk_str(c._ad_extension.Version),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'Version', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.account_id),
            csv_to_field=lambda c, v: setattr(c, 'account_id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: field_to_csv_SchedulingStartDate(c._ad_extension.Scheduling),
            csv_to_field=lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'StartDate', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: field_to_csv_SchedulingEndDate(c._ad_extension.Scheduling),
            csv_to_field = lambda c, v: csv_to_field_Date(c._ad_extension.Scheduling, 'EndDate', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdSchedule,
            field_to_csv=lambda c: field_to_csv_AdSchedule(c._ad_extension.Scheduling),
            csv_to_field=lambda c, v: csv_to_field_AdSchedule(c._ad_extension.Scheduling, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.UseSearcherTimeZone,
            field_to_csv=lambda c: field_to_csv_UseSearcherTimeZone(c._ad_extension.Scheduling),
            csv_to_field=lambda c, v: setattr(c._ad_extension.Scheduling, 'UseSearcherTimeZone', parse_bool(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.DevicePreference,
            field_to_csv=lambda c: bulk_device_preference_str(c._ad_extension.DevicePreference),
            csv_to_field=lambda c, v: setattr(c._ad_extension, 'DevicePreference', parse_device_preference(v))
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        row_values.convert_to_entity(self, _BulkAdExtensionBase._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkAdExtensionBase._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(_BulkAdExtensionBase, self).read_additional_data(stream_reader)
Exemple #17
0
class BulkCampaignAudienceAssociation(_SingleRecordBulkEntity):
    """ Base class for all Campaign Audience Association subclasses that can be read or written in a bulk file.

    *See also:*

    * :class:`.BulkCampaignCustomAudienceAssociation`
    * :class:`.BulkCampaignInMarketAudienceAssociation`
    * :class:`.BulkCampaignProductAudienceAssociation`
    * :class:`.BulkCampaignRemarketingListAssociation`
    * :class:`.BulkCampaignSimilarRemarketingListAssociation`
    """
    def __init__(self,
                 biddable_campaign_criterion=None,
                 campaign_name=None,
                 audience_name=None):
        super(BulkCampaignAudienceAssociation, self).__init__()

        self._biddable_campaign_criterion = biddable_campaign_criterion
        self._campaign_name = campaign_name
        self._audience_name = audience_name
        self._performance_data = None

    _MAPPINGS = [
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.Status),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'Status', v
                               if v else None)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_campaign_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_campaign_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_campaign_criterion.CampaignId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_campaign_criterion, 'CampaignId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.Audience,
            field_to_csv=lambda c: c.audience_name,
            csv_to_field=lambda c, v: setattr(c, 'audience_name', v)),
        _SimpleBulkMapping(
            _StringTable.BidAdjustment,
            field_to_csv=lambda c: field_to_csv_BidAdjustment(
                c.biddable_campaign_criterion),
            csv_to_field=lambda c, v: csv_to_field_BidAdjustment(
                c.biddable_campaign_criterion,
                float(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.AudienceId,
            field_to_csv=lambda c: field_to_csv_CriterionAudienceId(
                c.biddable_campaign_criterion),
            csv_to_field=lambda c, v: csv_to_field_CriterionAudienceId(
                c.biddable_campaign_criterion,
                int(v) if v else None)),
    ]

    @property
    def biddable_campaign_criterion(self):
        """ Defines a Biddable Campaign Criterion """

        return self._biddable_campaign_criterion

    @biddable_campaign_criterion.setter
    def biddable_campaign_criterion(self, biddable_campaign_criterion):
        self._biddable_campaign_criterion = biddable_campaign_criterion

    @property
    def campaign_name(self):
        """ Defines the name of the Campaign.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def audience_name(self):
        """ Defines the name of the Audience

        :rtype: str
        """

        return self._audience_name

    @audience_name.setter
    def audience_name(self, audience_name):
        self._audience_name = audience_name

    @property
    def performance_data(self):
        return self._performance_data

    def process_mappings_from_row_values(self, row_values):
        self._biddable_campaign_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BiddableCampaignCriterion')
        self._biddable_campaign_criterion.Type = 'BiddableCampaignCriterion'
        self._biddable_campaign_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'AudienceCriterion')
        self._biddable_campaign_criterion.Criterion.Type = 'AudienceCriterion'
        self._biddable_campaign_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BidMultiplier')
        self._biddable_campaign_criterion.CriterionBid.Type = 'BidMultiplier'
        row_values.convert_to_entity(self,
                                     BulkCampaignAudienceAssociation._MAPPINGS)

        self._performance_data = PerformanceData.read_from_row_values_or_null(
            row_values)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_campaign_criterion,
                                         'biddable_campaign_criterion')
        self.convert_to_values(row_values,
                               BulkCampaignAudienceAssociation._MAPPINGS)

        PerformanceData.write_to_row_values_if_not_null(
            self._performance_data, row_values)

    def read_additional_data(self, stream_reader):
        super(BulkCampaignAudienceAssociation,
              self).read_additional_data(stream_reader)
Exemple #18
0
class BulkSitelinkAdExtension(_BulkAdExtensionBase):
    """ Represents a sitelink ad extension.

    This class exposes the :attr:`sitelink_ad_extension` property that can be read and written
    as fields of the Sitelink Ad Extension record in a bulk file.

    For more information, see Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, ad_extension=None):
        if ad_extension and not isinstance(ad_extension, _SitelinkAdExtension):
            raise ValueError(
                'The type of ad_extension is: {0}, should be: {1}'.format(
                    type(ad_extension), 'SitelinkAdExtension'))
        super(BulkSitelinkAdExtension,
              self).__init__(account_id=account_id, ad_extension=ad_extension)

    @property
    def sitelink_ad_extension(self):
        """ The sitelink ad extension.

        see Sitelink Ad Extension at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad_extension

    @sitelink_ad_extension.setter
    def sitelink_ad_extension(self, value):
        self._ad_extension = value

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.SiteLinkDescription1,
            field_to_csv=lambda c: c.sitelink_ad_extension.Description1,
            csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension,
                                              'Description1', v)),
        _SimpleBulkMapping(
            header=_StringTable.SiteLinkDescription2,
            field_to_csv=lambda c: c.sitelink_ad_extension.Description2,
            csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension,
                                              'Description2', v)),
        _SimpleBulkMapping(header=_StringTable.DestinationUrl,
                           field_to_csv=lambda c: bulk_optional_str(
                               c.sitelink_ad_extension.DestinationUrl),
                           csv_to_field=lambda c, v: setattr(
                               c.sitelink_ad_extension, 'DestinationUrl', v
                               if v else '')),
        _SimpleBulkMapping(
            header=_StringTable.SiteLinkDisplayText,
            field_to_csv=lambda c: c.sitelink_ad_extension.DisplayText,
            csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension,
                                              'DisplayText', v)),
        _SimpleBulkMapping(header=_StringTable.FinalUrl,
                           field_to_csv=lambda c: field_to_csv_Urls(
                               c.sitelink_ad_extension.FinalUrls),
                           csv_to_field=lambda c, v: csv_to_field_Urls(
                               c.sitelink_ad_extension.FinalUrls, v)),
        _SimpleBulkMapping(header=_StringTable.FinalMobileUrl,
                           field_to_csv=lambda c: field_to_csv_Urls(
                               c.sitelink_ad_extension.FinalMobileUrls),
                           csv_to_field=lambda c, v: csv_to_field_Urls(
                               c.sitelink_ad_extension.FinalMobileUrls, v)),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.sitelink_ad_extension.
                                            TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension,
                                              'TrackingUrlTemplate', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(
                c.sitelink_ad_extension),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(
                c.sitelink_ad_extension, v)),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.sitelink_ad_extension = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'SitelinkAdExtension')
        self.sitelink_ad_extension.Type = 'SitelinkAdExtension'
        super(BulkSitelinkAdExtension,
              self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkSitelinkAdExtension._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.sitelink_ad_extension,
                                         'sitelink_ad_extension')
        super(BulkSitelinkAdExtension,
              self).process_mappings_to_row_values(row_values,
                                                   exclude_readonly_data)
        self.convert_to_values(row_values, BulkSitelinkAdExtension._MAPPINGS)
class BulkAdGroup(_SingleRecordBulkEntity):
    """ Represents an ad group.

    This class exposes the property :attr:`ad_group` that can be read and written as fields of the Ad Group record
    in a bulk file.

    For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self, campaign_id=None, campaign_name=None, ad_group=None):
        super(BulkAdGroup, self).__init__()

        self._campaign_id = campaign_id
        self._campaign_name = campaign_name
        self._ad_group = ad_group

        self._is_expired = None
        self._quality_score_data = None
        self._performance_data = None


    @property
    def campaign_id(self):
        """ The identifier of the campaign that contains the ad group.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._campaign_id

    @campaign_id.setter
    def campaign_id(self, campaign_id):
        self._campaign_id = campaign_id

    @property
    def campaign_name(self):
        """ The name of the campaign that contains the ad group.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group(self):
        """ The AdGroup Data Object of the Campaign Management Service.

        A subset of AdGroup properties are available in the Ad Group record.
        For more information, see Ad Group at https://go.microsoft.com/fwlink/?linkid=846127.
        """
        return self._ad_group

    @ad_group.setter
    def ad_group(self, ad_group):
        self._ad_group = ad_group

    @property
    def is_expired(self):
        """ Indicates whether the AdGroup is expired.

        :rtype: bool
        """

        return self._is_expired

    @property
    def quality_score_data(self):
        """ The quality score data for the ad group.

        :rtype: QualityScoreData
        """
        return self._quality_score_data

    @property
    def performance_data(self):
        """ The historical performance data for the ad group.

        :rtype: PerformanceData
        """

        return self._performance_data

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_group.Id),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: 'Expired' if c.is_expired else bulk_str(c.ad_group.Status),
            csv_to_field=csv_to_status
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.campaign_id),
            csv_to_field=lambda c, v: setattr(c, 'campaign_id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group.Name,
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.StartDate,
            field_to_csv=lambda c: bulk_date_str(c.ad_group.StartDate),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'StartDate', parse_date(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.EndDate,
            field_to_csv=lambda c: bulk_date_str(c.ad_group.EndDate),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'EndDate', parse_date(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.NetworkDistribution,
            field_to_csv=lambda c: bulk_str(c.ad_group.Network),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Network', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdRotation,
            field_to_csv=lambda c: ad_rotation_bulk_str(c.ad_group.AdRotation),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'AdRotation', parse_ad_rotation(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.CpcBid,
            field_to_csv=lambda c: ad_group_bid_bulk_str(c.ad_group.CpcBid),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'CpcBid', parse_ad_group_bid(v))
        ),
        _SimpleBulkMapping(
            header=_StringTable.Language,
            field_to_csv=lambda c: bulk_str(c.ad_group.Language),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'Language', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.BidAdjustment,
            field_to_csv=lambda c: bulk_str(c.ad_group.AudienceAdsBidAdjustment),
            csv_to_field=lambda c, v: setattr(
                c.ad_group,
                'AudienceAdsBidAdjustment',
                int(v) if v else None
            )
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.ad_group.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'TrackingUrlTemplate', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad_group),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad_group, v)
        ),
        _ComplexBulkMapping(bidding_scheme_to_csv, csv_to_bidding_scheme),

        _SimpleBulkMapping(
            header=_StringTable.TargetSetting,
            field_to_csv=lambda c: target_setting_to_csv(c.ad_group),
            csv_to_field=lambda c, v: csv_to_target_setting(c.ad_group, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.PrivacyStatus,
            field_to_csv=lambda c: bulk_str(c.ad_group.PrivacyStatus),
            csv_to_field=lambda c, v: setattr(c.ad_group, 'PrivacyStatus', v if v else None)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.ad_group = _CAMPAIGN_OBJECT_FACTORY_V12.create('AdGroup')

        row_values.convert_to_entity(self, BulkAdGroup._MAPPINGS)

        self._quality_score_data = QualityScoreData.read_from_row_values_or_null(row_values)
        self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self._ad_group, 'AdGroup')
        self.convert_to_values(row_values, BulkAdGroup._MAPPINGS)
        if not exclude_readonly_data:
            QualityScoreData.write_to_row_values_if_not_null(self.quality_score_data, row_values)
            PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroup, self).read_additional_data(stream_reader)
class BulkKeywordBidSuggestion(_BulkObject):
    """ Represents a best position bid suggestion.

    It can only be read from a bulk file by the :class:`.BulkFileReader` when reading the corresponding :class:`.BulkKeyword`.
    An instance of this class can represent a single keyword bid position, and thus one record in the bulk file.
    """
    def __init__(self):
        self._keyword_text = None
        self._bid = None
        self._performance_data = None

    @property
    def keyword_text(self):
        """ The keyword corresponding to the suggested bid.

        Corresponds to the 'Keyword' field in the bulk file.
        :rtype: str
        """

        return self._keyword_text

    @property
    def bid(self):
        """ The suggested bid for the keyword.

        :rtype: float
        """

        return self._bid

    @property
    def performance_data(self):
        """ The historical performance data corresponding to the suggested bid.

        :rtype: PerformanceData
        """

        return self._performance_data

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Keyword,
            field_to_csv=lambda c: bulk_str(c.keyword_text),
            csv_to_field=lambda c, v: setattr(c, '_keyword_text', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.Bid,
            field_to_csv=lambda c: bulk_str(c.bid),
            csv_to_field=lambda c, v: setattr(c, '_bid',
                                              float(v) if v else None)),
    ]

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, BulkKeywordBidSuggestion._MAPPINGS)
        self._performance_data = PerformanceData.read_from_row_values(
            row_values)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, BulkKeywordBidSuggestion._MAPPINGS)
        if not exclude_readonly_data:
            PerformanceData.write_to_row_values_if_not_null(
                self.performance_data, row_values)

    @staticmethod
    def write_if_not_null(keyword_bid_suggestion, row_writer):
        if keyword_bid_suggestion is not None:
            row_writer.write_object_row(keyword_bid_suggestion)
class BulkError(_BulkObject):
    """ Contains bulk file error details in a separate record that corresponds to the record of a :class:`.BulkEntity` derived instance.

    Properties of this class and of classes that it is derived from, correspond to error fields of the 'Error' records in a bulk file.
    For more information, see Bulk File Schema at https://go.microsoft.com/fwlink/?linkid=846127.

    *Example:*

    If you upload a :class:`.BulkCampaign` without setting the campaign name using :meth:`BulkServiceManager.upload_entities,
    and if you request errors to be returned in the results using the corresponding :attr:`SubmitUploadParameters.response_mode`,
    then the upload result file will contain a record that can be read with a :class:`.BulkFileReader` as an instance of :class:`.BulkError`.
    """
    def __init__(self):
        self._error = None
        self._number = None
        self._editorial_location = None
        self._editorial_term = None
        self._editorial_reason_code = None
        self._publisher_countries = None
        self._entity = None
        self._field_path = None

    @property
    def entity(self):
        return self._entity

    @entity.setter
    def entity(self, value):
        self._entity = value

    @property
    def error(self):
        """ The error code, for example 'CampaignServiceEditorialValidationError'.

        Corresponds to the 'Error' field in the bulk file.
        For more information, see Bing Ads Operation Error Codes at https://go.microsoft.com/fwlink/?linkid=846127.

        :rtype: str
        """

        return self._error

    @property
    def number(self):
        """ The error number, for example '1042'.

        Corresponds to the 'Error Number' field in the bulk file.
        For more information, see Bing Ads Operation Error Codes at https://go.microsoft.com/fwlink/?linkid=846127.

        :rtype: int
        """

        return self._number

    @property
    def editorial_location(self):
        """ The location of the entity property that resulted in the editorial error, for example 'AdDescription'.

        Corresponds to the 'Editorial Location' field in the bulk file.

        :rtype: str
        """

        return self._editorial_location

    @property
    def editorial_term(self):
        """ The term that resulted in the editorial error, for example 'bing'.

        Corresponds to the 'Editorial Term' field in the bulk file.

        :rtype: str
        """

        return self._editorial_term

    @property
    def editorial_reason_code(self):
        """ The term that resulted in the editorial error, for example '17'.

        Corresponds to the 'Editorial Reason Code' field in the bulk file.
        For more information, see Bing Ads Editorial Failure Reason Codes at https://go.microsoft.com/fwlink/?linkid=846127.

        :rtype: int
        """

        return self._editorial_reason_code

    @property
    def field_path(self):
        """ The term that resulted in the editorial error.

        Corresponds to the 'Field Path' field in the bulk file.

        :rtype: int
        """

        return self._field_path

    @property
    def publisher_countries(self):
        """ The publisher countries where editorial restriction is enforced, for example 'US'.

        Corresponds to the 'Publisher Countries' field in the bulk file.

        *Remarks:*

        In a bulk file, the list of publisher countries are delimited with a semicolon (;).

        :rtype: str
        """

        return self._publisher_countries

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Error,
            field_to_csv=lambda c: bulk_str(c.error),
            csv_to_field=lambda c, v: setattr(c, '_error', v if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ErrorNumber,
            field_to_csv=lambda c: bulk_str(c.number),
            csv_to_field=lambda c, v: setattr(c, '_number',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.EditorialLocation,
            field_to_csv=lambda c: bulk_str(c.editorial_location),
            csv_to_field=lambda c, v: setattr(c, '_editorial_location', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.EditorialReasonCode,
            field_to_csv=lambda c: bulk_str(c.editorial_reason_code),
            csv_to_field=lambda c, v: setattr(c, '_editorial_reason_code',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.EditorialTerm,
            field_to_csv=lambda c: bulk_str(c.editorial_term),
            csv_to_field=lambda c, v: setattr(c, '_editorial_term', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.PublisherCountries,
            field_to_csv=lambda c: bulk_str(c.publisher_countries),
            csv_to_field=lambda c, v: setattr(c, '_publisher_countries', v
                                              if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.FieldPath,
            field_to_csv=lambda c: bulk_str(c.field_path),
            csv_to_field=lambda c, v: setattr(c, '_field_path', v
                                              if v else None)),
    ]

    def can_enclose_in_multiline_entity(self):
        return super(BulkError, self).can_enclose_in_multiline_entity()

    def enclose_in_multiline_entity(self):
        return super(BulkError, self).enclose_in_multiline_entity()

    def read_from_row_values(self, row_values):
        row_values.convert_to_entity(self, BulkError._MAPPINGS)

    def read_related_data_from_stream(self, stream_reader):
        return super(BulkError,
                     self).read_related_data_from_stream(stream_reader)

    def write_to_row_values(self, row_values, exclude_readonly_data):
        self.entity.write_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkError._MAPPINGS)

    def write_to_stream(self, stream_writer, exclude_readonly_data):
        return super(BulkError, self).write_to_stream(stream_writer,
                                                      exclude_readonly_data)
class _BulkAd(_SingleRecordBulkEntity):
    """ This abstract base class provides properties that are shared by all bulk ad classes.

    *See also:*

    * :class:`.BulkProductAd`
    * :class:`.BulkTextAd`
    * :class:`.BulkAppInstallAd`
    * :class:`.BulkExpandedTextAd`
    * :class:`.BulkDynamicSearchAd`
    * :class:`.BulkResponsiveAd`
    * :class:`.BulkResponsiveSearchAd`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(_BulkAd, self).__init__()

        self._ad_group_id = ad_group_id
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._ad = ad
        self._performance_data = None

    @property
    def ad_group_id(self):
        """ The identifier of the ad group that contains the ad.

        Corresponds to the 'Parent Id' field in the bulk file.

        :rtype: int
        """

        return self._ad_group_id

    @ad_group_id.setter
    def ad_group_id(self, ad_group_id):
        self._ad_group_id = ad_group_id

    @property
    def campaign_name(self):
        """ The name of the campaign that contains the ad.

        Corresponds to the 'Campaign' field in the bulk file.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the ad group that contains the ad.

        Corresponds to the 'Ad Group' field in the bulk file.

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def ad(self):
        """ The type of ad.

        """

        return self._ad

    @ad.setter
    def ad(self, ad):
        self._ad = ad

    @property
    def performance_data(self):
        """ The historical performance data for the ad.

        :rtype: PerformanceData
        """

        return self._performance_data

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Status,
            field_to_csv=lambda c: bulk_str(c.ad.Status),
            csv_to_field=lambda c, v: setattr(c.ad, 'Status', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad.Id),
            csv_to_field=lambda c, v: setattr(c.ad, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_group_id),
            csv_to_field=lambda c, v: setattr(c, '_ad_group_id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, '_campaign_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, '_ad_group_name', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.EditorialStatus,
            field_to_csv=lambda c: c.ad.EditorialStatus,
            csv_to_field=lambda c, v: setattr(c.ad, 'EditorialStatus', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.DevicePreference,
            field_to_csv=lambda c: bulk_device_preference_str(c.ad.DevicePreference),
            csv_to_field=lambda c, v: setattr(c.ad, 'DevicePreference', parse_device_preference(v))
        ),

        _SimpleBulkMapping(
            header=_StringTable.AdFormatPreference,
            field_to_csv=lambda c: bulk_str(c.ad.AdFormatPreference),
            csv_to_field=lambda c, v: setattr(c.ad, 'AdFormatPreference', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalUrls),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.ad.FinalUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.ad.FinalMobileUrls),
            csv_to_field=lambda c, v: csv_to_field_Urls(c.ad.FinalMobileUrls, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_str(c.ad.TrackingUrlTemplate),
            csv_to_field=lambda c, v: setattr(c.ad, 'TrackingUrlTemplate', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad),
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad, v)
        ),
    ]

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self.convert_to_values(row_values, _BulkAd._MAPPINGS)
        if not exclude_readonly_data:
            PerformanceData.write_to_row_values_if_not_null(self.performance_data, row_values)

    def process_mappings_from_row_values(self, row_values):
        row_values.convert_to_entity(self, _BulkAd._MAPPINGS)
        self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)

    def read_additional_data(self, stream_reader):
        super(_BulkAd, self).read_additional_data(stream_reader)
class BulkAdGroupRadiusCriterion(_SingleRecordBulkEntity):
    """ Represents an Ad Group Radius Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`biddable_ad_group_criterion` property that can be read and written as fields of the
    Ad Group Radius Criterion record in a bulk file.

    For more information, see Ad Group Radius Criterion at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(
        self,
        biddable_ad_group_criterion=None,
        campaign_name=None,
        ad_group_name=None,
    ):
        super(BulkAdGroupRadiusCriterion, self).__init__()

        self._biddable_ad_group_criterion = biddable_ad_group_criterion
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name

    _MAPPINGS = [
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_ad_group_criterion.Status),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'Status', v
                               if v else None)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.biddable_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.biddable_ad_group_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.biddable_ad_group_criterion.AdGroupId),
                           csv_to_field=lambda c, v: setattr(
                               c.biddable_ad_group_criterion, 'AdGroupId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)),
        _SimpleBulkMapping(
            _StringTable.BidAdjustment,
            field_to_csv=lambda c: field_to_csv_BidAdjustment(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v: csv_to_field_BidAdjustment(
                c.biddable_ad_group_criterion,
                float(v) if v else None)),
        _SimpleBulkMapping(_StringTable.Name,
                           field_to_csv=lambda c: field_to_csv_RadiusName(
                               c.biddable_ad_group_criterion),
                           csv_to_field=lambda c, v: csv_to_field_RadiusName(
                               c.biddable_ad_group_criterion, v)),
        _SimpleBulkMapping(_StringTable.Radius,
                           field_to_csv=lambda c: field_to_csv_Radius(
                               c.biddable_ad_group_criterion),
                           csv_to_field=lambda c, v: csv_to_field_Radius(
                               c.biddable_ad_group_criterion,
                               int(v) if v else None)),
        _SimpleBulkMapping(_StringTable.Unit,
                           field_to_csv=lambda c: field_to_csv_RadiusUnit(
                               c.biddable_ad_group_criterion),
                           csv_to_field=lambda c, v: csv_to_field_RadiusUnit(
                               c.biddable_ad_group_criterion, v)),
        _SimpleBulkMapping(
            _StringTable.Latitude,
            field_to_csv=lambda c: field_to_csv_LatitudeDegrees(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v: csv_to_field_LatitudeDegrees(
                c.biddable_ad_group_criterion,
                float(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Longitude,
            field_to_csv=lambda c: field_to_csv_LongitudeDegrees(
                c.biddable_ad_group_criterion),
            csv_to_field=lambda c, v: csv_to_field_LongitudeDegrees(
                c.biddable_ad_group_criterion,
                float(v) if v else None)),
    ]

    @property
    def biddable_ad_group_criterion(self):
        """ Defines a Ad Group Criterion """

        return self._biddable_ad_group_criterion

    @biddable_ad_group_criterion.setter
    def biddable_ad_group_criterion(self, biddable_ad_group_criterion):
        self._biddable_ad_group_criterion = biddable_ad_group_criterion

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.biddable_ad_group_criterion,
                                         'biddable_ad_group_criterion')
        self.convert_to_values(row_values,
                               BulkAdGroupRadiusCriterion._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BiddableAdGroupCriterion')
        self._biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'
        self._biddable_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'RadiusCriterion')
        self._biddable_ad_group_criterion.Criterion.Type = 'RadiusCriterion'
        self._biddable_ad_group_criterion.CriterionBid = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'BidMultiplier')
        self._biddable_ad_group_criterion.CriterionBid.Type = 'BidMultiplier'
        row_values.convert_to_entity(self,
                                     BulkAdGroupRadiusCriterion._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupRadiusCriterion,
              self).read_additional_data(stream_reader)
class BulkAppInstallAd(_BulkAd):
    """ Represents an App Install Ad.

    This class exposes the :attr:`app_install_ad` property that can be read and written as fields of the App Install Ad record in a bulk file.

    For more information, see App Install Ad at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkAppInstallAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self.app_install_ad = ad

    @property
    def app_install_ad(self):
        """ The App Install Ad.

        see App Install Ad at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad

    @app_install_ad.setter
    def app_install_ad(self, app_install_ad):
        if app_install_ad is not None and not isinstance(app_install_ad, AppInstallAd):
            raise ValueError('Not an instance of AppInstallAd')
        self._ad = app_install_ad

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.AppPlatform,
            field_to_csv=lambda c: c.app_install_ad.AppPlatform,
            csv_to_field=lambda c, v: setattr(c.app_install_ad, 'AppPlatform', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.AppStoreId,
            field_to_csv=lambda c: c.app_install_ad.AppStoreId,
            csv_to_field=lambda c, v: setattr(c.app_install_ad, 'AppStoreId', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Title,
            field_to_csv=lambda c: c.app_install_ad.Title,
            csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Title', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Text,
            field_to_csv=lambda c: c.app_install_ad.Text,
            csv_to_field=lambda c, v: setattr(c.app_install_ad, 'Text', v)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.app_install_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('AppInstallAd')
        self.app_install_ad.Type = 'AppInstall'
        super(BulkAppInstallAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkAppInstallAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.app_install_ad, 'app_install_ad')
        super(BulkAppInstallAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkAppInstallAd._MAPPINGS)
Exemple #25
0
class BulkAdGroupProductPartition(_SingleRecordBulkEntity):
    """ Represents an Ad Group Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`ad_group_criterion` property that can be read and written as fields of the
    Ad Group Product Partition record in a bulk file.

    For more information, see Ad Group Product Scope at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_criterion=None,
                 campaign_name=None,
                 ad_group_name=None):
        super(BulkAdGroupProductPartition, self).__init__()

        self._ad_group_criterion = ad_group_criterion
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name
        self._performance_data = None

    @classmethod
    def _read_is_excluded(cls, entity, row_value):
        if row_value is None:
            row_value = ''
        row_value = row_value.lower()
        if row_value == 'yes' or row_value == 'true':
            is_excluded = True
        elif row_value == 'no' or row_value == 'false':
            is_excluded = False
        else:
            raise ValueError('IsExcluded can only be set to TRUE|FALSE in Ad Group Product Partition row')
        if is_excluded:
            product_partition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductPartition')
            product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductCondition')
            product_partition.Type = 'ProductPartition'

            negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('NegativeAdGroupCriterion')
            negative_ad_group_criterion.Criterion = product_partition
            negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion'

            entity.ad_group_criterion = negative_ad_group_criterion
        else:
            product_partition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductPartition')
            product_partition.Condition = _CAMPAIGN_OBJECT_FACTORY_V12.create('ProductCondition')
            product_partition.Type = 'ProductPartition'

            fixed_bid = _CAMPAIGN_OBJECT_FACTORY_V12.create('FixedBid')
            fixed_bid.Type = 'FixedBid'

            biddable_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create('BiddableAdGroupCriterion')
            biddable_ad_group_criterion.Criterion = product_partition
            biddable_ad_group_criterion.CriterionBid = fixed_bid
            biddable_ad_group_criterion.Type = 'BiddableAdGroupCriterion'

            entity.ad_group_criterion = biddable_ad_group_criterion

    @classmethod
    def _write_bid(cls, entity):
        criterion = entity.ad_group_criterion
        if isinstance(criterion, _BiddableAdGroupCriterion) and \
                criterion.CriterionBid is not None:
            return fixed_bid_bulk_str(entity.ad_group_criterion.CriterionBid)

    @classmethod
    def _read_bid(cls, entity, row_value):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            entity.ad_group_criterion.CriterionBid = parse_fixed_bid(row_value)
        else:
            pass

    @classmethod
    def _write_destination_url(cls, entity):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            return entity.ad_group_criterion.DestinationUrl
        else:
            return None

    @classmethod
    def _get_partition_type(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'PartitionType'):
            return entity.ad_group_criterion.Criterion.PartitionType
        return None

    @classmethod
    def _get_parent_criterion_id(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'ParentCriterionId'):
            return bulk_str(entity.ad_group_criterion.Criterion.ParentCriterionId)
        return None

    @classmethod
    def _get_condition_operand(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \
                entity.ad_group_criterion.Criterion.Condition is not None and \
                hasattr(entity.ad_group_criterion.Criterion.Condition, 'Operand'):
            return entity.ad_group_criterion.Criterion.Condition.Operand
        return None

    @classmethod
    def _get_condition_attribute(cls, entity):
        if entity.ad_group_criterion.Criterion is not None and \
                hasattr(entity.ad_group_criterion.Criterion, 'Condition') and \
                entity.ad_group_criterion.Criterion.Condition is not None and \
                hasattr(entity.ad_group_criterion.Criterion.Condition, 'Attribute'):
            return entity.ad_group_criterion.Criterion.Condition.Attribute
        return None

    @classmethod
    def _read_destination_url(cls, entity, row_value):
        if isinstance(entity.ad_group_criterion, _BiddableAdGroupCriterion):
            entity.ad_group_criterion.DestinationUrl = row_value
        else:
            pass

    _MAPPINGS = [
        _SimpleBulkMapping(
            _StringTable.IsExcluded,
            field_to_csv=lambda c: 'True' if isinstance(c.ad_group_criterion, _NegativeAdGroupCriterion) else 'False',
            csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_is_excluded(c, v)
        ),
        _SimpleBulkMapping(
            _StringTable.Status,
            field_to_csv=lambda c: c.ad_group_criterion.Status,
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Status', v)
        ),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'Id', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            _StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.ad_group_criterion.AdGroupId),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'AdGroupId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)
        ),
        _SimpleBulkMapping(
            _StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)
        ),
        _SimpleBulkMapping(
            _StringTable.SubType,
            field_to_csv=lambda c: BulkAdGroupProductPartition._get_partition_type(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion, 'PartitionType', v)
        ),
        _SimpleBulkMapping(
            _StringTable.ParentAdGroupCriterionId,
            field_to_csv=lambda c: BulkAdGroupProductPartition._get_parent_criterion_id(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion, 'ParentCriterionId',
                                              int(v) if v else None)
        ),
        _SimpleBulkMapping(
            _StringTable.ProductCondition1,
            field_to_csv=lambda c: BulkAdGroupProductPartition._get_condition_operand(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion.Condition, 'Operand', v)
        ),
        _SimpleBulkMapping(
            _StringTable.ProductValue1,
            field_to_csv=lambda c: BulkAdGroupProductPartition._get_condition_attribute(c),
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion.Criterion.Condition, 'Attribute', v)
        ),
        _SimpleBulkMapping(
            _StringTable.Bid,
            field_to_csv=lambda c: BulkAdGroupProductPartition._write_bid(c),
            csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_bid(c, v)
        ),
        _SimpleBulkMapping(
            _StringTable.DestinationUrl,
            field_to_csv=lambda c: BulkAdGroupProductPartition._write_destination_url(c),
            csv_to_field=lambda c, v: BulkAdGroupProductPartition._read_destination_url(c, v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.ad_group_criterion.FinalUrls)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: csv_to_field_Urls(c.ad_group_criterion.FinalUrls, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
        ),
        _SimpleBulkMapping(
            header=_StringTable.FinalMobileUrl,
            field_to_csv=lambda c: field_to_csv_Urls(c.ad_group_criterion.FinalMobileUrls)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: csv_to_field_Urls(c.ad_group_criterion.FinalMobileUrls, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
        ),
        _SimpleBulkMapping(
            header=_StringTable.TrackingTemplate,
            field_to_csv=lambda c: bulk_optional_str(c.ad_group_criterion.TrackingUrlTemplate)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'TrackingUrlTemplate', v if v else None)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
        ),
        _SimpleBulkMapping(
            header=_StringTable.CustomParameter,
            field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad_group_criterion)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None,
            csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad_group_criterion, v)
            if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
        ),
    ]

    @property
    def ad_group_criterion(self):
        """ Defines an Ad Group Criterion """

        return self._ad_group_criterion

    @ad_group_criterion.setter
    def ad_group_criterion(self, ad_group_criterion):
        self._ad_group_criterion = ad_group_criterion

    @property
    def campaign_name(self):
        """ Defines the name of the Campaign.

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ Defines the name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    @property
    def performance_data(self):
        return self._performance_data

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.ad_group_criterion, 'ad_group_criterion')
        self.convert_to_values(row_values, BulkAdGroupProductPartition._MAPPINGS)

        if not exclude_readonly_data:
            PerformanceData.write_to_row_values_if_not_null(self._performance_data, row_values)

    def process_mappings_from_row_values(self, row_values):
        row_values.convert_to_entity(self, BulkAdGroupProductPartition._MAPPINGS)

        self._performance_data = PerformanceData.read_from_row_values_or_null(row_values)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupProductPartition, self).read_additional_data(stream_reader)
class BulkExpandedTextAd(_BulkAd):
    """ Represents an Expanded Text Ad.

    This class exposes the :attr:`expanded_text_ad` property that can be read and written as fields of the Expanded Text Ad record in a bulk file.

    For more information, see Expanded Text Ad at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkExpandedTextAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self.expanded_text_ad = ad

    @property
    def expanded_text_ad(self):
        """ The Expanded Text Ad.

        see Expanded Text Ad at https://go.microsoft.com/fwlink/?linkid=846127.
        """

        return self._ad

    @expanded_text_ad.setter
    def expanded_text_ad(self, expanded_text_ad):
        if expanded_text_ad is not None and not isinstance(expanded_text_ad, ExpandedTextAd):
            raise ValueError('Not an instance of ExpandedTextAd')
        self._ad = expanded_text_ad

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Text,
            field_to_csv=lambda c: c.expanded_text_ad.Text,
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Text', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TextPart2,
            field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.TextPart2),
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TextPart2', v if v else '')
        ),
        _SimpleBulkMapping(
            header=_StringTable.TitlePart1,
            field_to_csv=lambda c: c.expanded_text_ad.TitlePart1,
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart1', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TitlePart2,
            field_to_csv=lambda c: c.expanded_text_ad.TitlePart2,
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart2', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.TitlePart3,
            field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.TitlePart3),
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'TitlePart3', v if v else '')
        ),
        _SimpleBulkMapping(
            header=_StringTable.Path1,
            field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Path1),
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Path1', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Path2,
            field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Path2),
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Path2', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Domain,
            field_to_csv=lambda c: bulk_optional_str(c.expanded_text_ad.Domain),
            csv_to_field=lambda c, v: setattr(c.expanded_text_ad, 'Domain', v)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.expanded_text_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ExpandedTextAd')
        self.expanded_text_ad.Type = 'ExpandedText'
        super(BulkExpandedTextAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkExpandedTextAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.expanded_text_ad, 'expanded_text_ad')
        super(BulkExpandedTextAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkExpandedTextAd._MAPPINGS)
Exemple #27
0
class BulkAccount(_SingleRecordBulkEntity):
    """ Represents an account that can be read or written in a bulk file.

    Properties of this class and of classes that it is derived from, correspond to fields of the Account record in a bulk file.
    For more information, see Account at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(self, account_id=None, customer_id=None, sync_time=None):
        super(BulkAccount, self).__init__()
        self._id = account_id
        self._customer_id = customer_id
        self._sync_time = sync_time

    @property
    def id(self):
        """ The identifier of the account.

        Corresponds to the 'Id' field in the bulk file.

        :return: The identifier of the account.
        :rtype: int
        """

        return self._id

    @property
    def customer_id(self):
        """ The identifier of the customer that contains the account.

        Corresponds to the 'Parent Id' field in the bulk file.

        :return: The identifier of the customer that contains the account.
        :rtype: int
        """

        return self._customer_id

    @property
    def sync_time(self):
        """ The date and time that you last synced your account using the bulk service.

        You should keep track of this value in UTC time.
        Corresponds to the 'Sync Time' field in the bulk file.

        :return: The date and time that you last synced your account using the bulk service.
        :rtype: datetime.datetime
        """

        return self._sync_time

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.id),
            csv_to_field=lambda c, v: setattr(c, '_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.ParentId,
            field_to_csv=lambda c: bulk_str(c.customer_id),
            csv_to_field=lambda c, v: setattr(c, '_customer_id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(
            header=_StringTable.SyncTime,
            field_to_csv=lambda c: bulk_datetime_str(c.sync_time),
            csv_to_field=lambda c, v: setattr(c, '_sync_time',
                                              parse_datetime(v)
                                              if v else None)),
    ]

    def process_mappings_from_row_values(self, row_values):
        row_values.convert_to_entity(self, BulkAccount._MAPPINGS)

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self.convert_to_values(row_values, BulkAccount._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAccount, self).read_additional_data(stream_reader)
class BulkDynamicSearchAd(_BulkAd):
    """ Represents a Dynamic Search Ad.

    This class exposes the :attr:`dynamic_search_ad` property that can be read and written as fields of the Dynamic Search Ad record in a bulk file.

    For more information, see Dynamic Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkDynamicSearchAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self.dynamic_search_ad = ad

    @property
    def dynamic_search_ad(self):
        """ The dynamic search ad.

        see Dynamic Search Ad at https://go.microsoft.com/fwlink/?linkid=836840.
        """

        return self._ad

    @dynamic_search_ad.setter
    def dynamic_search_ad(self, dynamic_search_ad):
        if dynamic_search_ad is not None and not isinstance(dynamic_search_ad, DynamicSearchAd):
            raise ValueError('Not an instance of DynamicSearchAd')
        self._ad = dynamic_search_ad

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.Text,
            field_to_csv=lambda c: c.dynamic_search_ad.Text,
            csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Text', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Path1,
            field_to_csv=lambda c: c.dynamic_search_ad.Path1,
            csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Path1', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Path2,
            field_to_csv=lambda c: c.dynamic_search_ad.Path2,
            csv_to_field=lambda c, v: setattr(c.dynamic_search_ad, 'Path2', v)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.dynamic_search_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('DynamicSearchAd')
        self.dynamic_search_ad.Type = 'DynamicSearch'
        super(BulkDynamicSearchAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkDynamicSearchAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.dynamic_search_ad, 'dynamic_search_ad')
        super(BulkDynamicSearchAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkDynamicSearchAd._MAPPINGS)
Exemple #29
0
class BulkAdGroupNegativeProfileCriterion(_SingleRecordBulkEntity):
    """ Represents an Ad Group Negative Profile Criterion that can be read or written in a bulk file.

    This class exposes the :attr:`negative_ad_group_criterion` property that can be read and written as fields of the
    Ad Group Negative Profile Criterion record in a bulk file.

    For more information, see Ad Group Negative Profile Criterion at https://go.microsoft.com/fwlink/?linkid=846127.

    *See also:*

    * :class:`.BulkServiceManProfiler`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """
    def __init__(
        self,
        negative_ad_group_criterion=None,
        campaign_name=None,
        ad_group_name=None,
    ):
        super(BulkAdGroupNegativeProfileCriterion, self).__init__()

        self._negative_ad_group_criterion = negative_ad_group_criterion
        self._campaign_name = campaign_name
        self._ad_group_name = ad_group_name

    _MAPPINGS = [
        _SimpleBulkMapping(_StringTable.Status,
                           field_to_csv=lambda c: bulk_str(
                               c.negative_ad_group_criterion.Status),
                           csv_to_field=lambda c, v: setattr(
                               c.negative_ad_group_criterion, 'Status', v
                               if v else None)),
        _SimpleBulkMapping(
            _StringTable.Id,
            field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.Id),
            csv_to_field=lambda c, v: setattr(c.negative_ad_group_criterion,
                                              'Id',
                                              int(v) if v else None)),
        _SimpleBulkMapping(_StringTable.ParentId,
                           field_to_csv=lambda c: bulk_str(
                               c.negative_ad_group_criterion.AdGroupId),
                           csv_to_field=lambda c, v: setattr(
                               c.negative_ad_group_criterion, 'AdGroupId',
                               int(v) if v else None)),
        _SimpleBulkMapping(
            _StringTable.Campaign,
            field_to_csv=lambda c: c.campaign_name,
            csv_to_field=lambda c, v: setattr(c, 'campaign_name', v)),
        _SimpleBulkMapping(
            _StringTable.AdGroup,
            field_to_csv=lambda c: c.ad_group_name,
            csv_to_field=lambda c, v: setattr(c, 'ad_group_name', v)),
        _SimpleBulkMapping(
            _StringTable.Profile,
            field_to_csv=lambda c: c.profile_name,
            csv_to_field=lambda c, v: setattr(c, 'profile_name', v)),
        _SimpleBulkMapping(
            _StringTable.ProfileId,
            field_to_csv=lambda c: bulk_str(c.negative_ad_group_criterion.
                                            Criterion.ProfileId),
            csv_to_field=lambda c, v: setattr(
                c.negative_ad_group_criterion.Criterion, 'ProfileId',
                int(v) if v else None)),
    ]

    @property
    def negative_ad_group_criterion(self):
        """ Defines a Ad Group Criterion """

        return self._negative_ad_group_criterion

    @negative_ad_group_criterion.setter
    def negative_ad_group_criterion(self, negative_ad_group_criterion):
        self._negative_ad_group_criterion = negative_ad_group_criterion

    @property
    def campaign_name(self):
        """ The name of the Campaign

        :rtype: str
        """

        return self._campaign_name

    @campaign_name.setter
    def campaign_name(self, campaign_name):
        self._campaign_name = campaign_name

    @property
    def ad_group_name(self):
        """ The name of the Ad Group

        :rtype: str
        """

        return self._ad_group_name

    @ad_group_name.setter
    def ad_group_name(self, ad_group_name):
        self._ad_group_name = ad_group_name

    def process_mappings_to_row_values(self, row_values,
                                       exclude_readonly_data):
        self._validate_property_not_null(self.negative_ad_group_criterion,
                                         'negative_ad_group_criterion')
        self.convert_to_values(row_values,
                               BulkAdGroupNegativeProfileCriterion._MAPPINGS)

    def process_mappings_from_row_values(self, row_values):
        self._negative_ad_group_criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'NegativeAdGroupCriterion')
        self._negative_ad_group_criterion.Type = 'NegativeAdGroupCriterion'
        self._negative_ad_group_criterion.Criterion = _CAMPAIGN_OBJECT_FACTORY_V12.create(
            'ProfileCriterion')
        self._negative_ad_group_criterion.Criterion.Type = 'ProfileCriterion'
        self._negative_ad_group_criterion.Criterion.ProfileType = self.profile_type(
        )
        row_values.convert_to_entity(
            self, BulkAdGroupNegativeProfileCriterion._MAPPINGS)

    def read_additional_data(self, stream_reader):
        super(BulkAdGroupNegativeProfileCriterion,
              self).read_additional_data(stream_reader)

    @abstractmethod
    def profile_type(self):
        pass
class BulkResponsiveAd(_BulkAd):
    """ Represents a Responsive Ad.

    This class exposes the :attr:`responsive_ad` property that can be read and written as fields of the Responsive Ad record in a bulk file.

    For more information, see Responsive Ad at https://go.microsoft.com/fwlink/?linkid=836840.

    *See also:*

    * :class:`.BulkServiceManager`
    * :class:`.BulkOperation`
    * :class:`.BulkFileReader`
    * :class:`.BulkFileWriter`
    """

    def __init__(self,
                 ad_group_id=None,
                 campaign_name=None,
                 ad_group_name=None,
                 ad=None):
        super(BulkResponsiveAd, self).__init__(
            ad_group_id,
            campaign_name,
            ad_group_name,
            ad,
        )
        self._ad = ad

    @property
    def responsive_ad(self):
        """ The responsive search ad.

        see Responsive Ad at https://go.microsoft.com/fwlink/?linkid=836840.
        """

        return self._ad

    @responsive_ad.setter
    def responsive_ad(self, responsive_ad):
        if responsive_ad is not None and not isinstance(responsive_ad, ResponsiveAd):
            raise ValueError('Not an instance of ResponsiveAd')
        self._ad = responsive_ad

    _MAPPINGS = [
        _SimpleBulkMapping(
            header=_StringTable.BusinessName,
            field_to_csv=lambda c: c.responsive_ad.BusinessName,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'BusinessName', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.CallToAction,
            field_to_csv=lambda c: c.responsive_ad.CallToAction,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'CallToAction', v if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Headline,
            field_to_csv=lambda c: c.responsive_ad.Headline,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'Headline', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.LongHeadline,
            field_to_csv=lambda c: c.responsive_ad.LongHeadline,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LongHeadline', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.LandscapeImageMediaId,
            field_to_csv=lambda c: c.responsive_ad.LandscapeImageMediaId,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LandscapeImageMediaId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.LandscapeLogoMediaId,
            field_to_csv=lambda c: c.responsive_ad.LandscapeLogoMediaId,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'LandscapeLogoMediaId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.SquareImageMediaId,
            field_to_csv=lambda c: c.responsive_ad.SquareImageMediaId,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'SquareImageMediaId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.SquareLogoMediaId,
            field_to_csv=lambda c: c.responsive_ad.SquareLogoMediaId,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'SquareLogoMediaId', int(v) if v else None)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Text,
            field_to_csv=lambda c: c.responsive_ad.Text,
            csv_to_field=lambda c, v: setattr(c.responsive_ad, 'Text', v)
        ),
        _SimpleBulkMapping(
            header=_StringTable.Images,
            field_to_csv=lambda c: field_to_csv_ImageAssetLinks(c.responsive_ad.Images),
            csv_to_field=lambda c, v: csv_to_field_ImageAssetLinks(c.responsive_ad.Images, v)
        ),
    ]

    def process_mappings_from_row_values(self, row_values):
        self.responsive_ad = _CAMPAIGN_OBJECT_FACTORY_V12.create('ResponsiveAd')
        self.responsive_ad.Type = 'Responsive'
        super(BulkResponsiveAd, self).process_mappings_from_row_values(row_values)
        row_values.convert_to_entity(self, BulkResponsiveAd._MAPPINGS)

    def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
        self._validate_property_not_null(self.responsive_ad, 'responsive_ad')
        super(BulkResponsiveAd, self).process_mappings_to_row_values(row_values, exclude_readonly_data)
        self.convert_to_values(row_values, BulkResponsiveAd._MAPPINGS)