Skip to content

Commit 48c5930

Browse files
SDK regenerated by CI server [ci skip]
1 parent 37ebbbc commit 48c5930

File tree

6 files changed

+259
-2
lines changed

6 files changed

+259
-2
lines changed

dev/api/api_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)")
6565
)
6666

67-
// APIClient manages communication with the Aspose.Words for Cloud API Reference API v22.3
67+
// APIClient manages communication with the Aspose.Words for Cloud API Reference API v22.4
6868
// In most cases there should be only one, shared, APIClient.
6969
type APIClient struct {
7070
cfg *models.Configuration

dev/api/models/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func NewConfiguration(configFilePath string) (pConfig *Configuration, err error)
9999
cfg := Configuration{
100100
BaseUrl: "https://api.aspose.cloud",
101101
DebugMode: false,
102-
DefaultHeader: map[string]string{"x-aspose-client": "go sdk", "x-aspose-client-version": "22.3"},
102+
DefaultHeader: map[string]string{"x-aspose-client": "go sdk", "x-aspose-client-version": "22.4"},
103103
}
104104
err = json.Unmarshal(data, &cfg)
105105

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* --------------------------------------------------------------------------------
3+
* <copyright company="Aspose" file="copy_styles_from_template_request.go">
4+
* Copyright (c) 2022 Aspose.Words for Cloud
5+
* </copyright>
6+
* <summary>
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
* </summary>
25+
* --------------------------------------------------------------------------------
26+
*/
27+
28+
package models
29+
30+
import (
31+
"fmt"
32+
"net/url"
33+
"strings"
34+
"io"
35+
"encoding/json"
36+
)
37+
38+
// CopyStylesFromTemplateRequest contains request data for WordsApiService.CopyStylesFromTemplate method.
39+
type CopyStylesFromTemplateRequest struct {
40+
// The filename of the target document.
41+
Name *string
42+
// The filename of the origin document.
43+
TemplateName *string
44+
/* optional (nil or map[string]interface{}) with one or more of key / value pairs:
45+
key: "folder" value: (*string) Original document folder.
46+
key: "storage" value: (*string) Original document storage.
47+
key: "loadEncoding" value: (*string) Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.
48+
key: "password" value: (*string) Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API.
49+
key: "encryptedPassword" value: (*string) Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details.
50+
key: "destFileName" value: (*string) Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.
51+
key: "revisionAuthor" value: (*string) Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.
52+
key: "revisionDateTime" value: (*string) The date and time to use for revisions. */
53+
Optionals map[string]interface{}
54+
}
55+
56+
57+
func (data *CopyStylesFromTemplateRequest) CreateRequestData() (RequestData, error) {
58+
59+
var result RequestData
60+
61+
result.Method = strings.ToUpper("put")
62+
63+
// create path and map variables
64+
result.Path = "/words/{name}/styles/copy_from"
65+
result.Path = strings.Replace(result.Path, "{"+"name"+"}", fmt.Sprintf("%v", *data.Name), -1)
66+
67+
result.Path = strings.Replace(result.Path, "/<nil>", "", -1)
68+
result.Path = strings.Replace(result.Path, "//", "/", -1)
69+
70+
result.HeaderParams = make(map[string]string)
71+
result.QueryParams = url.Values{}
72+
result.FormParams = make([]FormParamContainer, 0)
73+
74+
75+
if err := typeCheckParameter(data.Optionals["folder"], "string", "data.Optionals[folder]"); err != nil {
76+
return result, err
77+
}
78+
if err := typeCheckParameter(data.Optionals["storage"], "string", "data.Optionals[storage]"); err != nil {
79+
return result, err
80+
}
81+
if err := typeCheckParameter(data.Optionals["loadEncoding"], "string", "data.Optionals[loadEncoding]"); err != nil {
82+
return result, err
83+
}
84+
if err := typeCheckParameter(data.Optionals["password"], "string", "data.Optionals[password]"); err != nil {
85+
return result, err
86+
}
87+
if err := typeCheckParameter(data.Optionals["encryptedPassword"], "string", "data.Optionals[encryptedPassword]"); err != nil {
88+
return result, err
89+
}
90+
if err := typeCheckParameter(data.Optionals["destFileName"], "string", "data.Optionals[destFileName]"); err != nil {
91+
return result, err
92+
}
93+
if err := typeCheckParameter(data.Optionals["revisionAuthor"], "string", "data.Optionals[revisionAuthor]"); err != nil {
94+
return result, err
95+
}
96+
if err := typeCheckParameter(data.Optionals["revisionDateTime"], "string", "data.Optionals[revisionDateTime]"); err != nil {
97+
return result, err
98+
}
99+
100+
101+
result.QueryParams.Add("TemplateName", parameterToString(*data.TemplateName, ""))
102+
103+
104+
if localVarTempParam, localVarOk := data.Optionals["folder"].(string); localVarOk {
105+
result.QueryParams.Add("Folder", parameterToString(localVarTempParam, ""))
106+
}
107+
108+
109+
if localVarTempParam, localVarOk := data.Optionals["storage"].(string); localVarOk {
110+
result.QueryParams.Add("Storage", parameterToString(localVarTempParam, ""))
111+
}
112+
113+
114+
if localVarTempParam, localVarOk := data.Optionals["loadEncoding"].(string); localVarOk {
115+
result.QueryParams.Add("LoadEncoding", parameterToString(localVarTempParam, ""))
116+
}
117+
118+
119+
if localVarTempParam, localVarOk := data.Optionals["password"].(string); localVarOk {
120+
result.QueryParams.Add("Password", parameterToString(localVarTempParam, ""))
121+
}
122+
123+
124+
if localVarTempParam, localVarOk := data.Optionals["encryptedPassword"].(string); localVarOk {
125+
result.QueryParams.Add("EncryptedPassword", parameterToString(localVarTempParam, ""))
126+
}
127+
128+
129+
if localVarTempParam, localVarOk := data.Optionals["destFileName"].(string); localVarOk {
130+
result.QueryParams.Add("DestFileName", parameterToString(localVarTempParam, ""))
131+
}
132+
133+
134+
if localVarTempParam, localVarOk := data.Optionals["revisionAuthor"].(string); localVarOk {
135+
result.QueryParams.Add("RevisionAuthor", parameterToString(localVarTempParam, ""))
136+
}
137+
138+
139+
if localVarTempParam, localVarOk := data.Optionals["revisionDateTime"].(string); localVarOk {
140+
result.QueryParams.Add("RevisionDateTime", parameterToString(localVarTempParam, ""))
141+
}
142+
143+
144+
// to determine the Content-Type header
145+
localVarHttpContentTypes := []string{ "application/xml", "application/json", }
146+
147+
// set Content-Type header
148+
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
149+
if localVarHttpContentType != "" {
150+
result.HeaderParams["Content-Type"] = localVarHttpContentType
151+
}
152+
153+
// to determine the Accept header
154+
localVarHttpHeaderAccepts := []string{
155+
"application/xml",
156+
"application/json",
157+
}
158+
159+
// set Accept header
160+
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
161+
if localVarHttpHeaderAccept != "" {
162+
result.HeaderParams["Accept"] = localVarHttpHeaderAccept
163+
}
164+
165+
166+
167+
168+
return result, nil
169+
}
170+
171+
func (data *CopyStylesFromTemplateRequest) CreateResponse(reader io.Reader, boundary string) (response interface{}, err error) {
172+
var successPayload WordsResponse
173+
if err = json.NewDecoder(reader).Decode(&successPayload); err != nil {
174+
return nil, err
175+
}
176+
177+
return successPayload, err
178+
}

dev/api/words_api.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,54 @@ func (a *WordsApiService) CopyStyleOnline(ctx context.Context, data *models.Copy
902902
return result.(models.CopyStyleOnlineResponse), response, err
903903
}
904904

905+
/* WordsApiService Copies styles from the origin document to the target document.
906+
* @param ctx context.Context for authentication, logging, tracing, etc.
907+
* @data operation request data.
908+
@return models.WordsResponse*/
909+
func (a *WordsApiService) CopyStylesFromTemplate(ctx context.Context, data *models.CopyStylesFromTemplateRequest) (models.WordsResponse, *http.Response, error) {
910+
var (
911+
successPayload models.WordsResponse
912+
)
913+
914+
requestData, err := data.CreateRequestData();
915+
if err != nil {
916+
return successPayload, nil, err
917+
}
918+
919+
requestData.Path = a.client.cfg.BaseUrl + requestData.Path;
920+
921+
r, err := a.client.prepareRequest(ctx, requestData)
922+
if err != nil {
923+
return successPayload, nil, err
924+
}
925+
926+
response, err := a.client.callAPI(r)
927+
928+
if err != nil || response == nil {
929+
return successPayload, nil, err
930+
}
931+
932+
defer response.Body.Close()
933+
934+
if response.StatusCode == 401 {
935+
return successPayload, nil, errors.New("Access is denied")
936+
}
937+
if response.StatusCode >= 300 {
938+
var apiError models.WordsApiErrorResponse;
939+
940+
if err = json.NewDecoder(response.Body).Decode(&apiError); err != nil {
941+
return successPayload, nil, err
942+
}
943+
944+
return successPayload, response, &apiError
945+
}
946+
if err = json.NewDecoder(response.Body).Decode(&successPayload); err != nil {
947+
return successPayload, response, err
948+
}
949+
950+
return successPayload, response, err
951+
}
952+
905953
/* WordsApiService Supported extensions: ".doc", ".docx", ".docm", ".dot", ".dotm", ".dotx", ".flatopc", ".fopc", ".flatopc_macro", ".fopc_macro", ".flatopc_template", ".fopc_template", ".flatopc_template_macro", ".fopc_template_macro", ".wordml", ".wml", ".rtf".
906954
* @param ctx context.Context for authentication, logging, tracing, etc.
907955
* @data operation request data.

dev/tests/styles_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,34 @@ func Test_Styles_ApplyStyleToDocumentElementOnline(t *testing.T) {
438438
}
439439

440440
}
441+
442+
// Test for copying styles from a template.
443+
func Test_Styles_CopyStylesFromTemplate(t *testing.T) {
444+
config := ReadConfiguration(t)
445+
client, ctx := PrepareTest(t, config)
446+
remoteDataFolder := remoteBaseTestDataFolder + "/DocumentElements/Styles"
447+
localFile := "DocumentElements/Styles/GetStyles.docx"
448+
remoteFileName := "TestCopyStylesFromTemplate.docx"
449+
templateFolder := "DocumentElements/Styles"
450+
templateName := "StyleTemplate.docx"
451+
452+
UploadNextFileToStorage(t, ctx, client, GetLocalFile(localFile), remoteDataFolder + "/" + remoteFileName)
453+
UploadNextFileToStorage(t, ctx, client, GetLocalFile(templateFolder + "/" + templateName), remoteDataFolder + "/" + templateName)
454+
455+
456+
options := map[string]interface{}{
457+
"folder": remoteDataFolder,
458+
}
459+
460+
request := &models.CopyStylesFromTemplateRequest{
461+
Name: ToStringPointer(remoteFileName),
462+
TemplateName: ToStringPointer(templateName),
463+
Optionals: options,
464+
}
465+
466+
_, _, err := client.WordsApi.CopyStylesFromTemplate(ctx, request)
467+
if err != nil {
468+
t.Error(err)
469+
}
470+
471+
}
Binary file not shown.

0 commit comments

Comments
 (0)