diff --git a/README.md b/README.md index 144a676..cb7b947 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,20 @@ if err != nil { } ``` +### Get a contact by id + +Damit man einen speziellen Kontakt auslesen kann, wird die ID benötigt. Diese erhalten Sie mit der Funktion goplacetel.Contacts(). + +```go +// Get a contact by id +contact, err := Contact("id", "token") +if err != nil { + fmt.Println(err) +} else { + fmt.Println(contact) +} +``` + ### Add a contact If a new contact is to be created, then this can be done as follows. The field: id (it is the first field) can be ignored. diff --git a/contacts.go b/contacts.go index ec3d8cb..90754de 100644 --- a/contacts.go +++ b/contacts.go @@ -151,6 +151,34 @@ func Contacts(token string) (*[]ContactReturn, error) { } +// Contact is to get a contact by id +func Contact(id string, token string) (*ContactReturn, error) { + + // Set config for new request + r := Request{"/contacts/" + id, "GET", token, nil} + + // Send new request + response, err := r.Send() + if err != nil { + return nil, err + } + + // Close response body after function ends + defer response.Body.Close() + + // Decode data + var decode ContactReturn + + err = json.NewDecoder(response.Body).Decode(&decode) + if err != nil { + return nil, err + } + + // Return data + return &decode, nil + +} + // AddContact is to add a new contact func AddContact(body *ContactBody, token string) (*ContactReturn, error) {