Skip to content

Commit 1021719

Browse files
authored
Merge pull request #36 from aspose-pdf-cloud/develop
update to 22.8.0
2 parents 438a3cf + 1020a25 commit 1021719

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ These SDKs are now fully supported. If you have any questions, see any bugs or h
99

1010
Extract Text & Images of a PDF document online https://products.aspose.app/pdf/parser.
1111

12-
## Enhancements in Version 22.7
12+
## Enhancements in Version 22.8
1313
- A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET.
1414

15-
## Bugs fixed in Version 22.7
16-
- Text Replace API method changes background of the elements.
17-
1815
## Installation
1916
```
2017
go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v22

api_client.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (c *APIClient) prepareRequest (
176176

177177
// set custom header
178178
headerParams["x-aspose-client"] = "go sdk"
179-
headerParams["x-aspose-client-version"] = "22.7.0"
179+
headerParams["x-aspose-client-version"] = "22.8.0"
180180

181181
// Detect postBody type and post.
182182
if postBody != nil {
@@ -420,24 +420,30 @@ func (a *APIClient) addAuth(request *http.Request) (err error) {
420420
}
421421

422422
// RequestOauthToken function for requests OAuth token
423-
func (a *APIClient) RequestOauthToken() (error) {
424-
425-
resp, err := http.PostForm(strings.Replace(a.cfg.BasePath, "/v3.0", "/connect/token", -1), url.Values{
426-
"grant_type": {"client_credentials"},
427-
"client_id": {a.cfg.AppSid},
428-
"client_secret": {a.cfg.AppKey}})
429-
430-
if err != nil {
431-
return err
432-
}
433-
defer resp.Body.Close()
434-
435-
var tr TokenResp
436-
if err = json.NewDecoder(resp.Body).Decode(&tr); err != nil {
437-
return err
438-
}
439-
a.cfg.AccessToken = tr.AccessToken
440-
return nil
423+
func (a *APIClient) RequestOauthToken() error {
424+
resp, err := http.PostForm(
425+
strings.Replace(a.cfg.BasePath, "/v3.0", "/connect/token", -1),
426+
// a.cfg.BasePath+"/pdf/connect/token",
427+
url.Values{
428+
"grant_type": {"client_credentials"},
429+
"client_id": {a.cfg.AppSid},
430+
"client_secret": {a.cfg.AppKey},
431+
},
432+
)
433+
if err != nil {
434+
return err
435+
}
436+
defer resp.Body.Close()
437+
bodyBytes, _ := io.ReadAll(resp.Body)
438+
var tr TokenResp
439+
if err = json.NewDecoder(bytes.NewReader(bodyBytes)).Decode(&tr); err != nil {
440+
return fmt.Errorf("%s (wrapped error: %w)", bodyBytes, err)
441+
}
442+
if len(tr.AccessToken) == 0 {
443+
return fmt.Errorf("empty token (%s)", bodyBytes)
444+
}
445+
a.cfg.AccessToken = tr.AccessToken
446+
return nil
441447
}
442448

443449
func deserializeDTO(readCloser io.Reader, successPayload interface{}) error {

base_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ func getServercredsJson() string {
7070
}
7171

7272
type Creds struct {
73-
AppSID string
74-
AppKey string
73+
AppSID string `json:"AppSID"`
74+
AppKey string `json:"AppKey"`
75+
ProductUri string `json:"ProductUri"`
7576
}
7677

77-
func getCreds() (appSID, appKey string) {
78+
func getCreds() Creds {
7879
bbCreds, err := os.ReadFile(getServercredsJson())
7980
if err != nil {
8081
panic(err)
@@ -89,17 +90,19 @@ func getCreds() (appSID, appKey string) {
8990
if len(creds.AppKey) == 0 {
9091
panic("no AppKey")
9192
}
92-
return creds.AppSID, creds.AppKey
93+
if len(creds.ProductUri) == 0 {
94+
panic("no ProductUri")
95+
}
96+
return creds
9397
}
9498

9599
func NewBaseTest() *BaseTest {
96-
appSID, appKey := getCreds()
100+
creds := getCreds()
97101
bt := BaseTest{
98102
remoteFolder: "TempPdfCloud",
99103
localTestDataFolder: "test_data",
100104
TestNumber: 0,
101-
// Get App key and App SID from https://aspose.cloud
102-
PdfAPI: NewPdfApiService(appSID, appKey, "https://api.aspose.cloud/v3.0"),
105+
PdfAPI: NewPdfApiService(creds.AppSID, creds.AppKey, creds.ProductUri),
103106
}
104107
return &bt
105108
}

0 commit comments

Comments
 (0)