Skip to content

Commit

Permalink
Change code after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
SoeunSona committed Dec 14, 2023
1 parent c850433 commit 18f08cb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -135,7 +135,6 @@ api.UpdateNote(&cm.UpdateNote{}, "noteUUID")
api.DeleteNote("noteUUID")
```


#### [Plans](https://dev.chartmogul.com/reference#plans)

```go
Expand Down
2 changes: 1 addition & 1 deletion customer_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions customers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -265,17 +264,21 @@ 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
//
// 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)
}
2 changes: 1 addition & 1 deletion customers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/customer_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
49 changes: 24 additions & 25 deletions notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 18f08cb

Please sign in to comment.