class Label: #즐겨찾기 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) LabelRefObjectList = List[LabelRefObject] LabelObjectList = List[LabelObject] def get_label_list(self) -> LabelObjectList: result = self.conn.get('/ncc/labels') label_list = [] for arr in result: label = LabelObject(arr) label_list.append(label) return label_list def update_label(self, UpdateLabelObject: UpdateLabelObject) -> LabelObject: data = jsonpickle.encode(UpdateLabelObject, unpicklable=False) data = json.loads(data) data = CommonFunctions.dropna(data) data_str = json.dumps(data) result = self.conn.put('/ncc/labels', data_str) result = LabelObject(result) return result def update_label_ref( self, UpdateLabelRefObject: UpdateLabelRefObject) -> LabelRefObjectList: data = jsonpickle.encode(UpdateLabelRefObject, unpicklable=False) data = json.loads(data) data = CommonFunctions.dropna(data) data = [data] data_str = json.dumps(data) result = self.conn.put('/ncc/label-refs/', data_str) labelref_list = [] for arr in result: labelref = LabelRefObject(arr) labelref_list.append(labelref) return labelref_list
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
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)
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
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
class LabelRef: 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) LabelRefObjectList = List[LabelRefObject] def update(self, customerId, enable, nccLabelId, refId, refTp, editTm=None, regTm=None) -> LabelRefObjectList: data = jsonpickle.encode(UpdateLabelRefObject(editTm, customerId, enable, nccLabelId, refId, refTp, regTm), unpicklable=False) data = json.loads(data) data = CommonFunctions.dropna(data) data = [data] data_str = json.dumps(data) result = self.conn.put('/ncc/label-refs/', data_str) return result
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
class Label: 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) LabelObjectList = List[LabelObject] def list(self): result = self.conn.get('/ncc/labels') return result def update(self, color: str, name: str, nccLabelId: str) -> LabelObject: data = jsonpickle.encode(UpdateLabelObject(color, name, nccLabelId), unpicklable=False) data = json.loads(data) data = CommonFunctions.dropna(data) data_str = json.dumps(data) result = self.conn.put('/ncc/labels', data_str) return result
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
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
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