diff --git a/README.md b/README.md index 9f543bb..7dfb631 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ go get github.com/chartmogul/chartmogul-go/v4 [Deprecation] - `account_token`/`secret_key` combo is deprecated. Please use API key for both fields. Version 3.x will introduce a breaking change in authentication configuration. For more details, please visit: https://dev.chartmogul.com -Version 4.x will introduce a breaking change for pagination on List endpoints. The `cursor` object now expects a `per_page` and `cursor` parameter. `page` will no longer be accepted. +Version 4.x will introduce a breaking change for pagination on List endpoints. The `cursor` object now expects a `per_page` and `cursor` parameter. `page` will no longer be accepted. First create the `API` struct by passing your API key, available from the administration section of your ChartMogul account. @@ -135,7 +135,6 @@ api.UpdateNote(&cm.UpdateNote{}, "noteUUID") api.DeleteNote("noteUUID") ``` - #### [Plans](https://dev.chartmogul.com/reference#plans) ```go diff --git a/customer_notes_test.go b/customer_notes_test.go index 73d849c..08cf818 100644 --- a/customer_notes_test.go +++ b/customer_notes_test.go @@ -41,7 +41,7 @@ func TestListNotes(t *testing.T) { tested := &API{ ApiKey: "token", } - params := &ListNotesParams{PaginationWithCursor: PaginationWithCursor{PerPage: 1}, CustomerUUID: "cus_00000000-0000-0000-0000-000000000000"} + params := &ListNotesParams{Cursor: Cursor{PerPage: 1}, CustomerUUID: "cus_00000000-0000-0000-0000-000000000000"} customer_notes, err := tested.ListNotes(params) if err != nil { diff --git a/customers.go b/customers.go index c4b3e2f..2217464 100644 --- a/customers.go +++ b/customers.go @@ -143,7 +143,6 @@ const ( searchCustomersEndpoint = "customers/search" mergeCustomersEndpoint = "customers/merges" customerContactsEndpoint = "customers/:uuid/contacts" - customerNotesEndpoin = "customer_notes" ) // CreateCustomer loads the customer to Chartmogul. New endpoint - with attributes. @@ -265,10 +264,12 @@ func (api API) ListCustomerNotes(listCustomerNotesParams *ListNotesParams, custo result := &Notes{} query := make([]interface{}, 0, 1) if listCustomerNotesParams != nil { + if listCustomerNotesParams.CustomerUUID == "" { + listCustomerNotesParams.CustomerUUID = customerUUID + } query = append(query, *listCustomerNotesParams) } - path := customerNotesEndpoint + "?customer_uuid=" + customerUUID - return result, api.list(path, result, query...) + return result, api.list(customerNotesEndpoint, result, query...) } // CreateCustomerNote @@ -276,6 +277,8 @@ func (api API) ListCustomerNotes(listCustomerNotesParams *ListNotesParams, custo // See https://dev.chartmogul.com/reference/create-a-customer-note func (api API) CreateCustomerNote(input *NewNote, customerUUID string) (*Note, error) { result := &Note{} - input.CustomerUUID = customerUUID + if input.CustomerUUID == "" { + input.CustomerUUID = customerUUID + } return result, api.create(customerNotesEndpoint, input, result) } diff --git a/customers_test.go b/customers_test.go index ed98769..5c76344 100644 --- a/customers_test.go +++ b/customers_test.go @@ -472,7 +472,7 @@ func TestListCustomerNotes(t *testing.T) { ApiKey: "token", } uuid := "cus_00000000-0000-0000-0000-000000000000" - params := &ListNotesParams{PaginationWithCursor: PaginationWithCursor{PerPage: 1}} + params := &ListNotesParams{Cursor: Cursor{PerPage: 1}} customer_notes, err := tested.ListCustomerNotes(params, uuid) if err != nil { diff --git a/integration_tests/customer_notes_test.go b/integration_tests/customer_notes_test.go index 7174daf..75571f8 100644 --- a/integration_tests/customer_notes_test.go +++ b/integration_tests/customer_notes_test.go @@ -7,7 +7,7 @@ import ( "reflect" "testing" - cm "github.com/chartmogul/chartmogul-go/v3" + cm "github.com/chartmogul/chartmogul-go/v4" "github.com/davecgh/go-spew/spew" "github.com/parnurzeal/gorequest" ) @@ -56,8 +56,8 @@ func TestCustomerNotesIntegration(t *testing.T) { t.Fatal(err) } allNotes, err := api.ListNotes(&cm.ListNotesParams{ - CustomerUUID: cus1.UUID, - PaginationWithCursor: cm.PaginationWithCursor{PerPage: 10}, + CustomerUUID: cus1.UUID, + Cursor: cm.Cursor{PerPage: 10}, }) if err != nil { t.Fatal(err) @@ -72,7 +72,7 @@ func TestCustomerNotesIntegration(t *testing.T) { if !reflect.DeepEqual(expectedAllNotes, expectedAllNotes) { spew.Dump(allNotes) spew.Dump(expectedAllNotes) - t.Fatal("All notes is not equal!") + t.Fatal("All notes are not equal!") } retrievedNote, err := api.RetrieveNote(newNote.UUID) diff --git a/notes.go b/notes.go index 95a09a5..1fa1eb8 100644 --- a/notes.go +++ b/notes.go @@ -2,51 +2,50 @@ package chartmogul // Note is the customer note as represented in the API. type Note struct { - UUID string `json:"uuid,omitempty"` + UUID string `json:"uuid"` // Basic info - CustomerUUID string `json:"customer_uuid,omitempty"` - Type string `json:"type,omitempty"` - Text string `json:"text,omitempty"` - Author string `json:"author,omitempty"` - CallDuration uint32 `json:"call_duration,omitempty"` - CreatedAt string `json:"created_at,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` + CustomerUUID string `json:"customer_uuid"` + Type string `json:"type"` + Text string `json:"text"` + Author string `json:"author"` + CallDuration uint32 `json:"call_duration"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` } // UpdateNote allows updating note on the update endpoint. type UpdateNote struct { - Text string `json:"text,omitempty"` - AuthorEmail string `json:"author_email,omitempty"` - CallDuration uint32 `json:"call_duration,omitempty"` - CreatedAt string `json:"create_at,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` + Text string `json:"text"` + AuthorEmail string `json:"author_email"` + CallDuration uint32 `json:"call_duration"` + CreatedAt string `json:"create_at"` + UpdatedAt string `json:"updated_at"` } // NewNote allows creating note on a new endpoint. type NewNote struct { // Obligatory - CustomerUUID string `json:"customer_uuid,omitempty"` - Type string `json:"type,omitempty"` + CustomerUUID string `json:"customer_uuid"` + Type string `json:"type"` //Optional - AuthorEmail string `json:"author_email,omitempty"` - Text string `json:"text,omitempty"` - CallDuration uint32 `json:"call_duration,omitempty"` - CreatedAt string `json:"created_at,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` + AuthorEmail string `json:"author_email"` + Text string `json:"text"` + CallDuration uint32 `json:"call_duration"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` } // ListNoteParams = parameters for listing customer notes in API. type ListNotesParams struct { - CustomerUUID string `json:"customer_uuid,omitempty"` - PaginationWithCursor + CustomerUUID string `json:"customer_uuid"` + Cursor } // Notes is result of listing customer notes in API. type Notes struct { - Entries []*Note `json:"entries,omitempty"` - Cursor string `json:"cursor,omitempty"` - HasMore bool `json:"has_more,omitempty"` + Entries []*Note `json:"entries"` + Pagination } const (