Skip to content

Commit

Permalink
feat(dmp): 增加dmp人群包相关API
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Jul 30, 2021
1 parent 9d1e9c3 commit 49528f7
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
16 changes: 16 additions & 0 deletions api/dmp/population_accounts_push.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions api/dmp/population_delete.go
Original file line number Diff line number Diff line change
@@ -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)
}
16 changes: 16 additions & 0 deletions api/dmp/population_list.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions api/dmp/population_push.go
Original file line number Diff line number Diff line change
@@ -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)
}
16 changes: 16 additions & 0 deletions api/dmp/population_update.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions api/dmp/population_upload.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions model/dmp/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package dmp DMP人群管理相关API models
package dmp
27 changes: 27 additions & 0 deletions model/dmp/population.go
Original file line number Diff line number Diff line change
@@ -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"`
}
24 changes: 24 additions & 0 deletions model/dmp/population_accounts_push_request.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions model/dmp/population_accounts_push_response.go
Original file line number Diff line number Diff line change
@@ -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"`
}
22 changes: 22 additions & 0 deletions model/dmp/population_delete_request.go
Original file line number Diff line number Diff line change
@@ -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
}
39 changes: 39 additions & 0 deletions model/dmp/population_list_request.go
Original file line number Diff line number Diff line change
@@ -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()
}
22 changes: 22 additions & 0 deletions model/dmp/population_push_request.go
Original file line number Diff line number Diff line change
@@ -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
}
57 changes: 57 additions & 0 deletions model/dmp/population_update_request.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
}
51 changes: 51 additions & 0 deletions model/dmp/population_upload_request.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
}

0 comments on commit 49528f7

Please sign in to comment.