This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ticket Search support and fix Ticket unmarshaling
- Loading branch information
1 parent
717dd54
commit dabcfd4
Showing
6 changed files
with
115 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package zendesk | ||
|
||
import ( | ||
"fmt" | ||
|
||
resty "gopkg.in/resty.v0" | ||
) | ||
|
||
type SearchApiHandler struct { | ||
client Client | ||
} | ||
|
||
func (s SearchApiHandler) SearchTickets(searchString string) (TicketSearch, error) { | ||
response, err := s.client.get( | ||
fmt.Sprintf("/search.json?query=type:ticket %s", searchString), | ||
nil, | ||
) | ||
|
||
if err != nil { | ||
|
||
} | ||
|
||
return s.parseResults(response), err | ||
} | ||
|
||
func (s SearchApiHandler) parseResults(response *resty.Response) TicketSearch { | ||
var object TicketSearch | ||
|
||
s.client.parseResponseToInterface(response, &object) | ||
|
||
return object | ||
} |
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,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"` | ||
} |
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 |
---|---|---|
|
@@ -2,12 +2,13 @@ package test | |
|
||
import ( | ||
"testing" | ||
"github.com/hellofresh/zendesk-go" | ||
|
||
zendesk "github.com/hellofresh/zendesk-go" | ||
) | ||
|
||
var client = zendesk.FromToken( | ||
zendesk.LoadConfiguration("./../config/configuration.yml"), | ||
); | ||
) | ||
|
||
var id int | ||
|
||
|
@@ -38,7 +39,7 @@ func TestUserApiHandler_GetById(t *testing.T) { | |
|
||
func TestUserApiHandler_Create(t *testing.T) { | ||
user := zendesk.User{ | ||
Name: "Felipe Pieretti Umpierre", | ||
Name: "Felipe Pieretti Umpierre", | ||
Email: "[email protected]", | ||
} | ||
|
||
|
@@ -52,7 +53,7 @@ func TestUserApiHandler_Create(t *testing.T) { | |
|
||
func TestUserApiHandler_CreateOrUpdate(t *testing.T) { | ||
user := zendesk.User{ | ||
Name: "Felipe Pieretti Umpierre = Updated", | ||
Name: "Felipe Pieretti Umpierre = Updated", | ||
Email: "[email protected]", | ||
} | ||
|
||
|
@@ -68,12 +69,12 @@ func TestUserApiHandler_CreateOrUpdateMany(t *testing.T) { | |
var many zendesk.ManyUsers | ||
|
||
many.AppendUsers(zendesk.User{ | ||
Name: "User 1", | ||
Name: "User 1", | ||
Email: "[email protected]", | ||
}) | ||
|
||
many.AppendUsers(zendesk.User{ | ||
Name: "User-2", | ||
Name: "User-2", | ||
Email: "[email protected]", | ||
}) | ||
|
||
|
@@ -96,8 +97,8 @@ func TestUserApiHandler_Delete(t *testing.T) { | |
|
||
func TestUserApiHandler_Update(t *testing.T) { | ||
user := zendesk.User{ | ||
Id: id, | ||
Name: "Felipe Pieretti Umpierre - hallo", | ||
Id: id, | ||
Name: "Felipe Pieretti Umpierre - hallo", | ||
Email: "[email protected]", | ||
} | ||
|
||
|
@@ -109,6 +110,22 @@ func TestUserApiHandler_Update(t *testing.T) { | |
} | ||
} | ||
|
||
// --------- SEARCH -------- | ||
|
||
func TestSearchApiHandler_Search(t *testing.T) { | ||
tickets, err := client.Search().SearchTickets("TEST") | ||
|
||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
t.Fail() | ||
} | ||
|
||
for _, ticket := range tickets.Tickets { | ||
id = ticket.Id | ||
break | ||
} | ||
} | ||
|
||
// --------- TICKET -------- | ||
|
||
func TestTicketApiHandler_GetAll(t *testing.T) { | ||
|
@@ -171,7 +188,7 @@ func TestTicketApiHandler_Delete(t *testing.T) { | |
|
||
func TestTicketApiHandler_Update(t *testing.T) { | ||
ticket := zendesk.Ticket{ | ||
Id: id, | ||
Id: id, | ||
Description: "Test ticket", | ||
} | ||
|
||
|
@@ -181,4 +198,4 @@ func TestTicketApiHandler_Update(t *testing.T) { | |
t.Errorf("Error: %s", err) | ||
t.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
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