Skip to content

Commit

Permalink
Delete Campaign - Brand Go SDK (#152)
Browse files Browse the repository at this point in the history
* Delete Campaign - Brand Go SDK

* method fix

* version update
  • Loading branch information
NirmitiJain authored Dec 15, 2022
1 parent 8a1b682 commit 8c17c5a
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
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.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

## [7.14.0](https://github.com/plivo/plivo-go/tree/v7.14.0) (2022-10-17)
**Feature - Brandusecase API, 10DLC api enhancements**
- Added Brandusecase API, 10DLC api enhancements
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.14.0"
const sdkVersion = "7.15.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down
17 changes: 17 additions & 0 deletions brand.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ type Brand struct {
Address Address `json:"address,omitempty"`
AuthorizedContact AuthorizedContact `json:"authorized_contact,omitempty"`
}

type BrandDeleteResponse struct {
ApiID string `json:"api_id,omitempty"`
BrandID string `json:"brand_id,omitempty"`
Message string `json:"message,omitempty"`
}

type BrandListParams struct {
Type *string `json:"type,omitempty"`
Status *string `json:"status,omitempty"`
Expand Down Expand Up @@ -107,6 +114,16 @@ func (service *BrandService) Get(brandID string) (response *BrandGetResponse, er
return
}

func (service *BrandService) Delete(brandID string) (response *BrandDeleteResponse, err error) {
req, err := service.client.NewRequest("DELETE", nil, "10dlc/Brand/%s", brandID)
if err != nil {
return
}
response = &BrandDeleteResponse{}
err = service.client.ExecuteRequest(req, response)
return
}

func (service *BrandService) Create(params BrandCreationParams) (response *BrandCreationResponse, err error) {
req, err := service.client.NewRequest("POST", params, "10dlc/Brand")
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions brand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,23 @@ func TestBrand_Usecase(t *testing.T) {

assertRequest(t, "GET", "10dlc/Brand/%s/usecases", BrandID)
}

func TestBrand_Delete(t *testing.T) {
expectResponse("brandDeleteResponse.json", 200)
BrandID := "BRPXS6E"
assert := require.New(t)
brand, err := client.Brand.Delete(BrandID)
assert.NotNil(brand)
assert.Nil(err)
assert.Equal(BrandID, brand.BrandID)
assert.NotEmpty(brand.ApiID)

cl := client.httpClient
client.httpClient = nil
brand, err = client.Brand.Delete(BrandID)
assert.NotNil(err)
assert.Nil(brand)
client.httpClient = cl

assertRequest(t, "DELETE", "10dlc/Brand/%s", BrandID)
}
16 changes: 16 additions & 0 deletions campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ type CampaignCreateResponse struct {
Message string `json:"message,omitempty"`
}

type CampaignDeleteResponse struct {
ApiID string `json:"api_id"`
CampaignID string `json:"campaign_id,omitempty"`
Message string `json:"message,omitempty"`
}

type Campaign struct {
BrandID string `json:"brand_id,omitempty"`
CampaignID string `json:"campaign_id,omitempty"`
Expand Down Expand Up @@ -163,6 +169,16 @@ func (service *CampaignService) Create(params CampaignCreationParams) (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 {
return
}
response = &CampaignDeleteResponse{}
err = service.client.ExecuteRequest(req, response)
return
}

func (service *CampaignService) NumberLink(campaignID string, params CampaignNumberLinkParams) (response *CampaignNumberLinkUnlinkResponse, err error) {
req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/%s/Number", campaignID)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,23 @@ func TestCampaign_NumberUnlink(t *testing.T) {

assertRequest(t, "DELETE", "10dlc/Campaign/CY5NVUA/Number/9876564598")
}

func TestCampaign_Delete(t *testing.T) {
expectResponse("campaignDeleteResponse.json", 200)
CampaignID := "CY5NVUA"
assert := require.New(t)
campaign, err := client.Campaign.Delete(CampaignID)
assert.NotNil(campaign)
assert.Nil(err)
assert.Equal(CampaignID, campaign.CampaignID)
assert.NotEmpty(campaign.ApiID)

cl := client.httpClient
client.httpClient = nil
campaign, err = client.Campaign.Delete(CampaignID)
assert.NotNil(err)
assert.Nil(campaign)
client.httpClient = cl

assertRequest(t, "DELETE", "10dlc/Campaign/%s", CampaignID)
}
5 changes: 5 additions & 0 deletions fixtures/brandDeleteResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"message": "Brand Deactivated",
"brand_id": "BRPXS6E",
"api_id": "XXX"
}
5 changes: 5 additions & 0 deletions fixtures/campaignDeleteResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"message": "Campaign Deactivated",
"campaign_id": "CY5NVUA",
"api_id": "XXX"
}

0 comments on commit 8c17c5a

Please sign in to comment.