Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import campaign support #184

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 22 additions & 4 deletions campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -306,4 +330,4 @@ func TestCampaign_Delete(t *testing.T) {
client.httpClient = cl

assertRequest(t, "DELETE", "10dlc/Campaign/%s", CampaignID)
}
}
5 changes: 5 additions & 0 deletions fixtures/campaignImportResponse.json
Original file line number Diff line number Diff line change
@@ -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."
}
Loading