From 6a52f3b128b95ffee569f9d04ac1da19e8cf56c3 Mon Sep 17 00:00:00 2001 From: freesky-edward Date: Mon, 13 Jan 2020 21:07:12 +0800 Subject: [PATCH] Add gitee email api support --- api/swagger.yaml | 50 +++++++++++++++++ docs/Email.md | 12 +++++ docs/EmailsApi.md | 44 +++++++++++++++ gitee/api_emails.go | 123 ++++++++++++++++++++++++++++++++++++++++++ gitee/api_webhooks.go | 12 ++--- gitee/client.go | 3 ++ gitee/model_email.go | 17 ++++++ 7 files changed, 254 insertions(+), 7 deletions(-) create mode 100644 docs/Email.md create mode 100644 docs/EmailsApi.md create mode 100644 gitee/api_emails.go create mode 100644 gitee/model_email.go diff --git a/api/swagger.yaml b/api/swagger.yaml index a8643e1..e431ce3 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5820,6 +5820,35 @@ paths: description: "执行成功" 403: description: "没有权限" + /v5/emails: + get: + tags: + - "Emails" + summary: "获取授权用户的所有邮箱" + description: "获取授权用户的所有邮箱" + operationId: "getV5Emails" + consumes: + - "application/json" + - "multipart/form-data" + produces: + - "application/json" + parameters: + - name: "access_token" + in: "query" + description: "用户授权码" + required: false + type: "string" + x-exportParamName: "AccessToken" + x-optionalDataType: "String" + responses: + 200: + description: "返回格式" + schema: + type: "array" + items: + $ref: "#/definitions/Email" + 404: + description: "没有相关数据" /v5/user/keys: get: tags: @@ -13698,6 +13727,27 @@ definitions: site_admin: "site_admin" id: 5 organizations_url: "organizations_url" + Email: + type: "object" + properties: + email: + type: "string" + state: + type: "string" + scope: + type: "array" + items: + type: "string" + description: "获取授权用户的邮件地址" + example: + email: "xxx@xx.com" + state: "confirmed" + scope: + - "primary" + - "secure" + - "notified" + - "commited" + - "public" Milestone: type: "object" properties: diff --git a/docs/Email.md b/docs/Email.md new file mode 100644 index 0000000..2b53e13 --- /dev/null +++ b/docs/Email.md @@ -0,0 +1,12 @@ +# Email + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Email** | **string** | | [optional] [default to null] +**State** | **string** | | [optional] [default to null] +**Scope** | **[]string** | | [optional] [default to null] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/EmailsApi.md b/docs/EmailsApi.md new file mode 100644 index 0000000..21f482c --- /dev/null +++ b/docs/EmailsApi.md @@ -0,0 +1,44 @@ +# \EmailsApi + +All URIs are relative to *https://gitee.com/api* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**GetV5Emails**](EmailsApi.md#GetV5Emails) | **Get** /v5/emails | 获取授权用户的所有邮箱 + + +# **GetV5Emails** +> []Email GetV5Emails(ctx, optional) +获取授权用户的所有邮箱 + +获取授权用户的所有邮箱 + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. + **optional** | ***GetV5EmailsOpts** | optional parameters | nil if no parameters + +### Optional Parameters +Optional parameters are passed through a pointer to a GetV5EmailsOpts struct + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **accessToken** | **optional.String**| 用户授权码 | + +### Return type + +[**[]Email**](Email.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json, multipart/form-data + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/gitee/api_emails.go b/gitee/api_emails.go new file mode 100644 index 0000000..57500fb --- /dev/null +++ b/gitee/api_emails.go @@ -0,0 +1,123 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +import ( + "context" + "github.com/antihax/optional" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +// Linger please +var ( + _ context.Context +) + +type EmailsApiService service + +/* +EmailsApiService 获取授权用户的所有邮箱 +获取授权用户的所有邮箱 + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param optional nil or *GetV5EmailsOpts - Optional Parameters: + * @param "AccessToken" (optional.String) - 用户授权码 + +@return []Email +*/ + +type GetV5EmailsOpts struct { + AccessToken optional.String +} + +func (a *EmailsApiService) GetV5Emails(ctx context.Context, localVarOptionals *GetV5EmailsOpts) ([]Email, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue []Email + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v5/emails" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if localVarOptionals != nil && localVarOptionals.AccessToken.IsSet() { + localVarQueryParams.Add("access_token", parameterToString(localVarOptionals.AccessToken.Value(), "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + + if localVarHttpResponse.StatusCode == 200 { + var v []Email + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} diff --git a/gitee/api_webhooks.go b/gitee/api_webhooks.go index 7a99f8c..36421c6 100644 --- a/gitee/api_webhooks.go +++ b/gitee/api_webhooks.go @@ -12,13 +12,11 @@ package gitee import ( "context" "fmt" + "github.com/antihax/optional" "io/ioutil" "net/http" "net/url" - neturl "net/url" "strings" - - "github.com/antihax/optional" ) // Linger please @@ -371,8 +369,8 @@ func (a *WebhooksApiService) PatchV5ReposOwnerRepoHooksId(ctx context.Context, o localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1) localVarHeaderParams := make(map[string]string) - localVarQueryParams := neturl.Values{} - localVarFormParams := neturl.Values{} + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} // to determine the Content-Type header localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} @@ -504,8 +502,8 @@ func (a *WebhooksApiService) PostV5ReposOwnerRepoHooks(ctx context.Context, owne localVarPath = strings.Replace(localVarPath, "{"+"repo"+"}", fmt.Sprintf("%v", repo), -1) localVarHeaderParams := make(map[string]string) - localVarQueryParams := neturl.Values{} - localVarFormParams := neturl.Values{} + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} // to determine the Content-Type header localVarHttpContentTypes := []string{"application/json", "multipart/form-data"} diff --git a/gitee/client.go b/gitee/client.go index d6584c9..bf6510c 100644 --- a/gitee/client.go +++ b/gitee/client.go @@ -47,6 +47,8 @@ type APIClient struct { ActivityApi *ActivityApiService + EmailsApi *EmailsApiService + EnterprisesApi *EnterprisesApiService GistsApi *GistsApiService @@ -91,6 +93,7 @@ func NewAPIClient(cfg *Configuration) *APIClient { // API Services c.ActivityApi = (*ActivityApiService)(&c.common) + c.EmailsApi = (*EmailsApiService)(&c.common) c.EnterprisesApi = (*EnterprisesApiService)(&c.common) c.GistsApi = (*GistsApiService)(&c.common) c.GitDataApi = (*GitDataApiService)(&c.common) diff --git a/gitee/model_email.go b/gitee/model_email.go new file mode 100644 index 0000000..40de10d --- /dev/null +++ b/gitee/model_email.go @@ -0,0 +1,17 @@ +/* + * 码云 Open API + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: 5.3.2 + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package gitee + +// 获取授权用户的邮件地址 +type Email struct { + Email string `json:"email,omitempty"` + State string `json:"state,omitempty"` + Scope []string `json:"scope,omitempty"` +} -- GitLab