From 49528f7b11376e0f20810c9adac98e40945960de Mon Sep 17 00:00:00 2001 From: Syd Xu Date: Fri, 30 Jul 2021 19:45:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(dmp):=20=E5=A2=9E=E5=8A=A0dmp=E4=BA=BA?= =?UTF-8?q?=E7=BE=A4=E5=8C=85=E7=9B=B8=E5=85=B3API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++ api/dmp/population_accounts_push.go | 16 ++++++ api/dmp/population_delete.go | 11 ++++ api/dmp/population_list.go | 16 ++++++ api/dmp/population_push.go | 11 ++++ api/dmp/population_update.go | 16 ++++++ api/dmp/population_upload.go | 16 ++++++ model/dmp/doc.go | 2 + model/dmp/population.go | 27 +++++++++ model/dmp/population_accounts_push_request.go | 24 ++++++++ .../dmp/population_accounts_push_response.go | 9 +++ model/dmp/population_delete_request.go | 22 +++++++ model/dmp/population_list_request.go | 39 +++++++++++++ model/dmp/population_push_request.go | 22 +++++++ model/dmp/population_update_request.go | 57 +++++++++++++++++++ model/dmp/population_upload_request.go | 51 +++++++++++++++++ 16 files changed, 346 insertions(+) create mode 100644 api/dmp/population_accounts_push.go create mode 100644 api/dmp/population_delete.go create mode 100644 api/dmp/population_list.go create mode 100644 api/dmp/population_push.go create mode 100644 api/dmp/population_update.go create mode 100644 api/dmp/population_upload.go create mode 100644 model/dmp/doc.go create mode 100644 model/dmp/population.go create mode 100644 model/dmp/population_accounts_push_request.go create mode 100644 model/dmp/population_accounts_push_response.go create mode 100644 model/dmp/population_delete_request.go create mode 100644 model/dmp/population_list_request.go create mode 100644 model/dmp/population_push_request.go create mode 100644 model/dmp/population_update_request.go create mode 100644 model/dmp/population_upload_request.go diff --git a/README.md b/README.md index 35f91b9..213c8b2 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,13 @@ - 广告素材数据 [ CreativeReport(clt *core.SDKClient, accessToken string, req *report.MaterialReportRequest) (*report.ReportResponse, error) ] - 人群分析数据 [ AudienceReport(clt *core.SDKClient, accessToken string, req *report.AudienceReportRequest) (*report.ReportResponse, error) ] - 小店通转化数据 [ MerchantDeatailReport(clt *core.SDKClient, accessToken string, req *report.MerchantDetailReportRequest) (*report.MerchantDetailReportResponse, error) ] +- DMP人群管理(api/dmp) + - 人群包上传接口 [ PopulationUpload(clt *core.SDKClient, accessToken string, req *dmp.PopulationUploadRequest) (*dmp.Population, error) ] + - 人群包更新接口 [ PopulationUpdate(clt *core.SDKClient, accessToken string, req *dmp.PopulationUpdateRequest) (*dmp.Population, error) ] + - 人群列表查询接口 [ PopulationList(clt *core.SDKClient, accessToken string, req *dmp.PopulationListRequest) ([]dmp.Population, error) ] + - 人群包删除接口 [ PopulationDelete(clt *core.SDKClient, accessToken string, req *dmp.PopulationDeleteRequest) error ] + - 人群包跨账户推送 [ PopulationAccountsPush(clt *core.SDKClient, accessToken string, req *dmp.PopulationAccountsPushRequest) (*dmp.PopulationAccountsPushResponse, error) ] + - 人群包上线接口 [ PopulationPush(clt *core.SDKClient, accessToken string, req *dmp.PopulationPushRequest) error ] - 数据上报管理 (api/track) - 转化回传 [ Activate(req *track.ActivateRequest) error ] - 点击检测链接 [ Click(baseUrl string, fields []string) string ] diff --git a/api/dmp/population_accounts_push.go b/api/dmp/population_accounts_push.go new file mode 100644 index 0000000..4cdfdb5 --- /dev/null +++ b/api/dmp/population_accounts_push.go @@ -0,0 +1,16 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationAccountsPush 人群包跨账户推送 +func PopulationAccountsPush(clt *core.SDKClient, accessToken string, req *dmp.PopulationAccountsPushRequest) (*dmp.PopulationAccountsPushResponse, error) { + var resp dmp.PopulationAccountsPushResponse + err := clt.Post(accessToken, req, &resp) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/api/dmp/population_delete.go b/api/dmp/population_delete.go new file mode 100644 index 0000000..5c9120e --- /dev/null +++ b/api/dmp/population_delete.go @@ -0,0 +1,11 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationDelete 人群包删除接口 +func PopulationDelete(clt *core.SDKClient, accessToken string, req *dmp.PopulationDeleteRequest) error { + return clt.Post(accessToken, req, nil) +} diff --git a/api/dmp/population_list.go b/api/dmp/population_list.go new file mode 100644 index 0000000..4c75a84 --- /dev/null +++ b/api/dmp/population_list.go @@ -0,0 +1,16 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationList 人群列表查询接口 +func PopulationList(clt *core.SDKClient, accessToken string, req *dmp.PopulationListRequest) ([]dmp.Population, error) { + var resp []dmp.Population + err := clt.Get(accessToken, req, &resp) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/api/dmp/population_push.go b/api/dmp/population_push.go new file mode 100644 index 0000000..6cf0824 --- /dev/null +++ b/api/dmp/population_push.go @@ -0,0 +1,11 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationPush 人群包上线接口 +func PopulationPush(clt *core.SDKClient, accessToken string, req *dmp.PopulationPushRequest) error { + return clt.Post(accessToken, req, nil) +} diff --git a/api/dmp/population_update.go b/api/dmp/population_update.go new file mode 100644 index 0000000..3215235 --- /dev/null +++ b/api/dmp/population_update.go @@ -0,0 +1,16 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationUpdate 人群包更新接口 +func PopulationUpdate(clt *core.SDKClient, accessToken string, req *dmp.PopulationUpdateRequest) (*dmp.Population, error) { + var resp dmp.Population + err := clt.Upload(accessToken, req, &resp) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/api/dmp/population_upload.go b/api/dmp/population_upload.go new file mode 100644 index 0000000..40246da --- /dev/null +++ b/api/dmp/population_upload.go @@ -0,0 +1,16 @@ +package dmp + +import ( + "github.com/bububa/kwai-marketing-api/core" + "github.com/bububa/kwai-marketing-api/model/dmp" +) + +// PopulationUpload 人群包上传接口 +func PopulationUpload(clt *core.SDKClient, accessToken string, req *dmp.PopulationUploadRequest) (*dmp.Population, error) { + var resp dmp.Population + err := clt.Upload(accessToken, req, &resp) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/model/dmp/doc.go b/model/dmp/doc.go new file mode 100644 index 0000000..29f6e73 --- /dev/null +++ b/model/dmp/doc.go @@ -0,0 +1,2 @@ +// Package dmp DMP人群管理相关API models +package dmp diff --git a/model/dmp/population.go b/model/dmp/population.go new file mode 100644 index 0000000..d51a608 --- /dev/null +++ b/model/dmp/population.go @@ -0,0 +1,27 @@ +package dmp + +// Population 人群包 +type Population struct { + // OrientationID 人群包ID + OrientationID int64 `json:"orientation_id,omitempty"` + // OrientationName 人群包名称 + OrientationName string `json:"orientation_name,omitempty"` + // Type 人群数据类型; 1:IMEI;2:IDFA;3:IMEI_MD5;4:IDFA_MD5;5:手机号-MD5;7:OAID;8:OAID_MD5 + Type int `json:"type,omitempty"` + // PopulationType 人群包类型; 1, "上传人群";2, "广告人群";3, "主题专区";4, "逻辑规则";5, "人群扩展";6, "平台定制";7, "定制付费";8, "网红粉丝类别";9, "内容付费行为";10, "移动应用安装";11, "快手使用活跃度";12, "行业分类";13, "商业兴趣";14, "固化标签";15, "行业偏好";16, "第三方标签";17, "产品关键词";19, "应用渗透率";22, "指定网红";23, "行业分类"(同12) + PopulationType int `json:"population_type,omitempty"` + // RecordSize 上传数量 + RecordSize int64 `json:"record_size,omitempty"` + // MatchSize 匹配数量 + MatchSize int64 `json:"match_size,omitempty"` + // CoverNum 覆盖人群; 返回值固定为0 + CoverNum int64 `json:"cover_num,omitempty"` + // Status 人群包状态; 0, "计算中";1, "已生效";2, "已删除";3, "上线中";4, "已上线";5, "计算失败";6, "上线失败";7, "已失效" + Status int `json:"status,omitempty"` + // CreateTime 创建时间; 格式:13位毫秒级时间戳 + CreateTime int64 `json:"create_time,omitempty"` + // ThirdPlatformCode 付费人群包-第3方平台code + ThirdPlatformCode int `json:"third_platform_code,omitempty"` + // ThirdPlatformName 付费人群包第三方供应商名称 + ThirdPlatformName string `json:"third_platform_name,omitempty"` +} diff --git a/model/dmp/population_accounts_push_request.go b/model/dmp/population_accounts_push_request.go new file mode 100644 index 0000000..417bbe3 --- /dev/null +++ b/model/dmp/population_accounts_push_request.go @@ -0,0 +1,24 @@ +package dmp + +import "encoding/json" + +// PopulationAccountsPushRequest 人群包跨账户推送 APIRequest +type PopulationAccountsPushRequest struct { + // AdvertiserID 广告主 ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // OrientationID 人群包ID + OrientationID int64 `json:"orientation_id,omitempty"` + // DestAccountIDs 要推送的账户ids + DestAccountIDs []int64 `json:"dest_account_ids,omitempty"` +} + +// Url implement PostRequest interface +func (r PopulationAccountsPushRequest) Url() string { + return "v1/dmp/population/accounts/push" +} + +// Encode implement PostRequest interface +func (r PopulationAccountsPushRequest) Encode() []byte { + ret, _ := json.Marshal(r) + return ret +} diff --git a/model/dmp/population_accounts_push_response.go b/model/dmp/population_accounts_push_response.go new file mode 100644 index 0000000..8120c04 --- /dev/null +++ b/model/dmp/population_accounts_push_response.go @@ -0,0 +1,9 @@ +package dmp + +// PopulationAccountsPushResponse 人群包跨账户推送 APIResponse +type PopulationAccountsPushResponse struct { + // Success 推送成功的account_ids + Success []int64 `json:"success,omitempty"` + // Fail 推送失败的account_ids + Fail []int64 `json:"fail,omitempty"` +} diff --git a/model/dmp/population_delete_request.go b/model/dmp/population_delete_request.go new file mode 100644 index 0000000..d708607 --- /dev/null +++ b/model/dmp/population_delete_request.go @@ -0,0 +1,22 @@ +package dmp + +import "encoding/json" + +// PopulationDeleteRequest 人群包删除接口APIRequest +type PopulationDeleteRequest struct { + // AdvertiserID 广告主 ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // OrientationID 人群包ID + OrientationID int64 `json:"orientation_id,omitempty"` +} + +// Url implement PostRequest interface +func (r PopulationDeleteRequest) Url() string { + return "v1/dmp/population/delete" +} + +// Encode implement PostRequest interface +func (r PopulationDeleteRequest) Encode() []byte { + ret, _ := json.Marshal(r) + return ret +} diff --git a/model/dmp/population_list_request.go b/model/dmp/population_list_request.go new file mode 100644 index 0000000..502f537 --- /dev/null +++ b/model/dmp/population_list_request.go @@ -0,0 +1,39 @@ +package dmp + +import ( + "net/url" + "strconv" +) + +// PopulationListRequest 人群列表查询接口 API Request +type PopulationListRequest struct { + // AdvertiserID 广告主ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // Status 人群包状态; 0, "计算中";1, "已生效";2, "已删除";3, "推送中";4, "已推送";5, "计算失败";6, "推送失败" ;7, "已失效" + Status *int `json:"status,omitempty"` + // Page 页码,默认 1 + Page int `json:"page,omitempty"` + // PageSize 页数,默认 20 + PageSize int `json:"page_size,omitempty"` +} + +// Url implement GetRequest interface +func (r PopulationListRequest) Url() string { + return "v2/dmp/population/list" +} + +// Encode implement GetRequest interface +func (r PopulationListRequest) Encode() string { + values := &url.Values{} + values.Set("advertiser_id", strconv.FormatInt(r.AdvertiserID, 10)) + if r.Status != nil { + values.Set("status", strconv.Itoa(*r.Status)) + } + if r.Page > 0 { + values.Set("page", strconv.Itoa(r.Page)) + } + if r.PageSize > 0 { + values.Set("page_size", strconv.Itoa(r.PageSize)) + } + return values.Encode() +} diff --git a/model/dmp/population_push_request.go b/model/dmp/population_push_request.go new file mode 100644 index 0000000..b752242 --- /dev/null +++ b/model/dmp/population_push_request.go @@ -0,0 +1,22 @@ +package dmp + +import "encoding/json" + +// PopulationPushRequest 人群包上线接口APIRequest +type PopulationPushRequest struct { + // AdvertiserID 广告主 ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // OrientationID 人群包 ID; 只有 status 为 1 或 6 的人群包可上线,最多支持 4 个人群包状态同时为“上线中”, + OrientationID int64 `json:"orientation_id,omitempty"` +} + +// Url implement PostRequest interface +func (r PopulationPushRequest) Url() string { + return "v1/dmp/population/push" +} + +// Encode implement PostRequest interface +func (r PopulationPushRequest) Encode() []byte { + ret, _ := json.Marshal(r) + return ret +} diff --git a/model/dmp/population_update_request.go b/model/dmp/population_update_request.go new file mode 100644 index 0000000..015514e --- /dev/null +++ b/model/dmp/population_update_request.go @@ -0,0 +1,57 @@ +package dmp + +import ( + "strconv" + + "github.com/bububa/kwai-marketing-api/model" +) + +// PopulationUpdateRequest 人群包更新接口 +type PopulationUpdateRequest struct { + // AdvertiserID 广告主ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // Type 人群数据类型; 1:IMEI;2:IDFA;3:IMEI_MD5;4:IDFA_MD5;5:手机号-MD5;7:OAID;8:OAID_MD5 + Type int `json:"type,omitempty"` + // OrientationID 人群包id + OrientationID int64 `json:"orientation_id,omitempty"` + // OperationType 修改操作类型; 1:APPEND(增量更新)3:DELETE(缩量更新) + OperationType int `json:"operation_type,omitempty"` + // File 请求的文件; 最大支持500MB + File *model.UploadField `json:"file,omitempty"` +} + +// Url implement UploadRequest interface +func (r PopulationUpdateRequest) Url() string { + return "v1/dmp/population/update" +} + +// Encode implement UploadRequest interface +func (r PopulationUpdateRequest) Encode() []model.UploadField { + fileName := r.File.Value + if fileName == "" { + fileName = "file" + } + return []model.UploadField{ + { + Key: "advertiser_id", + Value: strconv.FormatInt(r.AdvertiserID, 10), + }, + { + Key: "type", + Value: strconv.Itoa(r.Type), + }, + { + Key: "orientation_id", + Value: strconv.FormatInt(r.OrientationID, 10), + }, + { + Key: "operation_type", + Value: strconv.Itoa(r.OperationType), + }, + { + Key: "file", + Value: fileName, + Reader: r.File.Reader, + }, + } +} diff --git a/model/dmp/population_upload_request.go b/model/dmp/population_upload_request.go new file mode 100644 index 0000000..18de6c9 --- /dev/null +++ b/model/dmp/population_upload_request.go @@ -0,0 +1,51 @@ +package dmp + +import ( + "strconv" + + "github.com/bububa/kwai-marketing-api/model" +) + +// PopulationUploadRequest 人群包上传接口 +type PopulationUploadRequest struct { + // AdvertiserID 广告主ID + AdvertiserID int64 `json:"advertiser_id,omitempty"` + // Type 人群数据类型; 1:IMEI;2:IDFA;3:IMEI_MD5;4:IDFA_MD5;5:手机号-MD5;7:OAID;8:OAID_MD5 + Type int `json:"type,omitempty"` + // OrientationName 人群包名称; 不能大于20个字符,人群包名称不得重复 + OrientationName string `json:"orientation_name,omitempty"` + // File 请求的文件; 最大支持500MB + File *model.UploadField `json:"file,omitempty"` +} + +// Url implement UploadRequest interface +func (r PopulationUploadRequest) Url() string { + return "v1/dmp/population/upload" +} + +// Encode implement UploadRequest interface +func (r PopulationUploadRequest) Encode() []model.UploadField { + fileName := r.File.Value + if fileName == "" { + fileName = "file" + } + return []model.UploadField{ + { + Key: "advertiser_id", + Value: strconv.FormatInt(r.AdvertiserID, 10), + }, + { + Key: "type", + Value: strconv.Itoa(r.Type), + }, + { + Key: "orientation_name", + Value: r.OrientationName, + }, + { + Key: "file", + Value: fileName, + Reader: r.File.Reader, + }, + } +}