Skip to content

Commit 4a3e7e9

Browse files
committed
Optimize Ruby SDK
1 parent 489ca80 commit 4a3e7e9

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

lib/aspose_diagram_cloud/api/diagram_file_api.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ class DiagramFileApi
1818

1919
def initialize(api_client = ApiClient.default)
2020
@api_client = api_client
21+
request_token
22+
end
23+
24+
#
25+
# Gets a request token from server
26+
#
27+
def request_token
28+
config = @api_client.config
29+
base_path = config.base_path
30+
config.base_path = '/'
31+
request_url = "/oauth2/token"
32+
post_data = "grant_type=client_credentials" + "&client_id=" + config.api_key['app_sid'] + "&client_secret=" + config.api_key['api_key']
33+
data, status_code, header = @api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
34+
@api_client.config.access_token = data[:access_token]
35+
@api_client.config.base_path = base_path
36+
@api_client.default_headers["Authorization"] ="Bearer " + data[:access_token]
2137
end
2238

2339
# Read document info or export.
@@ -30,6 +46,7 @@ def initialize(api_client = ApiClient.default)
3046
# @return [File]
3147
def diagram_file_get_diagram(name, opts = {})
3248
data, _status_code, _headers = diagram_file_get_diagram_with_http_info(name, opts)
49+
request_token if _status_code == 401
3350
return data
3451
end
3552

@@ -96,6 +113,7 @@ def diagram_file_get_diagram_with_http_info(name, opts = {})
96113
# @return [SaveResponse]
97114
def diagram_file_post_save_as(name, opts = {})
98115
data, _status_code, _headers = diagram_file_post_save_as_with_http_info(name, opts)
116+
request_token if _status_code == 401
99117
return data
100118
end
101119

@@ -163,6 +181,7 @@ def diagram_file_post_save_as_with_http_info(name, opts = {})
163181
# @return [SaaSposeResponse]
164182
def diagram_file_put_create(name, opts = {})
165183
data, _status_code, _headers = diagram_file_put_create_with_http_info(name, opts)
184+
request_token if _status_code == 401
166185
return data
167186
end
168187

@@ -227,6 +246,7 @@ def diagram_file_put_create_with_http_info(name, opts = {})
227246
# @return [SaaSposeResponse]
228247
def diagram_file_put_upload(name, opts = {})
229248
data, _status_code, _headers = diagram_file_put_upload_with_http_info(name, opts)
249+
request_token if _status_code == 401
230250
return data
231251
end
232252

lib/aspose_diagram_cloud/api_client.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def self.default
4949
def call_api(http_method, path, opts = {})
5050
request = build_request(http_method, path, opts)
5151
response = request.run
52-
5352
if @config.debugging
5453
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
5554
end

lib/aspose_diagram_cloud/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module AsposeDiagramCloud
14-
VERSION = "18.10.2"
14+
VERSION = "18.10.3"
1515
end

spec/api/diagram_file_api_spec.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,10 @@
1919
describe 'DiagramFileApi' do
2020
before do
2121
# run before each test
22-
# run before each test
23-
if $access_token == nil then
24-
conf = AsposeDiagramCloud::Configuration.new
25-
conf.base_path = ""
26-
instance = AsposeDiagramCloud::OAuthApi.new(AsposeDiagramCloud::ApiClient.new(conf))
27-
$access_token = instance.o_auth_post($grant_type,$client_id,$client_secret).access_token
28-
end
29-
30-
conf = AsposeDiagramCloud::Configuration.new
31-
conf.access_token = $access_token
32-
client = AsposeDiagramCloud::ApiClient.new(conf)
33-
client.default_headers["Authorization"] ="Bearer " + $access_token
22+
conf = AsposeDiagramCloud::Configuration.new
23+
conf.api_key['app_sid'] = $client_id
24+
conf.api_key['api_key'] = $client_secret
25+
client = AsposeDiagramCloud::ApiClient.new(conf)
3426
@instance = AsposeDiagramCloud::DiagramFileApi.new(client)
3527
end
3628

0 commit comments

Comments
 (0)