@@ -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
0 commit comments