-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go client notes and call logs API support[sc-55271]
- Loading branch information
Showing
8 changed files
with
858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package chartmogul | ||
|
||
// CustomerNote is the customer note as represented in the API. | ||
type CustomerNote struct { | ||
UUID string `json:"uuid,omitempty"` | ||
// 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"` | ||
} | ||
|
||
// 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"` | ||
} | ||
|
||
// NewNote allows creating note on a new endpoint. | ||
type NewNote struct { | ||
// Obligatory | ||
CustomerUUID string `json:"customer_uuid,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
|
||
//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"` | ||
} | ||
|
||
// ListCustomerNoteParams = parameters for listing customer notes in API. | ||
type ListNotesParams struct { | ||
CustomerUUID string `json:"customer_uuid,omitempty"` | ||
PaginationWithCursor | ||
} | ||
|
||
// CustomerNotes is result of listing customer notes in API. | ||
type CustomerNotes struct { | ||
Entries []*CustomerNote `json:"entries,omitempty"` | ||
Cursor string `json:"cursor,omitempty"` | ||
HasMore bool `json:"has_more,omitempty"` | ||
} | ||
|
||
const ( | ||
singleCustomerNoteEndpoint = "customer_notes/:uuid" | ||
customerNotesEndpoint = "customer_notes" | ||
) | ||
|
||
// CreateCustomerNote loads the customer note to Chartmogul | ||
// | ||
// See https://dev.chartmogul.com/reference/create-a-customer-note | ||
func (api API) CreateNote(input *NewNote) (*CustomerNote, error) { | ||
result := &CustomerNote{} | ||
return result, api.create(customerNotesEndpoint, input, result) | ||
} | ||
|
||
// RetrieveCustomerNote returns one customer note as in API. | ||
// | ||
// See https://dev.chartmogul.com/reference/retrieve-a-customer-note | ||
func (api API) RetrieveNote(customerNoteUUID string) (*CustomerNote, error) { | ||
result := &CustomerNote{} | ||
return result, api.retrieve(singleCustomerNoteEndpoint, customerNoteUUID, result) | ||
} | ||
|
||
// UpdateNote updates one customer note in API. | ||
// | ||
// See https://dev.chartmogul.com/reference/retrieve-a-customer-note | ||
func (api API) UpdateNote(input *UpdateNote, customerNoteUUID string) (*CustomerNote, error) { | ||
output := &CustomerNote{} | ||
return output, api.update(singleCustomerNoteEndpoint, customerNoteUUID, input, output) | ||
} | ||
|
||
// ListNotes lists all CustomerNotes | ||
// | ||
// See https://dev.chartmogul.com/reference/list-all-customer-notes | ||
func (api API) ListNotes(listNotesParams *ListNotesParams) (*CustomerNotes, error) { | ||
result := &CustomerNotes{} | ||
query := make([]interface{}, 0, 1) | ||
if listNotesParams != nil { | ||
query = append(query, *listNotesParams) | ||
} | ||
return result, api.list(customerNotesEndpoint, result, query...) | ||
} | ||
|
||
// DeleteNote deletes one customer note by UUID. | ||
// | ||
// See https://dev.chartmogul.com/reference/delete-a-customer-note | ||
func (api API) DeleteNote(customerNoteUUID string) error { | ||
return api.delete(singleCustomerNoteEndpoint, customerNoteUUID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package chartmogul | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
) | ||
|
||
func TestListNotes(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "GET" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/customer_notes?customer_uuid=cus_00000000-0000-0000-0000-000000000000&per_page=1" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"entries": [{ | ||
"uuid": "note_00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"type": "note", | ||
"author": "John Doe (john@example.com)", | ||
"text": "This is a note", | ||
"call_duration": 0, | ||
"created_at": "2015-06-09T19:20:30Z", | ||
"updated_at": "2015-06-09T19:20:30Z" | ||
}], | ||
"has_more": false, | ||
"cursor": "88abf99" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
params := &ListNotesParams{PaginationWithCursor: PaginationWithCursor{PerPage: 1}, CustomerUUID: "cus_00000000-0000-0000-0000-000000000000"} | ||
customer_notes, err := tested.ListNotes(params) | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if len(customer_notes.Entries) == 0 { | ||
spew.Dump(customer_notes) | ||
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestRetrieveNote(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "GET" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/customer_notes/note_00000000-0000-0000-0000-000000000000" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"uuid": "note_00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"type": "note", | ||
"author": "John Doe (john@example.com)", | ||
"text": "This is a note", | ||
"call_duration": 0, | ||
"created_at": "2015-06-09T19:20:30Z", | ||
"updated_at": "2015-06-09T19:20:30Z" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
customer_note, err := tested.RetrieveNote("note_00000000-0000-0000-0000-000000000000") | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if customer_note == nil { | ||
spew.Dump(customer_note) | ||
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestCreateNote(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/customer_notes" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusCreated) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"uuid": "note_00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"type": "note", | ||
"text": "This is a note", | ||
"author": "John Doe (john@example.com)", | ||
"call_duration": 0, | ||
"created_at": "2015-06-09T19:20:30Z", | ||
"updated_at": "2015-06-09T19:20:30Z" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
|
||
customer_notes, err := tested.CreateNote(&NewNote{ | ||
CustomerUUID: "cus_00000000-0000-0000-0000-000000000000", | ||
Type: "note", | ||
Text: "This is a note", | ||
AuthorEmail: "john@example.com", | ||
CallDuration: 0, | ||
}) | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if customer_notes.UUID != "note_00000000-0000-0000-0000-000000000000" { | ||
spew.Dump(customer_notes) | ||
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestUpdateNote(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "PATCH" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/customer_notes/note_00000000-0000-0000-0000-000000000000" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"uuid": "note_00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"type": "note", | ||
"text": "This is a new note", | ||
"author": "John Doe (john@example.com)", | ||
"call_duration": 0, | ||
"created_at": "2015-06-09T19:20:30Z", | ||
"updated_at": "2015-06-09T19:20:30Z" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
|
||
customer_note, err := tested.UpdateNote(&UpdateNote{ | ||
Text: "This is a new note", | ||
}, "note_00000000-0000-0000-0000-000000000000") | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if customer_note.Text != "This is a new note" { | ||
spew.Dump(customer_note) | ||
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestDeleteNote(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "DELETE" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/customer_notes/note_00000000-0000-0000-0000-000000000000" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusNoContent) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
|
||
err := tested.DeleteNote("note_00000000-0000-0000-0000-000000000000") | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.