Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,13 @@ Delete an existing ticket

```
client.ZendeskApi().DeleteTicket(1)
```
```

## Search function available

#### TicketSearch
Return a Search result containing only tickets

```
client.ZendeskApi().TicketSearch("Test")
```
4 changes: 2 additions & 2 deletions adapter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zendesk

import "gopkg.in/resty.v0"
import resty "gopkg.in/resty.v0"

type ZendeskApi interface {
GetById(id int) (interface{}, error)
Expand All @@ -14,4 +14,4 @@ type ZendeskApi interface {
// Parse response
parseSingleObject(response *resty.Response) interface{}
parseMultiObjects(response *resty.Response) []interface{}
}
}
21 changes: 17 additions & 4 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package zendesk
import (
"fmt"
"io/ioutil"
"os"

"gopkg.in/yaml.v2"
"gopkg.in/resty.v0"
resty "gopkg.in/resty.v0"
yaml "gopkg.in/yaml.v2"
)

func FromToken(config ZendeskConfiguration) Client {
Expand All @@ -16,12 +17,24 @@ func FromToken(config ZendeskConfiguration) Client {
restyClient.SetHeader("Content-Type", "application/json")

return Client{
domain: config.Domain,
domain: config.Domain,
apiVersion: config.ApiVersion,
client: restyClient,
client: restyClient,
}
}

func FromEnv() Client {
zendeskConfiguration := ZendeskConfiguration{}
zendeskConfiguration.ApiVersion = os.Getenv("ZENDESK_API_VERSION")
zendeskConfiguration.Domain = os.Getenv("ZENDESK_DOMAIN")
zendeskConfiguration.Email = os.Getenv("ZENDESK_EMAIL")
zendeskConfiguration.Password = os.Getenv("ZENDESK_PASSWORD")
zendeskConfiguration.Token = os.Getenv("ZENDESK_TOKEN")

fmt.Println(zendeskConfiguration)
return FromToken(zendeskConfiguration)
}

func LoadConfiguration(path string) ZendeskConfiguration {
zendeskConfiguration := ZendeskConfiguration{}
zendeskConfigurationFile, err := ioutil.ReadFile(path)
Expand Down
29 changes: 24 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package zendesk

import (
"gopkg.in/resty.v0"
"fmt"
"encoding/json"
"fmt"
"strings"

resty "gopkg.in/resty.v0"
)

type Client struct {
domain string
client *resty.Client
domain string
client *resty.Client
apiVersion string
}

Expand All @@ -20,10 +22,27 @@ func (c Client) Ticket() TicketApiHandler {
return TicketApiHandler{c}
}

func (c Client) Search() SearchApiHandler {
return SearchApiHandler{c}
}

func (c Client) TicketMetric() TicketMetricApiHandler {
return TicketMetricApiHandler{c}
}

func (c Client) SatisfactionRating() SatisfactionRatingApiHandler {
return SatisfactionRatingApiHandler{c}
}

func (c Client) toFullUrl(path string) string {
return fmt.Sprintf("https://%v.zendesk.com/api/%s/%s", c.domain, c.apiVersion, path)
}

func (c Client) toPath(path string) string {
baseURL := fmt.Sprintf("https://%v.zendesk.com/api/%s", c.domain, c.apiVersion)
return strings.Replace(path, baseURL, "", -1)
}

func (c Client) get(path string, params map[string]string) (*resty.Response, error) {
resp, err := c.client.R().SetQueryParams(params).Get(c.toFullUrl(path))

Expand Down Expand Up @@ -60,4 +79,4 @@ func (c Client) delete(path string) (*resty.Response, error) {

func (c Client) parseResponseToInterface(response *resty.Response, v interface{}) {
json.Unmarshal(response.Body(), &v)
}
}
20 changes: 20 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package: github.com/smartfrog-oss/zendesk-go
import:
- package: github.com/golang/protobuf
version: f0a097ddac24fb00e07d2ac17f8671423f3ea47c
subpackages:
- proto
- package: github.com/ttacon/builder
version: 7f152c3cf4714fd6318739f8f3dbcd14c2a18b39
- package: github.com/ttacon/libphonenumber
version: 1197dfb91fa03c779576ad248ad5ca0a43fb3a31
- package: golang.org/x/net
version: 4876518f9e71663000c348837735820161a42df7
subpackages:
- publicsuffix
- package: gopkg.in/resty.v0
version: ~0.6.0
- package: gopkg.in/yaml.v2
version: a83829b6f1293c91addabc89d0571c246397bbf4
39 changes: 39 additions & 0 deletions satisfaction_ratings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package zendesk

import (
"fmt"
"time"

resty "gopkg.in/resty.v0"
)

type SatisfactionRatingApiHandler struct {
client Client
}

func (s SatisfactionRatingApiHandler) SatisfactionRatings(score string, startDate *time.Time, stopDate *time.Time) (SatisfactionRatings, error) {
urlString := fmt.Sprintf("/satisfaction_ratings.json?start_time=%d&end_time=%d", startDate.Unix(), stopDate.Unix())

if len(score) > 0 {
urlString = fmt.Sprintf(urlString+"&score=%s", score)
}

response, err := s.client.get(
urlString,
nil,
)

if err != nil {

}

return s.parseResults(response), err
}

func (s SatisfactionRatingApiHandler) parseResults(response *resty.Response) SatisfactionRatings {
var object SatisfactionRatings

s.client.parseResponseToInterface(response, &object)

return object
}
22 changes: 22 additions & 0 deletions satisfaction_ratings_struct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package zendesk

import "time"

type SatisfactionRatings struct {
Count int `json:"count,omitempty"`
NextPage string `json:"next_page,omitempty"`
PrevPage string `json:"prev_page,omitempty"`
SatisfactionRatings []SatisfactionRating `json:"satisfaction_ratings,omitempty"`
}

type SatisfactionRating struct {
Id int `json:"id,omitempty"`
Url string `json:"url,omitempty"`
AssigneeId int `json:"assignee_id,omitempty"`
GroupId int `json:"group_id,omitempty"`
RequesterId int `json:"requester_id,omitempty"`
TicketId int `json:"ticket_id,omitempty"`
Score string `json:"score,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
}
68 changes: 68 additions & 0 deletions search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package zendesk

import (
"fmt"

resty "gopkg.in/resty.v0"
)

type SearchApiHandler struct {
client Client
}

func (s SearchApiHandler) SearchTickets(searchString string, sortBy string, sortOrder string) (TicketSearch, error) {
urlString := fmt.Sprintf("/search.json?query=type:ticket %s", searchString)

if len(sortBy) > 0 {
urlString = fmt.Sprintf(urlString+"&sort_by=%s", sortBy)
}

if len(sortBy) > 0 {
urlString = fmt.Sprintf(urlString+"&sort_order=%s", sortOrder)
}

response, err := s.client.get(
urlString,
nil,
)

if err != nil {

}

return s.parseResults(response), err
}

func (s SearchApiHandler) NextPage(t TicketSearch) (TicketSearch, error) {
response, err := s.client.get(
s.client.toPath(t.NextPage),
nil,
)

if err != nil {
return TicketSearch{}, err
}

return s.parseResults(response), err
}

func (s SearchApiHandler) PrevPage(t TicketSearch) (TicketSearch, error) {
response, err := s.client.get(
s.client.toPath(t.PrevPage),
nil,
)

if err != nil {
return TicketSearch{}, err
}

return s.parseResults(response), err
}

func (s SearchApiHandler) parseResults(response *resty.Response) TicketSearch {
var object TicketSearch

s.client.parseResponseToInterface(response, &object)

return object
}
8 changes: 8 additions & 0 deletions search_struct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package zendesk

type TicketSearch struct {
Count int `json:"count,omitempty"`
NextPage string `json:"next_page,omitempty"`
PrevPage string `json:"prev_page,omitempty"`
Tickets []Ticket `json:"results,omitempty"`
}
Loading