Skip to content

Commit

Permalink
Improve documentation - MEDIGO#45
Browse files Browse the repository at this point in the history
- Add inline doc about credentials so they appear in godoc
- Replace the doc file by a Example file that should run on godocs (https://blog.golang.org/examples)
  • Loading branch information
Simon Alfassa committed Aug 30, 2017
1 parent 6c50253 commit dae6156
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func main() {
}
```

Find the complete API on https://godoc.org/github.com/MEDIGO/go-zendesk/zendesk#NewClient


## Development

### Linting
Expand All @@ -49,7 +52,7 @@ The project contains integration tests that uses the Zendesk API. To execute the

```
ZENDESK_DOMAIN=<your-zendesk-domain>
ZENDESK_USERNAME=<your-zendesk-api-username>
ZENDESK_USERNAME=<your-zendesk-api-email>
ZENDESK_PASSWORD=<your-zendesk-api-password>
```

Expand Down
24 changes: 0 additions & 24 deletions zendesk/doc.go

This file was deleted.

8 changes: 8 additions & 0 deletions zendesk/zendesk.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package zendesk provides a client for using the Zendesk Core API.

package zendesk

import (
Expand Down Expand Up @@ -63,6 +65,9 @@ type client struct {
}

// NewEnvClient creates a new Client configured via environment variables.
//
// Three environment variables are required: ZENDESK_DOMAIN, ZENDESK_USERNAME and ZENDESK_PASSWORD
// they will provide parameters to the NewClient function
func NewEnvClient(middleware ...MiddlewareFunction) (Client, error) {
domain := os.Getenv("ZENDESK_DOMAIN")
if domain == "" {
Expand All @@ -83,6 +88,9 @@ func NewEnvClient(middleware ...MiddlewareFunction) (Client, error) {
}

// NewClient creates a new Client.
//
// You can use either a user email/password combination or an API token.
// For the latter, append /token to the email and use the API token as a password
func NewClient(domain, username, password string, middleware ...MiddlewareFunction) (Client, error) {
baseURL, err := url.Parse(fmt.Sprintf("https://%s.zendesk.com", domain))
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions zendesk/zendesk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zendesk_test

import (
"log"

"github.com/MEDIGO/go-zendesk/zendesk"
)

func Example() {
client, err := zendesk.NewClient("domain", "username", "password")
if err != nil {
log.Fatal(err)
}
ticket, err := client.ShowTicket(1)
if err != nil {
log.Fatal(err)
}
log.Printf("Requester ID is: %d", *ticket.RequesterID)
}

0 comments on commit dae6156

Please sign in to comment.