From 5428c02ef29f0e2674dcd4268c3b40a24a8e593f Mon Sep 17 00:00:00 2001 From: Narayana Shanbhog Date: Mon, 16 Oct 2023 18:33:15 +0530 Subject: [PATCH] import campaign support (#184) * import campaign support * brand id filter fix * version update * remove space --------- Co-authored-by: renoldthomas-plivo --- CHANGELOG.md | 5 +++++ baseclient.go | 2 +- campaign.go | 26 ++++++++++++++++++++++---- campaign_test.go | 26 +++++++++++++++++++++++++- fixtures/campaignImportResponse.json | 5 +++++ 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 fixtures/campaignImportResponse.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c2b2b..3057195 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [7.38.0](https://github.com/plivo/plivo-go/tree/v7.38.0) (2023-10-16) +**Feature - Campaign API Enhancements & New API for Importing Partner Campaigns** +- Import Partner Campaign API +- campaign_source field in LIST / GET API + ## [7.37.0](https://github.com/plivo/plivo-go/tree/v7.37.0) (2023-08-25) **Feature - Added New Param 'carrier_fees', 'carrier_fees_rate', 'destination_network' in Get Message and List Message APIs** - Added new params on message get and list response diff --git a/baseclient.go b/baseclient.go index b1940ff..a99b341 100644 --- a/baseclient.go +++ b/baseclient.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-querystring/query" ) -const sdkVersion = "7.37.0" +const sdkVersion = "7.38.0" const lookupBaseUrl = "lookup.plivo.com" diff --git a/campaign.go b/campaign.go index d7c8026..3f5596e 100644 --- a/campaign.go +++ b/campaign.go @@ -3,6 +3,12 @@ package plivo type CampaignService struct { client *Client } +type ImportCampaignParams struct { + CampaignID string `json:"campaign_id,omitempty" url:"campaign_id,omitempty"` + CampaignAlias string `json:"campaign_alias,omitempty" url:"campaign_alias,omitempty"` + URL string `json:"url,omitempty" url:"url,omitempty"` + Method string `json:"method,omitempty" url:"method,omitempty"` +} type CampaignCreationParams struct { BrandID string `json:"brand_id" url:"brand_id" validate:"required"` CampaignAlias *string `json:"campaign_alias,omitempty" url:"campaign_alias,omitempty"` @@ -88,6 +94,7 @@ type Campaign struct { CampaignDescription string `json:"description,omitempty"` CampaignAttributes CampaignAttributes `json:"campaign_attributes,omitempty"` CreatedAt string `json:"created_at,omitempty"` + CampaignSource string `json:"campaign_source,omitempty"` } type CampaignAttributes struct { @@ -112,10 +119,11 @@ type OperatorDetail struct { TPM int `json:"tpm,omitempty"` } type CampaignListParams struct { - BrandID *string `json:"brand,omitempty"` - Usecase *string `json:"usecase,omitempty"` - Limit int `url:"limit,omitempty"` - Offset int `url:"offset,omitempty"` + BrandID *string `json:"brand_id,omitempty"` + Usecase *string `json:"usecase,omitempty"` + CampaignSource *string `json:"campaign_source,omitempty"` + Limit int `url:"limit,omitempty"` + Offset int `url:"offset,omitempty"` } type CampaignNumberLinkParams struct { @@ -184,6 +192,16 @@ func (service *CampaignService) Create(params CampaignCreationParams) (response return } +func (service *CampaignService) Import(params ImportCampaignParams) (response *CampaignCreateResponse, err error) { + req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/Import") + if err != nil { + return + } + response = &CampaignCreateResponse{} + err = service.client.ExecuteRequest(req, response) + return +} + func (service *CampaignService) Update(campaignID string, params CampaignUpdateParams) (response *CampaignGetResponse, err error) { // response needs to be same as CampaignGetResponse req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/%s", campaignID) diff --git a/campaign_test.go b/campaign_test.go index c7e97ee..f63eab6 100644 --- a/campaign_test.go +++ b/campaign_test.go @@ -48,6 +48,30 @@ func TestCampaign_Get(t *testing.T) { assertRequest(t, "GET", "10dlc/Campaign/%s", CampaignID) } +func TestImportCampaign(t *testing.T) { + expectResponse("campaignImportResponse.json", 200) + assert := require.New(t) + resp, err := client.Campaign.Import(ImportCampaignParams{ + CampaignID: "C1QGYD1", + CampaignAlias: "import campaign", + }) + assert.NotNil(resp) + assert.Nil(err) + assert.NotEmpty(resp.ApiID) + assert.NotEmpty(resp.CampaignID) + cl := client.httpClient + client.httpClient = nil + resp, err = client.Campaign.Import(ImportCampaignParams{ + CampaignID: "C1QGYD1", + CampaignAlias: "import campaign", + }) + assert.NotNil(err) + assert.Nil(resp) + client.httpClient = cl + + assertRequest(t, "POST", "10dlc/Campaign/Import") +} + func TestCampaign_Create(t *testing.T) { expectResponse("campaignCreationResponse.json", 200) assert := require.New(t) @@ -306,4 +330,4 @@ func TestCampaign_Delete(t *testing.T) { client.httpClient = cl assertRequest(t, "DELETE", "10dlc/Campaign/%s", CampaignID) -} \ No newline at end of file +} diff --git a/fixtures/campaignImportResponse.json b/fixtures/campaignImportResponse.json new file mode 100644 index 0000000..950de30 --- /dev/null +++ b/fixtures/campaignImportResponse.json @@ -0,0 +1,5 @@ +{ + "api_id": "2c6c5e16-090a-11ed-bb48-0242ac110004", + "campaign_id": "C1QGYD1", + "message": "Request to import campaign was received and is being processed." +} \ No newline at end of file