-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from grnhse/add-memberships-and-views
Add some support for group memberships, views and get many users
- Loading branch information
Showing
13 changed files
with
747 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"group_memberships": [ | ||
{ | ||
"url": "https://terraform-provider-zendesk.zendesk.com/api/v2/group_memberships/360002440594.json", | ||
"id": 360002440594, | ||
"user_id": 15439980, | ||
"group_id": 98907558, | ||
"default": false, | ||
"created_at": "2018-11-23T16:05:12Z", | ||
"updated_at": "2018-11-23T16:05:15Z" | ||
}, | ||
{ | ||
"url": "https://terraform-provider-zendesk.zendesk.com/api/v2/group_memberships/360002440595.json", | ||
"id": 360002440595, | ||
"user_id": 15439981, | ||
"group_id": 98907557, | ||
"default": false, | ||
"created_at": "2018-11-23T16:05:12Z", | ||
"updated_at": "2018-11-23T16:05:15Z" | ||
} | ||
], | ||
"next_page": null, | ||
"previous_page": null, | ||
"count": 1 | ||
} |
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 @@ | ||
{ | ||
"user_related": { | ||
"assigned_tickets": 5, | ||
"ccd_tickets": 3, | ||
"organization_subscriptions": 1, | ||
"requested_tickets": 10 | ||
} | ||
} |
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,91 @@ | ||
{ | ||
"view": { | ||
"url": "https://terraform-provider-zendesk.zendesk.com/api/v2/views/360002440594.json", | ||
"id": 360002440594, | ||
"title": "Wonderful tickets", | ||
"active": true, | ||
"created_at": "2018-11-23T16:05:12Z", | ||
"updated_at": "2018-11-23T16:05:15Z", | ||
"position": 0, | ||
"description": "This is a wonderful view of your tickets", | ||
"execution": { | ||
"group_by": "status", | ||
"group_order": "asc", | ||
"sort_by": "nice_id", | ||
"sort_order": "desc", | ||
"group": { | ||
"id": "status", | ||
"title": "Status", | ||
"order": "asc" | ||
}, | ||
"sort": { | ||
"id": "ticket_id", | ||
"title": "ID", | ||
"order": "desc" | ||
}, | ||
"columns": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"fields": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"custom_fields": [] | ||
}, | ||
"conditions": { | ||
"all": [ | ||
{ | ||
"field": "status", | ||
"operator": "less_than", | ||
"value": "solved" | ||
}, | ||
{ | ||
"field": "assignee_id", | ||
"operator": "is", | ||
"value": "current_user" | ||
} | ||
], | ||
"any": [] | ||
}, | ||
"restriction": null, | ||
"watchable": true, | ||
"raw_title": "{{zd.your_wonderful_tickets}}" | ||
} | ||
} |
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,185 @@ | ||
{ | ||
"views": [ | ||
{ | ||
"url": "https://terraform-provider-zendesk.zendesk.com/api/v2/views/360002440595.json", | ||
"id": 360002440595, | ||
"title": "Wonderful tickets", | ||
"active": true, | ||
"created_at": "2018-11-23T16:05:12Z", | ||
"updated_at": "2018-11-23T16:05:15Z", | ||
"position": 0, | ||
"description": "This is a wonderful view of your tickets", | ||
"execution": { | ||
"group_by": "status", | ||
"group_order": "asc", | ||
"sort_by": "nice_id", | ||
"sort_order": "desc", | ||
"group": { | ||
"id": "status", | ||
"title": "Status", | ||
"order": "asc" | ||
}, | ||
"sort": { | ||
"id": "ticket_id", | ||
"title": "ID", | ||
"order": "desc" | ||
}, | ||
"columns": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"fields": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"custom_fields": [] | ||
}, | ||
"conditions": { | ||
"all": [ | ||
{ | ||
"field": "status", | ||
"operator": "less_than", | ||
"value": "solved" | ||
}, | ||
{ | ||
"field": "assignee_id", | ||
"operator": "is", | ||
"value": "current_user" | ||
} | ||
], | ||
"any": [] | ||
}, | ||
"restriction": null, | ||
"watchable": true, | ||
"raw_title": "{{zd.your_wonderful_tickets}}" | ||
}, | ||
{ | ||
"url": "https://terraform-provider-zendesk.zendesk.com/api/v2/views/360002440594.json", | ||
"id": 360002440594, | ||
"title": "OK tickets", | ||
"active": true, | ||
"created_at": "2018-11-23T16:05:12Z", | ||
"updated_at": "2018-11-23T16:05:15Z", | ||
"position": 0, | ||
"description": "This is an ok view of your tickets", | ||
"execution": { | ||
"group_by": "status", | ||
"group_order": "asc", | ||
"sort_by": "nice_id", | ||
"sort_order": "desc", | ||
"group": { | ||
"id": "status", | ||
"title": "Status", | ||
"order": "asc" | ||
}, | ||
"sort": { | ||
"id": "ticket_id", | ||
"title": "ID", | ||
"order": "desc" | ||
}, | ||
"columns": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"fields": [ | ||
{ | ||
"id": "subject", | ||
"title": "Subject" | ||
}, | ||
{ | ||
"id": "requester", | ||
"title": "Requester" | ||
}, | ||
{ | ||
"id": "created", | ||
"title": "Requested" | ||
}, | ||
{ | ||
"id": "type", | ||
"title": "Type" | ||
}, | ||
{ | ||
"id": "priority", | ||
"title": "Priority" | ||
} | ||
], | ||
"custom_fields": [] | ||
}, | ||
"conditions": { | ||
"all": [ | ||
{ | ||
"field": "status", | ||
"operator": "less_than", | ||
"value": "solved" | ||
}, | ||
{ | ||
"field": "assignee_id", | ||
"operator": "is", | ||
"value": "current_user" | ||
} | ||
], | ||
"any": [] | ||
}, | ||
"restriction": null, | ||
"watchable": true, | ||
"raw_title": "{{zd.your_ok_tickets}}" | ||
} | ||
], | ||
"next_page": null, | ||
"previous_page": null, | ||
"count": 2 | ||
} |
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,65 @@ | ||
package zendesk | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
type ( | ||
// GroupMembership is struct for group membership payload | ||
// https://developer.zendesk.com/api-reference/ticketing/groups/group_memberships/ | ||
GroupMembership struct { | ||
ID int64 `json:"id,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
UserID int64 `json:"user_id"` | ||
GroupID int64 `json:"group_id"` | ||
Default bool `json:"default"` | ||
Name string `json:"name"` | ||
CreatedAt time.Time `json:"created_at,omitempty"` | ||
UpdatedAt time.Time `json:"updated_at,omitempty"` | ||
} | ||
|
||
// GroupMembershipListOptions is a struct for options for group membership list | ||
// ref: https://developer.zendesk.com/api-reference/ticketing/groups/group_memberships/ | ||
GroupMembershipListOptions struct { | ||
PageOptions | ||
GroupID int64 `json:"group_id,omitempty" url:"group_id,omitempty"` | ||
UserID int64 `json:"user_id,omitempty" url:"user_id,omitempty"` | ||
} | ||
|
||
// GroupMembershipAPI is an interface containing group membership related methods | ||
GroupMembershipAPI interface { | ||
GetGroupMemberships(context.Context, *GroupMembershipListOptions) ([]GroupMembership, Page, error) | ||
} | ||
) | ||
|
||
// GetGroupMemberships gets the memberships of the specified group | ||
// ref: https://developer.zendesk.com/api-reference/ticketing/groups/group_memberships/ | ||
func (z *Client) GetGroupMemberships(ctx context.Context, opts *GroupMembershipListOptions) ([]GroupMembership, Page, error) { | ||
var result struct { | ||
GroupMemberships []GroupMembership `json:"group_memberships"` | ||
Page | ||
} | ||
|
||
tmp := opts | ||
if tmp == nil { | ||
tmp = new(GroupMembershipListOptions) | ||
} | ||
|
||
u, err := addOptions("/group_memberships.json", tmp) | ||
if err != nil { | ||
return nil, Page{}, err | ||
} | ||
|
||
body, err := z.get(ctx, u) | ||
if err != nil { | ||
return nil, Page{}, err | ||
} | ||
|
||
if err := json.Unmarshal(body, &result); err != nil { | ||
return nil, Page{}, err | ||
} | ||
|
||
return result.GroupMemberships, result.Page, nil | ||
} |
Oops, something went wrong.