예제 #1
0
class IpExclusion:

    def __init__(self, base_url: str, api_key: str, secret_key: str, customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_ip_exclusion(self):
        result = self.r.get('/tool/ip-exclusions')

        ip_exclusion_list = []
        for arr in result:
            ipex = IpExclusionObject(arr)
            ip_exclusion_list.append(ipex)

        return ip_exclusion_list

    def create_ip_exclusion(self, CreateIpExclusionObject: CreateIpExclusionObject) -> IpExclusionObject:
        data = jsonpickle.encode(CreateIpExclusionObject, unpicklable=False)
        data = json.loads(data)       
        data = CommonFunctions.delete_null_dict_items(data)
        data_str = json.dumps(data)

        result = self.r.post('/tool/ip-exclusions', data_str)
        result = IpExclusionObject(result)

        return result

    def update_ip_exclusion(self, UpdateIpExclusionObject: UpdateIpExclusionObject) -> UpdateIpExclusionObject:
        data = jsonpickle.encode(UpdateIpExclusionObject, unpicklable=False)
        data = json.loads(data)       
        data = CommonFunctions.delete_null_dict_items(data)
        data_str = json.dumps(data)

        result = self.r.put('/tool/ip-exclusions', data_str)
        result = IpExclusionObject(result)

        return result

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

        return result

    def delete_ip_exclusion_many(self, id_array: ExclusionIdList):
        query = {'ids' : id_array}
        self.r.delete('/tool/ip-exclusions', query)

        return True
예제 #2
0
class MasterReport:  #광고정보일괄다운로드탭
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_master_report_list(self) -> MasterReportObjectList:
        result = self.r.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.r.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.delete_null_dict_items(data)
        data_str = json.dumps(data)

        result = self.r.post('/master-reports', data_str)
        result = MasterReportObject(result)

        return result

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

    def delete_master_report_by_id(self, id: str):
        self.r.delete('/master-reports', {'id': id})
        return True
예제 #3
0
class StatReport:  #대용량 보고서
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_stat_report_list(self) -> StatReportObjectList:
        result = self.r.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.r.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.delete_null_dict_items(data)
        data_str = json.dumps(data)

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

        return result

    def delete_stat_reports(self, reportJobId: str):
        self.r.delete('/stat-reports/' + reportJobId)
        return True
예제 #4
0
class AdExtension:  #확장소재
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_ad_extensions_list(self, ownerId: str) -> AdExtensionObjectList:
        result = self.r.get('/ncc/ad-extensions', {'ownerId': ownerId})
        adext_list = []
        for arr in result:
            camp = AdExtensionObject(arr)
            adext_list.append(camp)
        return adext_list

    def get_ad_extensions_list_by_ids(self,
                                      ids: IdList) -> AdExtensionObjectList:
        ids = ",".join(ids)
        ids = {'ids': ids}
        result = self.r.get('/ncc/ad-extensions', ids)
        adext_list = []
        for arr in result:
            camp = AdExtensionObject(arr)
            adext_list.append(camp)
        return adext_list

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

        return result

    def create_ad_extensions(
            self, CreateAdExtensionObject: CreateAdExtensionObject
    ) -> AdExtensionObject:

        data = jsonpickle.encode(CreateAdExtensionObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.delete_null_dict_items(data)
        data_str = data
        data_str = json.dumps(data_str)

        result = self.r.post('/ncc/ad-extensions', data_str)
        result = AdExtensionObject(result)
        return result

    def update_ad_extensions(
            self, adExtensionId: str, fields: ChangeFieldsList,
            UpdateAdExtensionObject: UpdateAdExtensionObject
    ) -> AdExtensionObject:

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

    def delete_ad_extensions(self, adExtensionId: str):
        self.r.delete('/ncc/ad-extensions/' + adExtensionId)
        return True
예제 #5
0
class BusinessChannel:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_business_channel_list(self) -> BusinessChannelObjectList:
        result = self.r.get('/ncc/channels')

        business_channel_list = []
        for arr in result:
            channel = BusinessChannelObject(arr)
            business_channel_list.append(channel)

        return business_channel_list

    def get_business_channel_list_by_type(
            self, tp: str) -> BusinessChannelObjectList:
        result = self.r.get('/ncc/channels', {'channelTp': tp})

        business_channel_list = []
        for arr in result:
            channel = BusinessChannelObject(arr)
            business_channel_list.append(channel)

        return business_channel_list

    def get_business_channel_list_by_ids(
            self, ids: BusinessChannelIdList) -> BusinessChannelObjectList:
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.r.get('/ncc/channels', query)

        business_channel_list = []
        for arr in result:
            channel = BusinessChannelObject(arr)
            business_channel_list.append(channel)
        return business_channel_list

    def get_business_channel(self, businessChannelId) -> BusinessChannelObject:
        result = self.r.get('/ncc/channels/' + businessChannelId)
        result = BusinessChannelObject(result)

        return result

    def create_business_channel(
        self, CreateBusinessChannelObj: CreateBusinessChannelObject
    ) -> BusinessChannelObject:

        data = jsonpickle.encode(CreateBusinessChannelObj, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.delete_null_dict_items(data)
        data_str = json.dumps(data)
        result = self.r.post('/ncc/channels', data_str)
        result = BusinessChannelObject(result)
        return result

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

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

    def delete_business_channel_by_ids(self, ids: BusinessChannelIdList):
        ids = ",".join(ids)
        query = {'ids': ids}
        self.r.delete('/ncc/channels', query)
        return True
예제 #6
0
class AdKeyword:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

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

        adkeyword_list = []
        for arr in result:
            keyword = AdKeywordObject(arr)
            adkeyword_list.append(keyword)

        return adkeyword_list

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

        adkeyword_list = []
        for arr in result:
            keyword = AdKeywordObject(arr)
            adkeyword_list.append(keyword)

        return adkeyword_list

    def get_adkeyword_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.r.get('/ncc/keywords', query)

        adkeyword_list = []
        for arr in result:
            keyword = AdKeywordObject(arr)
            adkeyword_list.append(keyword)

        return adkeyword_list

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

    def create_adkeyword(self, nccAdgroupId,
                         CreateAdKeywordObject) -> AdKeywordObject:
        data = jsonpickle.encode(CreateAdKeywordObject, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.delete_null_dict_items(data)
        data = [data]
        data_str = json.dumps(data)

        result = self.r.post('/ncc/keywords', data_str,
                             {'nccAdgroupId': nccAdgroupId})
        result = AdKeywordObject(result)
        return result

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

        query = {'fields': fields}

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

        return result

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

    def delete_adkeyword_many(self, ids: AdKeywordIdList):
        ids = ",".join(ids)
        query = {'ids': ids}
        self.r.delete('/ncc/keywords', query)

    def managed_keyword_list(self,
                             keywords: KeywordsList) -> ManagedKeywordObject:
        keywords = ",".join(keywords)
        query = {'keywords': keywords}
        result = self.r.get('/ncc/managedKeyword', query)

        managedkeyword_list = []
        for arr in result:
            managedkeyword = ManagedKeywordObject(arr)
            managedkeyword_list.append(managedkeyword)

        return managedkeyword_list
예제 #7
0
class Ad:  #광고 소재에 관한 API입니다.
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_ad_list_by_ids(self, ids: AdIdList) -> AdObjectList:
        ids = ",".join(ids)
        ids = {'ids': ids}
        result = self.r.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.r.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.r.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.delete_null_dict_items(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.r.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.delete_null_dict_items(data)
        data_str = data
        data_str = json.dumps(data_str)
        result = self.r.put('/ncc/ads/' + adId, data_str, query)
        result = AdObject(result)
        return result

    def delete_ad(self, adId: str):
        self.r.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.r.put('/ncc/ads', None, query)
        result = AdObject(result)
        return result
예제 #8
0
class AdGroup:
    def __init__(self, base_url: str, api_key: str, secret_key: str,
                 customer_id: int):
        self.r = RestApi(base_url, api_key, secret_key, customer_id)

    def get_restricted_keyword(self, adgroupId: str) -> RestrictedKeywordList:
        query = {'type': 'KEYWORD_PLUS_RESTRICT'}
        result = self.r.get(
            '/ncc/adgroups/' + adgroupId + "/restricted-keywords", query)
        restricted_list = []
        for arr in result:
            restricted_keyword = RestrictedKeyword(arr)
            restricted_list.append(restricted_keyword)

        return restricted_list

    def get_adgroup_list(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.r.get('/ncc/adgroups', query)

        adgroup_list = []
        for arr in result:
            camp = AdgroupObject(arr)
            adgroup_list.append(camp)

        return adgroup_list

    def get_adgroup_list_by_ids(self, ids: AdGroupIdList) -> AdGroupList:
        ids = ",".join(ids)
        query = {'ids': ids}
        result = self.r.get('/ncc/adgroups', query)
        adgroup_list = []
        for arr in result:
            camp = AdgroupObject(arr)
            adgroup_list.append(camp)

        return adgroup_list

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

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

        return restrict_keyword

    def create_adgroup(self, create_adgroup_object: CreateAdgroupObject):
        data = jsonpickle.encode(create_adgroup_object, unpicklable=False)
        data = json.loads(data)
        data = CommonFunctions.delete_null_dict_items(data)
        data_str = json.dumps(data)
        result = self.r.post('/ncc/adgroups', data_str)
        result = AdgroupObject(result)
        return result

    def update_adgroup(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.delete_null_dict_items(data)
        data_str = json.dumps(data)
        result = self.r.put('/ncc/adgroups/' + adgroupId, data_str, query)
        result = AdgroupObject(result)
        return result

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

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

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