Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dimuska139 committed Jul 6, 2021
1 parent a655924 commit b73950a
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 80 deletions.
28 changes: 14 additions & 14 deletions sendpulse/automation360_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Autoresponder struct {
MainID int `json:"main_id"`
AfType string `json:"af_type"`
Created DateTimeType `json:"created"`
LastSend DateTimeType `json:"created"`
LastSend DateTimeType `json:"last_send"`
Task map[string]interface{} `json:"task"`
} `json:"flows"`
Starts int `json:"starts"`
Expand All @@ -44,7 +44,7 @@ func (service *Automation360Service) GetAutoresponderStatistics(id int) (*Autore
path := fmt.Sprintf("/a360/autoresponders/%d", id)

var respData *Autoresponder
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}

Expand All @@ -55,7 +55,7 @@ func (service *Automation360Service) StartEvent(eventName string, variables map[
var respData struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), variables, &respData, true)
_, err := service.client.newRequest(http.MethodPost, path, variables, &respData, true)
return err
}

Expand All @@ -73,7 +73,7 @@ func (service *Automation360Service) GetStartBlockStatistics(id int) (*MainTrigg
var respData struct {
Data *MainTriggerBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (service *Automation360Service) GetEmailBlockStatistics(id int) (*EmailBloc
var respData struct {
Data *EmailBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -126,7 +126,7 @@ func (service *Automation360Service) GetPushBlockStatistics(id int) (*PushBlockS
var respData struct {
Data *PushBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -149,7 +149,7 @@ func (service *Automation360Service) GetSmsBlockStatistics(id int) (*SmsBlockSta
var respData struct {
Data *SmsBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -168,7 +168,7 @@ func (service *Automation360Service) GetMessengerBlockStatistics(id int) (*Messe
var respData struct {
Data *MessengerBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -186,7 +186,7 @@ func (service *Automation360Service) GetFilterBlockStatistics(id int) (*FilterBl
var respData struct {
Data *FilterBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -204,7 +204,7 @@ func (service *Automation360Service) GetTriggerBlockStatistics(id int) (*Trigger
var respData struct {
Data *TriggerBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -227,7 +227,7 @@ func (service *Automation360Service) GetGoalBlockStatistics(id int) (*GoalBlockS
var respData struct {
Data *GoalBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -245,7 +245,7 @@ func (service *Automation360Service) GetActionBlockStatistics(id int) (*ActionBl
var respData struct {
Data *ActionBlockStat `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand Down Expand Up @@ -279,7 +279,7 @@ func (service *Automation360Service) GetAutoresponderConversions(id int) (*Autor
var respData struct {
Data *AutoresponderConversion `json:"data"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}

Expand All @@ -301,6 +301,6 @@ func (service *Automation360Service) GetAutoresponderContacts(id int) ([]*Autore
var respData struct {
Items []*AutoresponderContact `json:"items"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData.Items, err
}
5 changes: 2 additions & 3 deletions sendpulse/balance_service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sendpulse

import (
"fmt"
"net/http"
"strings"
)
Expand Down Expand Up @@ -56,7 +55,7 @@ func (service *BalanceService) GetBalance(currency string) (*Balance, error) {
}

var respData Balance
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return &respData, err
}

Expand All @@ -65,6 +64,6 @@ func (service *BalanceService) GetDetailedBalance() (*BalanceDetailed, error) {
path := "/user/balance/detail"

var respData BalanceDetailed
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return &respData, err
}
18 changes: 9 additions & 9 deletions sendpulse/emails_address_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type EmailInfo struct {
func (service *AddressService) GetEmailInfo(email string) ([]*EmailInfo, error) {
path := fmt.Sprintf("/emails/%s", email)
var response []*EmailInfo
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &response, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &response, true)
return response, err
}

Expand All @@ -46,7 +46,7 @@ func (service *AddressService) GetEmailsInfo(emails []string) (map[string][]*Ema

params := data{Emails: emails}
respData := make(map[string][]*EmailInfo)
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &respData, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &respData, true)
return respData, err
}

Expand All @@ -62,15 +62,15 @@ type EmailInfoList struct {
func (service *AddressService) GetDetails(email string) ([]*EmailInfoList, error) {
path := fmt.Sprintf("/emails/%s/details", email)
var response []*EmailInfoList
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &response, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &response, true)
return response, err
}

// GetStatisticsByCampaign returns information for a specific email address from a specific campaign
func (service *AddressService) GetStatisticsByCampaign(campaignID int, email string) (*CampaignEmailStatistics, error) {
path := fmt.Sprintf("/campaigns/%d/email/%s", campaignID, email)
var respData *CampaignEmailStatistics
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}

Expand All @@ -96,7 +96,7 @@ type CampaignEmailStatistics struct {
func (service *AddressService) GetStatisticsByAddressBook(addressBookID int, email string) (*AddressBookEmailStatistics, error) {
path := fmt.Sprintf("/addressbooks/%d/emails/%s", addressBookID, email)
var respData AddressBookEmailStatistics
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return &respData, err
}

Expand All @@ -106,7 +106,7 @@ func (service *AddressService) DeleteFromAllAddressBooks(email string) error {
var respData struct {
Result bool
}
_, err := service.client.newRequest(http.MethodDelete, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodDelete, path, nil, &respData, true)
return err
}

Expand All @@ -128,7 +128,7 @@ type CampaignsEmailStatistics struct {
func (service *AddressService) GetEmailStatisticsByCampaignsAndAddressBooks(email string) (*CampaignsEmailStatistics, error) {
path := fmt.Sprintf("/emails/%s/campaigns", email)
var respData *CampaignsEmailStatistics
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}

Expand All @@ -154,7 +154,7 @@ func (service *AddressService) GetEmailsStatisticsByCampaignsAndAddressBooks(ema
}

params := data{Emails: emails}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &respData, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &respData, true)
return respData, err
}

Expand All @@ -171,6 +171,6 @@ func (service *AddressService) ChangeVariables(addressBookID int, email string,
var respData struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &respData, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &respData, true)
return err
}
2 changes: 1 addition & 1 deletion sendpulse/emails_addressbooks_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (service *MailingListsService) CreateMailingList(name string) (int, error)
ID int `json:"id"`
}
params := data{Name: name}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &response, true)
return response.ID, err
}

Expand Down
7 changes: 3 additions & 4 deletions sendpulse/emails_blacklist_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sendpulse

import (
b64 "encoding/base64"
"fmt"
"net/http"
"strings"
)
Expand Down Expand Up @@ -39,7 +38,7 @@ func (service *BlacklistService) AddToBlacklist(emails []string, comment string)
}

var respData response
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &respData, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &respData, true)
return err
}

Expand All @@ -60,7 +59,7 @@ func (service *BlacklistService) RemoveFromBlacklist(emails []string) error {
}

var respData response
_, err := service.client.newRequest(http.MethodDelete, fmt.Sprintf(path), params, &respData, true)
_, err := service.client.newRequest(http.MethodDelete, path, params, &respData, true)
return err
}

Expand All @@ -69,6 +68,6 @@ func (service *BlacklistService) GetEmails() ([]string, error) {
path := "/blacklist"

var respData []string
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}
6 changes: 3 additions & 3 deletions sendpulse/emails_mailings_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (service *CampaignsService) CreateCampaign(data CampaignParams) (*Campaign,
data.BodyAMP = b64.StdEncoding.EncodeToString([]byte(data.BodyAMP))
}

_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), data, &innerMailing, true)
_, err := service.client.newRequest(http.MethodPost, path, data, &innerMailing, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -99,15 +99,15 @@ func (service *CampaignsService) UpdateCampaign(id int, data CampaignParams) err
data.BodyAMP = b64.StdEncoding.EncodeToString([]byte(data.BodyAMP))
}

_, err := service.client.newRequest(http.MethodPatch, fmt.Sprintf(path), data, &respData, true)
_, err := service.client.newRequest(http.MethodPatch, path, data, &respData, true)
return err
}

// GetCampaign returns an information about specific campaign
func (service *CampaignsService) GetCampaign(id int) (*Campaign, error) {
path := fmt.Sprintf("/campaigns/%d", id)
var respData Campaign
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return &respData, err
}

Expand Down
10 changes: 5 additions & 5 deletions sendpulse/emails_senders_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (service *SendersService) CreateSender(name string, email string) error {
Result bool `json:"result"`
}

_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &response, true)
return err
}

Expand All @@ -40,7 +40,7 @@ func (service *SendersService) GetSenderActivationCode(email string) error {
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &response, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &response, true)
return err
}

Expand All @@ -58,7 +58,7 @@ func (service *SendersService) ActivateSender(email, code string) error {
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &response, true)
return err
}

Expand All @@ -72,7 +72,7 @@ func (service *SendersService) GetSenders() ([]*Sender, error) {
path := "/senders"

var respData []*Sender
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}

Expand All @@ -90,6 +90,6 @@ func (service *SendersService) DeleteSender(email string) error {
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodDelete, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodDelete, path, params, &response, true)
return err
}
8 changes: 4 additions & 4 deletions sendpulse/emails_templates_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (service *TemplatesService) CreateTemplate(name string, body string, lang s
Result bool `json:"result"`
RealID int `json:"real_id"`
}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &response, true)
return response.RealID, err
}

Expand All @@ -58,7 +58,7 @@ func (service *TemplatesService) UpdateTemplate(templateID int, body string, lan
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(http.MethodPost, fmt.Sprintf(path), params, &response, true)
_, err := service.client.newRequest(http.MethodPost, path, params, &response, true)
return err
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (t *Template) UnmarshalJSON(data []byte) error {
func (service *TemplatesService) GetTemplate(templateID int) (*Template, error) {
path := fmt.Sprintf("/template/%d", templateID)
var respData Template
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return &respData, err
}

Expand All @@ -116,6 +116,6 @@ func (service *TemplatesService) GetTemplates(limit, offset int, owner string) (
}

var respData []*Template
_, err := service.client.newRequest(http.MethodGet, fmt.Sprintf(path), nil, &respData, true)
_, err := service.client.newRequest(http.MethodGet, path, nil, &respData, true)
return respData, err
}
Loading

0 comments on commit b73950a

Please sign in to comment.