Skip to content

Commit

Permalink
Merge pull request #209 from grnhse/add-memberships-and-views
Browse files Browse the repository at this point in the history
Add some support for group memberships, views and get many users
  • Loading branch information
nukosuke authored Oct 29, 2021
2 parents 2b9ff6d + cb1d815 commit 8e1d1a9
Show file tree
Hide file tree
Showing 13 changed files with 747 additions and 10 deletions.
25 changes: 25 additions & 0 deletions fixture/GET/group_memberships.json
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
}
8 changes: 8 additions & 0 deletions fixture/GET/user_related.json
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
}
}
91 changes: 91 additions & 0 deletions fixture/GET/view.json
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}}"
}
}
185 changes: 185 additions & 0 deletions fixture/GET/views.json
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
}
2 changes: 2 additions & 0 deletions zendesk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type API interface {
BrandAPI
DynamicContentAPI
GroupAPI
GroupMembershipAPI
LocaleAPI
MacroAPI
TicketAPI
Expand All @@ -25,6 +26,7 @@ type API interface {
TagAPI
TicketAuditAPI
TicketCommentAPI
ViewAPI
}

var _ API = (*Client)(nil)
65 changes: 65 additions & 0 deletions zendesk/group_membership.go
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
}
Loading

0 comments on commit 8e1d1a9

Please sign in to comment.