1 Star 0 Fork 0

mamh-mixed/go-jira2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
customer.go 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
package jira
import (
"context"
"net/http"
)
// CustomerService handles ServiceDesk customers for the Jira instance / API.
type CustomerService struct {
client *Client
}
// Customer represents a ServiceDesk customer.
type Customer struct {
AccountID string `json:"accountId,omitempty" structs:"accountId,omitempty"`
Name string `json:"name,omitempty" structs:"name,omitempty"`
Key string `json:"key,omitempty" structs:"key,omitempty"`
EmailAddress string `json:"emailAddress,omitempty" structs:"emailAddress,omitempty"`
DisplayName string `json:"displayName,omitempty" structs:"displayName,omitempty"`
Active *bool `json:"active,omitempty" structs:"active,omitempty"`
TimeZone string `json:"timeZone,omitempty" structs:"timeZone,omitempty"`
Links *SelfLink `json:"_links,omitempty" structs:"_links,omitempty"`
}
// CustomerListOptions is the query options for listing customers.
type CustomerListOptions struct {
Query string `url:"query,omitempty"`
Start int `url:"start,omitempty"`
Limit int `url:"limit,omitempty"`
}
// CustomerList is a page of customers.
type CustomerList struct {
Values []Customer `json:"values,omitempty" structs:"values,omitempty"`
Start int `json:"start,omitempty" structs:"start,omitempty"`
Limit int `json:"limit,omitempty" structs:"limit,omitempty"`
IsLast bool `json:"isLastPage,omitempty" structs:"isLastPage,omitempty"`
Expands []string `json:"_expands,omitempty" structs:"_expands,omitempty"`
}
// CreateWithContext creates a ServiceDesk customer.
//
// https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-customer/#api-rest-servicedeskapi-customer-post
func (c *CustomerService) CreateWithContext(ctx context.Context, email, displayName string) (*Customer, *Response, error) {
const apiEndpoint = "rest/servicedeskapi/customer"
payload := struct {
Email string `json:"email"`
DisplayName string `json:"displayName"`
}{
Email: email,
DisplayName: displayName,
}
req, err := c.client.NewRequestWithContext(ctx, http.MethodPost, apiEndpoint, payload)
if err != nil {
return nil, nil, err
}
responseCustomer := new(Customer)
resp, err := c.client.Do(req, responseCustomer)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return responseCustomer, resp, nil
}
// Create wraps CreateWithContext using the background context.
func (c *CustomerService) Create(email, displayName string) (*Customer, *Response, error) {
return c.CreateWithContext(context.Background(), email, displayName)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/go-jira2.git
git@gitee.com:mamh-mixed/go-jira2.git
mamh-mixed
go-jira2
go-jira2
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385