Ejemplo n.º 1
0
class StatReport:  # 대용량 보고서
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    StatReportObjectList = List[StatReportObject]

    def get_stat_report_list(self) -> StatReportObjectList:
        result = self.conn.get('/stat-reports')
        stat_list = []
        for arr in result:
            stat = StatReportObject(arr)
            stat_list.append(stat)
        return stat_list

    def get_stat_report(self, reportJobId: str) -> StatReportObject:
        result = self.conn.get('/stat-reports/' + reportJobId)
        result = StatReportObject(result)
        return result

    def create_stat_report(
            self, CreateStatReportObject: CreateStatReportObject
    ) -> StatReportObject:
        data = jsonpickle.encode(CreateStatReportObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)

        result = self.conn.post('/stat-reports', data_str)
        result = StatReportObject(result)
        return result

    def delete_stat_reports(self, reportJobId: str):
        self.conn.delete('/stat-reports/' + reportJobId)
        return True
Ejemplo n.º 2
0
class StatReport:  #대용량 다운로드 보고서
    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    StatReportObjectList = List[StatReportObject]

    def list(self) -> StatReportObjectList:
        result = self.conn.get('/stat-reports')
        return result

    def get(self, reportJobId: str) -> StatReportObject:
        result = self.conn.get('/stat-reports/' + reportJobId)
        return result

    def create(self, reportTp, statDt) -> StatReportObject:
        data = jsonpickle.encode(CreateStatReportObject(reportTp, statDt), unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/stat-reports', data_str)

        return result

    def delete_all(self):
        self.conn.delete('/stat-reports/')
        return True

    def delete_by_id(self, reportJobId: str):
        self.conn.delete('/stat-reports/' + reportJobId)
        return True
Ejemplo n.º 3
0
class IpExclusion:
    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    ExclusionIdList = List[str]

    def get(self):
        result = self.conn.get('/tool/ip-exclusions')
        return result

    def create(self, filterIp, memo) -> IpExclusionObject:
        data = jsonpickle.encode(CreateIpExclusionObject(filterIp, memo), unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/tool/ip-exclusions', data_str)
        return result

    def update(self, filterIp, ipFilterId, memo) -> IpExclusionObject:
        data = jsonpickle.encode(UpdateIpExclusionObject(filterIp, ipFilterId, memo), unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.put('/tool/ip-exclusions', data_str)
        return result

    def delete(self, id: str):
        result = self.conn.delete('/tool/ip-exclusions/' + id)
        result = IpExclusionObject(result)
        return result

    def delete_by_ids(self, id_array: ExclusionIdList):
        query = {'ids':id_array}
        self.conn.delete('/tool/ip-exclusions', query)
        return True
Ejemplo n.º 4
0
class MasterReport:  #광고 정보 일괄 다운로드
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    MasterReportObjectList = List[MasterReportObject]

    def list(self) -> MasterReportObjectList:
        result = self.conn.get('/master-reports')
        return result

    def get_by_id(self, id: str) -> MasterReportObject:
        result = self.conn.get('/master-reports/' + id)
        return result

    def create(self, item: str, fromTime: str) -> MasterReportObject:
        data = jsonpickle.encode(CreateMasterReportObject(item, fromTime),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/master-reports', data_str)
        return result

    def delete_all(self):
        self.conn.delete('/master-reports')
        return True

    def delete_by_id(self, id: str):
        self.conn.delete('/master-reports/' + id)
        return True
Ejemplo n.º 5
0
class AdKeyword:
    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    AdKeywordList = List[AdKeywordObject]
    AdKeywordIdList = List[str]

    def list_by_label_id(self, nccLabelId: str) -> AdKeywordList:
        query = {'nccLabelId': nccLabelId}
        result = self.conn.get('/ncc/keywords', query)
        return result

    def list_by_ids(self, ids: AdKeywordIdList) -> AdKeywordList:
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.conn.get('/ncc/keywords', query)
        return result

    def list_by_group_id(self, nccAdgroupId: str = None, baseSearchId: str = None,
                                       recordSize: int = None, selector: str = None) -> AdKeywordList:

        query = {'nccAdgroupId': nccAdgroupId, 'baseSearchId': baseSearchId, 'recordSize': recordSize,
                 'selector': selector}
        result = self.conn.get('/ncc/keywords', query)
        return result

    def get(self, nccKeywordId) -> AdKeywordObject:
        result = self.conn.get('/ncc/keywords/' + nccKeywordId)
        return result

    def create(self, nccAdgroupId, CreateAdKeywordObject) -> AdKeywordObject:
        data = jsonpickle.encode(CreateAdKeywordObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data = [data]
        data_str = json.dumps(data)
        result = self.conn.post('/ncc/keywords', data_str, {'nccAdgroupId': nccAdgroupId})
        return result

    def update(self, nccKeywordId, fields, UpdateAdKeywordObject) -> AdKeywordObject:
        data = jsonpickle.encode(UpdateAdKeywordObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)

        query = {'fields': fields}

        result = self.conn.put('/ncc/keywords/' + nccKeywordId, data_str, query)
        return result

    def delete(self, nccKeywordId: str):
        self.conn.delete('/ncc/keywords/' + nccKeywordId)
        return True

    def delete_items(self, ids: AdKeywordIdList):
        ids = ",".join(ids)
        query = {'ids': ids}
        self.conn.delete('/ncc/keywords', query)
Ejemplo n.º 6
0
class Campaign:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    CampaignList = List[CampaignObject]
    CampaignIdList = List[str]
    ChangeFieldsList = List[str]

    def get(self, campaignId: str) -> CampaignObject:
        result = self.conn.get('/ncc/campaigns/' + campaignId)
        return result

    def list_by_ids(self, ids: CampaignIdList) -> CampaignList:
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.conn.get('/ncc/campaigns', query)
        return result

    def list_by_customer_id_or_campaign_type(
            self,
            campaignType: str = None,
            baseSearchId: str = None,
            recordSize: int = None,
            selector: str = None) -> CampaignList:
        query = {
            'campaignType': campaignType,
            'baseSearchId': baseSearchId,
            'recordSize': recordSize,
            'selector': selector
        }
        result = self.conn.get('/ncc/campaigns', query)
        return result

    def create(self, campaign_add_object: CampaignAddObject):

        data = jsonpickle.encode(campaign_add_object, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/ncc/campaigns', data_str)
        camp = CampaignObject(result)
        return camp

    def update(self, campaign_update_object: CampaignUpdateObject,
               campaignId: str, fields: ChangeFieldsList) -> CampaignObject:
        fields = ",".join(fields)
        fields = {'fields': fields}
        data = jsonpickle.encode(campaign_update_object, unpicklable=False)
        result = self.conn.put('/ncc/campaigns/' + str(campaignId), data,
                               fields)  # userLock, budget, period
        camp = CampaignObject(result)
        return camp
Ejemplo n.º 7
0
class BusinessChannel:
    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    BusinessChannelObjectList = List[BusinessChannelObject]
    BusinessChannelIdList = List[str]

    def get(self, businessChannelId: str):
        result = self.conn.get('/ncc/channels/' + businessChannelId)
        return result

    def list(self):
        result = self.conn.get('/ncc/channels')
        return result

    def list_by_channel_type(self, channelTp: str):
        result = self.conn.get('/ncc/channels', {'channelTp': channelTp})
        return result

    def list_by_ids(self, ids: BusinessChannelIdList):
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.conn.get('/ncc/channels', query)
        return result

    def create(self, CreateBusinessChannelObject: CreateBusinessChannelObject) -> BusinessChannelObject:
        data = jsonpickle.encode(CreateBusinessChannelObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/ncc/channels', data_str)
        return result

    def update(self, fields, UpdateBusinessChannelObject: UpdateBusinessChannelObject) -> BusinessChannelObject:
        data = jsonpickle.encode(UpdateBusinessChannelObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.put('/ncc/channels', data_str, fields)
        return result

    def delete(self, businessChannelId: str):
        self.conn.delete('/ncc/channels/' + businessChannelId)
        return True

    def delete_by_ids(self, ids: BusinessChannelIdList):
        ids = ",".join(ids)
        query = {'ids': ids}
        self.conn.delete('/ncc/channels', query)
        return True
Ejemplo n.º 8
0
class AdExtension:  # 확장소재
    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)
    AdExtensionObjectList = List[AdExtensionObject]
    IdList = List[str]
    ChangeFieldsList = List[str]

    def list_by_owner_id(self, ownerId: str) -> AdExtensionObjectList:
        result = self.conn.get('/ncc/ad-extensions', {'ownerId': ownerId})
        return result

    def list_by_ids(self, ids: IdList) -> AdExtensionObjectList:
        ids = ",".join(ids)
        ids = {'ids': ids}
        result = self.conn.get('/ncc/ad-extensions', ids)
        return result

    def get(self, adExtensionId: str) -> AdExtensionObject:
        result = self.conn.get('/ncc/ad-extensions/' + adExtensionId)
        return result

    def create(self, CreateAdExtensionObject: CreateAdExtensionObject) -> AdExtensionObject:
        data = jsonpickle.encode(CreateAdExtensionObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.conn.post('/ncc/ad-extensions', data_str)
        return result

    def update(self, adExtensionId: str, fields: ChangeFieldsList,
                             UpdateAdExtensionObject: UpdateAdExtensionObject) -> AdExtensionObject:
        data = jsonpickle.encode(UpdateAdExtensionObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        change_fields_list = ",".join(fields)
        query = {'fields': change_fields_list}
        result = self.conn.put('/ncc/ad-extensions/' + adExtensionId, data_str, query)
        return result

    def delete(self, adExtensionId: str):
        self.conn.delete('/ncc/ad-extensions/' + adExtensionId)
        return True
Ejemplo n.º 9
0
class MasterReport:  # 광고정보일괄다운로드탭
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    MasterReportObjectList = List[MasterReportObject]

    def get_master_report_list(self) -> MasterReportObjectList:
        result = self.conn.get('/master-reports')
        mreport_list = []
        for arr in result:
            mreport = MasterReportObject(arr)
            mreport_list.append(mreport)
        return mreport_list

    def get_master_report_by_id(self, id: str) -> MasterReportObject:
        result = self.conn.get('/master-reports/' + id)
        result = MasterReportObject(result)
        return result

    def create_master_report(
        self, CreateMasterReportObject: CreateMasterReportObject
    ) -> MasterReportObject:
        data = jsonpickle.encode(CreateMasterReportObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/master-reports', data_str)
        result = MasterReportObject(result)
        return result

    def delete_master_report_all(self):
        self.conn.delete('/master-reports')
        return True

    def delete_master_report_by_id(self, id: str):
        self.conn.delete('/master-reports', {'id': id})
        return True
Ejemplo n.º 10
0
class Ad:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    AdIdList = List[str]
    AdObjectList = List[AdObject]
    ChangeFieldsList = List[str]

    def get(self, adId: str) -> AdObject:
        result = self.conn.get('/ncc/ads/' + adId)
        return result

    def list_by_adgroup_id(self, nccAdGroupId: str) -> AdObjectList:
        result = self.conn.get('/ncc/ads', {'nccAdgroupId': nccAdGroupId})
        return result

    def list(self, ids: AdIdList) -> AdObjectList:
        ids = ",".join(ids)
        ids = {'ids': ids}
        result = self.conn.get('/ncc/ads', ids)
        return result

    def create(self, adObject, nccAdgroupId, type, inspectRequestMsg,
               userLock) -> AdObject:
        data = jsonpickle.encode(CreateAdObject(adObject, nccAdgroupId, type,
                                                inspectRequestMsg, userLock),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.conn.post('/ncc/ads', data_str)
        return result

    def update(self, adId: str, fields: ChangeFieldsList, adAttr,
               inspectRequestMsg, nccAdId, userLock) -> AdObject:
        change_fields_list = ",".join(fields)
        query = {'fields': change_fields_list}
        data = jsonpickle.encode(UpdateAdObject(
            adAttr=adAttr,
            inspectRequestMsg=inspectRequestMsg,
            nccAdId=nccAdId,
            userLock=userLock),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.conn.put('/ncc/ads/' + adId, data_str, query)
        return result

    def delete(self, adId: str):
        self.conn.delete('/ncc/ads/' + adId)
        return True

    def copy(self, adId: str, targetAdGroupId: str,
             userLock: bool) -> AdObject:
        query = {
            'ids': adId,
            'targetAdgroupId': targetAdGroupId,
            'userLock': userLock
        }
        result = self.conn.put('/ncc/ads', None, query)
        return result
Ejemplo n.º 11
0
class Estimate:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    EstimateAvgObjectList = List[EstimateAvgObject]
    EstimateMedianObjectList = List[EstimateMedianObject]
    EstimateExposureMiniObjectList = List[EstimateExposureMiniObject]
    EstimatePerformanceObjectList = List[EstimatePerformanceObject]
    GetPerformanceObjectList = List[GetPerformanceObject]
    GetPerformanceBulkObjectList = List[GetPerformanceBulkObject]

    def get_average_position_bid(self, type, device, key_and_position_list):
        temp = []
        for key_and_position in key_and_position_list:
            temp.append(
                KeyAndPositionObject(key_and_position[0], key_and_position[1]))
        data = jsonpickle.encode(GetAvgPositionBidObject(device, temp),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/average-position-bid/' + type,
                                data_str)
        result = result['estimate']
        return result

    def get_exposure_minimum_bid(self, type: str, device, period, keys):
        data = jsonpickle.encode(GetExposureMiniBidObject(
            device, period, keys),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/exposure-minimum-bid/' + type,
                                data_str)
        result = result['estimate']
        return result

    def get_median_bid(self, type: str, device, period, keys):
        data = jsonpickle.encode(GetMedianBidObject(device, period, keys),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/median-bid/' + type, data_str)
        result = result['estimate']
        return result

    def get_performance(self, type: str, device, keywordplus, key, bids):
        data = jsonpickle.encode(GetPerformanceObject(device, keywordplus, key,
                                                      bids),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        query = {'items': data_str}
        result = self.conn.post('/estimate/performance/' + type,
                                data_str,
                                query=query)
        result = result['estimate']
        return result

    # def get_performance_many_json(self, type: str, GetPerformanceObjectList: GetPerformanceObjectList):
    #     data = jsonpickle.encode(GetPerformanceObjectList, unpicklable=False)
    #     data = json.loads(data)
    #     #data = CommonFunctions.dropna(data)
    #     data_str = json.dumps(data)
    #     print('data_str: ',data_str)
    #     result = self.conn.post('/estimate/performance/' + type, data_str)
    #     print('result: ',result)
    #     result = result['estimate']
    #     return result

    def get_performance_bulk(
            self, type: str,
            GetPerformanceBulkObjectList: GetPerformanceBulkObjectList):
        data = jsonpickle.encode(GetPerformanceBulkObjectList,
                                 unpicklable=False)
        data = json.loads(data)
        #data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        print(data_str)
        result = self.conn.post('/estimate/performance-bulk', data_str)
        result = result['estimate']
        return result
Ejemplo n.º 12
0
class Estimate:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    EstimateAvgObjectList = List[EstimateAvgObject]
    EstimateMedianObjectList = List[EstimateMedianObject]
    EstimateExposureMiniObjectList = List[EstimateExposureMiniObject]
    EstimatePerformanceObjectList = List[EstimatePerformanceObject]
    GetPerformanceObjectList = List[GetPerformanceObject]

    def get_avg_position_bid_json(self, type, device, key_and_position_list):
        temp = []
        for key_and_position in key_and_position_list:
            temp.append(
                KeyAndPositionObject(key_and_position[0], key_and_position[1]))
        data = jsonpickle.encode(GetAvgPositionBidObject(device, temp),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/average-position-bid/' + type,
                                data_str)
        result = result['estimate']
        return result

    def get_avg_position_bid_list(
            self, type, device,
            key_and_position_list) -> EstimateAvgObjectList:
        result_json = self.get_avg_position_bid_json(type, device,
                                                     key_and_position_list)
        estimate_list = []
        for arr in result_json:
            estimate = EstimateAvgObject(arr)
            estimate_list.append(estimate)
        return estimate_list

    def get_exposure_mini_bid_json(self, type: str, device, period, keys):
        data = jsonpickle.encode(GetExposureMiniBidObject(
            device, period, keys),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/exposure-minimum-bid/' + type,
                                data_str)
        result = result['estimate']
        return result

    def get_exposure_mini_bid_list(self, type: str, device, period,
                                   keys) -> EstimateExposureMiniObjectList:
        result_json = self.get_exposure_mini_bid_json(type, device, period,
                                                      keys)
        estimate_list = []
        for arr in result_json:
            estimate = EstimateExposureMiniObject(arr)
            estimate_list.append(estimate)
        return estimate_list

    def get_median_bid_json(self, type: str, device, period, keys):
        data = jsonpickle.encode(GetMedianBidObject(device, period, keys),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/median-bid/' + type, data_str)
        result = result['estimate']
        return result

    def get_median_bid_list(self, type: str, device, period,
                            keys) -> EstimateMedianObjectList:
        result_json = self.get_median_bid_json(type, device, period, keys)
        estimate_list = []
        for arr in result_json:
            estimate = EstimateMedianObject(arr)
            estimate_list.append(estimate)
        return estimate_list

    def get_performance_json(self, type: str, device, keywordplus, key, bids):
        data = jsonpickle.encode(GetPerformanceObject(device, keywordplus, key,
                                                      bids),
                                 unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/performance/' + type, data_str)
        result = result['estimate']
        return result

    def get_performance_list(self, type: str, device, keywordplus, key,
                             bids) -> EstimatePerformanceObjectList:
        result_json = self.get_performance_json(type, device, keywordplus, key,
                                                bids)
        estimate_list = []
        for arr in result_json:
            estimate = EstimatePerformanceObject(arr)
            estimate_list.append(estimate)
        return estimate_list

    def get_performance_many_json(
            self, type: str,
            GetPerformanceObjectList: GetPerformanceObjectList):
        data = jsonpickle.encode(GetPerformanceObjectList, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/estimate/performance/' + type, data_str)
        result = result['estimate']
        return result

    def get_performance_many_list(
            self, type: str,
            GetPerformanceObjectList: GetPerformanceObjectList):
        result_json = self.get_performance_many_json(type,
                                                     GetPerformanceObjectList)
        estimate_list = []
        for arr in result_json:
            estimate = EstimatePerformanceObject(arr)
            estimate_list.append(estimate)
        return estimate_list
Ejemplo n.º 13
0
class Ad:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    AdIdList = List[str]
    AdObjectList = List[AdObject]
    ChangeFieldsList = List[str]

    def get_ad_list_by_ids(self, ids: AdIdList) -> AdObjectList:
        ids = ",".join(ids)
        ids = {'ids': ids}
        result = self.conn.get('/ncc/ads', ids)
        ad_obj_list = []
        for arr in result:
            ad_obj = AdObject(arr)
            ad_obj_list.append(ad_obj)

        return ad_obj_list

    def get_ad_list(self, nccAdGroupId: str) -> AdObjectList:
        result = self.conn.get('/ncc/ads', {'nccAdgroupId': nccAdGroupId})
        adobj_list = []
        for arr in result:
            ad_obj = AdObject(arr)
            adobj_list.append(ad_obj)

        return adobj_list

    def get_ad(self, adId: str) -> AdObject:
        result = self.conn.get('/ncc/ads/' + adId)
        result = AdObject(result)
        return result

    def create_ad(self, CreateAdObject: CreateAdObject) -> AdObject:
        data = jsonpickle.encode(CreateAdObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.conn.post('/ncc/ads', data_str)
        result = AdObject(result)
        return result

    def update_ad(self, adId: str, fields: ChangeFieldsList,
                  UpdateAdObject: UpdateAdObject) -> AdObject:
        change_fields_list = ",".join(fields)
        query = {'fields': change_fields_list}
        data = jsonpickle.encode(UpdateAdObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.conn.put('/ncc/ads/' + adId, data_str, query)
        result = AdObject(result)
        return result

    def delete_ad(self, adId: str):
        self.conn.delete('/ncc/ads/' + adId)
        return True

    def copy_ad(self, adId: str, targetAdGroupId: str,
                userLock: bool) -> AdObject:
        query = {
            'ids': adId,
            'targetAdgroupId': targetAdGroupId,
            'userLock': userLock
        }
        result = self.conn.put('/ncc/ads', None, query)
        result = AdObject(result)
        return result
Ejemplo n.º 14
0
class Adgroup:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.conn = Connector(base_url, api_key, secret_key, customer_id)

    RestrictedKeywordsAddObject = List[RestrictedKeywordsObject]
    RestrictedKeywordList = List[RestrictedKeyword]
    AdgroupList = List[AdgroupObject]
    AdgroupIdList = List[str]
    RestrictedKeywordIdList = List[str]
    ChangeFieldsList = List[str]

    def get(self, adgroupId: str) -> AdgroupObject:
        result = self.conn.get('/ncc/adgroups/' + adgroupId)
        return result

    def list_by_ids(self, ids: AdgroupIdList) -> AdgroupList:
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.conn.get('/ncc/adgroups', query)
        return result

    def list_keyword_plus_restricted_keywords(
            self, adgroupId: str) -> RestrictedKeywordList:
        query = {'type': 'KEYWORD_PLUS_RESTRICT'}
        result = self.conn.get(
            '/ncc/adgroups/' + adgroupId + "/restricted-keywords", query)
        return result

    def list_by_campaign_id(self,
                            nccCampaignId: str = None,
                            baseSearchId: str = None,
                            recordSize: int = None,
                            selector: str = None) -> AdgroupList:
        query = {
            'nccCampaignId': nccCampaignId,
            'baseSearchId': baseSearchId,
            'record_size': recordSize,
            'selector': selector
        }
        result = self.conn.get('/ncc/adgroups', query)
        return result

    def create_keyword_plus_restricted_keywords(
        self, adgroupId: str,
        restricted_keywords_object: RestrictedKeywordsAddObject
    ) -> RestrictedKeyword:
        data = jsonpickle.encode(restricted_keywords_object, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = [data]
        data_str = json.dumps(data_str)
        result = self.conn.post(
            '/ncc/adgroups/%s/restricted-keywords' % str(adgroupId), data_str)
        return result

    def create(self, create_adgroup_object: CreateAdgroupObject):
        data = jsonpickle.encode(create_adgroup_object, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.post('/ncc/adgroups', data_str)
        return result

    def update(self, adgroupId: str, fields: ChangeFieldsList,
               UpdateAdgroupObject: UpdateAdgroupObject):
        change_fields_list = ",".join(fields)
        query = {'fields': change_fields_list}
        data = jsonpickle.encode(UpdateAdgroupObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.put('/ncc/adgroups/' + adgroupId, data_str, query)
        return result

    def update_by_fields(self, adgroupId: str,
                         UpdateEntireAdgroupObject: UpdateEntireAdgroupObject):
        data = jsonpickle.encode(UpdateEntireAdgroupObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.dropna(data)
        data_str = json.dumps(data)
        result = self.conn.put('/ncc/adgroups/' + adgroupId, data_str)
        return result

    def delete_keyword_plus_restricted_keywords(
            self, adgroupId: str, res_keyword_ids: RestrictedKeywordIdList):
        res_keyword_ids = ",".join(res_keyword_ids)
        query = {'ids': res_keyword_ids}
        result = self.conn.delete(
            '/ncc/adgroups/%s/restricted-keywords' % str(adgroupId), query)
        return True

    def delete(self, adgroupId: str):
        result = self.conn.delete('/ncc/adgroups/' + adgroupId)
        return True