Skip to content

Commit

Permalink
Add contact function
Browse files Browse the repository at this point in the history
  • Loading branch information
gowizzard committed Jul 15, 2021
1 parent bfee1f2 commit 8103ba2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit 8103ba2

Please sign in to comment.