Skip to content

Commit

Permalink
Update Campaign Go SDK (#153)
Browse files Browse the repository at this point in the history
* Update Campaign Go SDK

* UT

* POST method

* update argument type

* IT

* merge fix

* version update
  • Loading branch information
NirmitiJain authored Jan 5, 2023
1 parent 8c17c5a commit ede74a5
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Change Log
## [7.16.0](https://github.com/plivo/plivo-go/tree/v7.16.0) (2022-12-16)
**Feature - Update campaign**
- Update campaign API

## [7.15.0](https://github.com/plivo/plivo-go/tree/v7.15.0) (2022-12-06)
**Feature - Delete campaign and brand API**
- Added Delete campaign and brand API
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.15.0"
const sdkVersion = "7.16.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down
96 changes: 61 additions & 35 deletions campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ type CampaignCreationParams struct {
HelpKeywords string `json:"help_keywords,omitempty" url:"help_keywords"`
}

type CampaignUpdateParams struct {
ResellerID string `json:" reseller_id,omitempty" url:" reseller_id,omitempty"`
Description string `json:"description,omitempty" url:"description,omitempty"`
Sample1 string `json:"sample1" url:"sample1"`
Sample2 string `json:"sample2,omitempty" url:"sample2,omitempty"`
MessageFlow string `json:"message_flow,omitempty" url:"message_flow"`
HelpMessage string `json:"help_message,omitempty" url:"help_message"`
OptinKeywords string `json:"optin_keywords,omitempty" url:"optin_keywords"`
OptinMessage string `json:"optin_message,omitempty" url:"optin_message"`
OptoutKeywords string `json:"optout_keywords,omitempty" url:"optout_keywords"`
OptoutMessage string `json:"optout_message,omitempty" url:"optout_message"`
HelpKeywords string `json:"help_keywords,omitempty" url:"help_keywords"`
}

type CampaignListResponse struct {
ApiID string `json:"api_id,omitempty"`
CampaignResponse []Campaign `json:"campaigns,omitempty"`
Expand All @@ -55,35 +69,35 @@ type CampaignDeleteResponse struct {
}

type Campaign struct {
BrandID string `json:"brand_id,omitempty"`
CampaignID string `json:"campaign_id,omitempty"`
MnoMetadata MnoMetadata `json:"mno_metadata,omitempty"`
ResellerID string `json:"reseller_id,omitempty"`
Usecase string `json:"usecase,omitempty"`
SubUsecase string `json:"sub_usecase,omitempty"`
RegistrationStatus string `json:"registration_status,omitempty"`
MessageFlow string `json:"message_flow,omitempty"`
HelpMessage string `json:"help_message,omitempty"`
OptinKeywords string `json:"optin_keywords,omitempty"`
OptinMessage string `json:"optin_message,omitempty"`
OptoutKeywords string `json:"optout_keywords,omitempty"`
OptoutMessage string `json:"optout_message,omitempty"`
HelpKeywords string `json:"help_keywords,omitempty"`
SampleMessage1 string `json:"sample1,omitempty"`
SampleMessage2 string `json:"sample2,omitempty"`
CampaignDescription string `json:"description,omitempty"`
CampaignAttributes CampaignAttributes `json:"campaign_attributes,omitempty"`
}

type CampaignAttributes struct{
EmbeddedLink bool `json:"embedded_link"`
EmbeddedPhone bool `json:"embedded_phone"`
AgeGated bool `json:"age_gated"`
DirectLending bool `json:"direct_lending"`
SubscriberOptin bool `json:"subscriber_optin"`
SubscriberOptout bool `json:"subscriber_optout"`
SubscriberHelp bool `json:"subscriber_help"`
AffiliateMarketing bool `json:"affiliate_marketing"`
BrandID string `json:"brand_id,omitempty"`
CampaignID string `json:"campaign_id,omitempty"`
MnoMetadata MnoMetadata `json:"mno_metadata,omitempty"`
ResellerID string `json:"reseller_id,omitempty"`
Usecase string `json:"usecase,omitempty"`
SubUsecase string `json:"sub_usecase,omitempty"`
RegistrationStatus string `json:"registration_status,omitempty"`
MessageFlow string `json:"message_flow,omitempty"`
HelpMessage string `json:"help_message,omitempty"`
OptinKeywords string `json:"optin_keywords,omitempty"`
OptinMessage string `json:"optin_message,omitempty"`
OptoutKeywords string `json:"optout_keywords,omitempty"`
OptoutMessage string `json:"optout_message,omitempty"`
HelpKeywords string `json:"help_keywords,omitempty"`
SampleMessage1 string `json:"sample1,omitempty"`
SampleMessage2 string `json:"sample2,omitempty"`
CampaignDescription string `json:"description,omitempty"`
CampaignAttributes CampaignAttributes `json:"campaign_attributes,omitempty"`
}

type CampaignAttributes struct {
EmbeddedLink bool `json:"embedded_link"`
EmbeddedPhone bool `json:"embedded_phone"`
AgeGated bool `json:"age_gated"`
DirectLending bool `json:"direct_lending"`
SubscriberOptin bool `json:"subscriber_optin"`
SubscriberOptout bool `json:"subscriber_optout"`
SubscriberHelp bool `json:"subscriber_help"`
AffiliateMarketing bool `json:"affiliate_marketing"`
}

type MnoMetadata struct {
Expand Down Expand Up @@ -125,13 +139,13 @@ type CampaignNumberLinkUnlinkResponse struct {
}

type CampaignNumberGetResponse struct {
ApiID string `json:"api_id"`
CampaignID string `json:"campaign_id"`
CampaignAlias string `json:"campaign_alias"`
CampaignUseCase string `json:"usecase"`
CampaignNumbers []CampaignNumber `json:"phone_numbers"`
ApiID string `json:"api_id"`
CampaignID string `json:"campaign_id"`
CampaignAlias string `json:"campaign_alias"`
CampaignUseCase string `json:"usecase"`
CampaignNumbers []CampaignNumber `json:"phone_numbers"`
CampaignNumberSummary map[string]int `json:"phone_numbers_summary,omitempty"`
NumberPoolLimit int `json:"number_pool_limit,omitempty"`
NumberPoolLimit int `json:"number_pool_limit,omitempty"`
}

type CampaignNumber struct {
Expand Down Expand Up @@ -169,6 +183,18 @@ func (service *CampaignService) Create(params CampaignCreationParams) (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)
if err != nil {
return
}
response = &CampaignGetResponse{}
err = service.client.ExecuteRequest(req, response)
return
}

func (service *CampaignService) Delete(campaignID string) (response *CampaignDeleteResponse, err error) {
req, err := service.client.NewRequest("DELETE", nil, "10dlc/Campaign/%s", campaignID)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ func TestCampaign_Create_WithMoreAttribute(t *testing.T) {
assertRequest(t, "POST", "10dlc/Campaign")
}

func TestCampaign_Update(t *testing.T) {
expectResponse("campaignUpdateResponse.json", 200)
campaignID := "CXNSG9W"
assert := require.New(t)
sample1 := "test1"
sample2 := "test2"
resp, err := client.Campaign.Update(campaignID, CampaignUpdateParams{
Sample1: sample1,
Sample2: sample2,
})
assert.NotNil(resp)
assert.Nil(err)
assert.NotEmpty(resp.ApiID)
assert.NotEmpty(resp.Campaign.CampaignID)
cl := client.httpClient
client.httpClient = nil
resp, err = client.Campaign.Update(campaignID, CampaignUpdateParams{
Sample1: sample1,
Sample2: sample2,
})
assert.NotNil(err)
assert.Nil(resp)
client.httpClient = cl

assertRequest(t, "POST", "10dlc/Campaign/%s", campaignID)
}

func TestCampaign_NumberLink(t *testing.T) {
expectResponse("campaignNumberLinkUnlinkResponse.json", 200)
assert := require.New(t)
Expand Down
40 changes: 40 additions & 0 deletions fixtures/campaignUpdateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"api_id": "f687a17e-0725-11ed-ab02-0242ac110004",
"campaign": {
"campaign_id": "CXNSG9W",
"registration_status": "FAILED",
"reseller_id": "",
"brand_id": "BS2TTMI",
"usecase": "MARKETING",
"mno_metadata": {
"AT&T": {
"tpm": 4500
},
"T-Mobile": {
"brand_tier": "TOP"
},
"US Cellular": {
"tpm": 4500
},
"Verizon Wireless": {
"tpm": 4500
}
},
"sample1": "updated sample1 asdsdasdfasdsdasdf 2",
"sample2": "sample message sdasdasdasdsdasdasda 2",
"description": "campaign descriptioncampaign descriptioncampaign descriptioncampaign descriptioncampaign descriptioncampaign descriptioncampaign descriptioncampaign descriptioncampaign description",
"campaign_attributes": {
"embedded_link": false,
"embedded_phone": false,
"age_gated": false,
"direct_lending": false,
"subscriber_optin": false,
"subscriber_optout": false,
"subscriber_help": false,
"affiliate_marketing": false
},
"message_flow": "message flowmessage flowmessage flowmessage flowmessage flowmessage flowmessage flowmessage flowmessage flow",
"help_message": "help message 2help message 2help message 2help message 2help message 2help message 2help message 2help message 2",
"help_keywords": "HELP UPDATE"
}
}

0 comments on commit ede74a5

Please sign in to comment.