groupdocs_platform_cloud 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +160 -0
  4. data/Ruby Mustache Templates/ReadMe.txt +1 -0
  5. data/Ruby Mustache Templates/api_client.mustache +441 -0
  6. data/Swagger Specs File/platform.json +1683 -0
  7. data/groupdocs_platform_cloud.gemspec +26 -0
  8. data/lib/groupdocs_platform_cloud.rb +72 -0
  9. data/lib/groupdocs_platform_cloud/api/app_api.rb +359 -0
  10. data/lib/groupdocs_platform_cloud/api/app_statistics_api.rb +572 -0
  11. data/lib/groupdocs_platform_cloud/api/auth_api.rb +176 -0
  12. data/lib/groupdocs_platform_cloud/api/file_api.rb +282 -0
  13. data/lib/groupdocs_platform_cloud/api/folder_api.rb +267 -0
  14. data/lib/groupdocs_platform_cloud/api/heroku_api.rb +241 -0
  15. data/lib/groupdocs_platform_cloud/api/storage_api.rb +249 -0
  16. data/lib/groupdocs_platform_cloud/api/usage_api.rb +233 -0
  17. data/lib/groupdocs_platform_cloud/api_client.rb +446 -0
  18. data/lib/groupdocs_platform_cloud/api_error.rb +38 -0
  19. data/lib/groupdocs_platform_cloud/configuration.rb +216 -0
  20. data/lib/groupdocs_platform_cloud/groupdocs_app.rb +20 -0
  21. data/lib/groupdocs_platform_cloud/models/access_token_list_response.rb +213 -0
  22. data/lib/groupdocs_platform_cloud/models/access_token_response.rb +211 -0
  23. data/lib/groupdocs_platform_cloud/models/app.rb +243 -0
  24. data/lib/groupdocs_platform_cloud/models/app_usage.rb +235 -0
  25. data/lib/groupdocs_platform_cloud/models/application_usage_response.rb +202 -0
  26. data/lib/groupdocs_platform_cloud/models/disc_usage.rb +207 -0
  27. data/lib/groupdocs_platform_cloud/models/disc_usage_response.rb +211 -0
  28. data/lib/groupdocs_platform_cloud/models/file.rb +253 -0
  29. data/lib/groupdocs_platform_cloud/models/file_exist.rb +207 -0
  30. data/lib/groupdocs_platform_cloud/models/file_exist_response.rb +211 -0
  31. data/lib/groupdocs_platform_cloud/models/file_response.rb +224 -0
  32. data/lib/groupdocs_platform_cloud/models/file_version.rb +276 -0
  33. data/lib/groupdocs_platform_cloud/models/file_versions_response.rb +213 -0
  34. data/lib/groupdocs_platform_cloud/models/folder_response.rb +208 -0
  35. data/lib/groupdocs_platform_cloud/models/heroku_request.rb +233 -0
  36. data/lib/groupdocs_platform_cloud/models/heroku_request_options.rb +188 -0
  37. data/lib/groupdocs_platform_cloud/models/move_file_response.rb +202 -0
  38. data/lib/groupdocs_platform_cloud/models/move_folder_response.rb +202 -0
  39. data/lib/groupdocs_platform_cloud/models/remove_file_response.rb +202 -0
  40. data/lib/groupdocs_platform_cloud/models/remove_folder_response.rb +202 -0
  41. data/lib/groupdocs_platform_cloud/models/saa_spose_response.rb +202 -0
  42. data/lib/groupdocs_platform_cloud/models/storage_exist_response.rb +216 -0
  43. data/lib/groupdocs_platform_cloud/models/user_usage_summary_response.rb +211 -0
  44. data/lib/groupdocs_platform_cloud/models/user_usage_summary_statistics.rb +291 -0
  45. data/lib/groupdocs_platform_cloud/version.rb +15 -0
  46. data/test/data/SampleExecuteTemplate.doc +0 -0
  47. data/test/data/SampleExecuteTemplateData.txt +49 -0
  48. data/test/data/SampleWordDocument.docx +0 -0
  49. data/test/data/buzz.png +0 -0
  50. data/test/data/testfile.txt +1 -0
  51. data/test/platform_tests.rb +144 -0
  52. metadata +156 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e6cf91cdffb28de83ff7104f04d5db089742936
4
+ data.tar.gz: 858f781ebcd0d3ab092eb8950029c99725f4d5d2
5
+ SHA512:
6
+ metadata.gz: 88219846b05d9d24fd15e7f67d114793909fed43cc67118f2a8764fac10a4b9b1ed7ee6c0791ff772d109246e6ebb5d33b6a902d09c8c4c298a26a48f94ed8e7
7
+ data.tar.gz: 83ed69bcd8e25acc38cbaf5b00f59f1897357cc9f44ebd6503cc880519277c4f4b5c884cef8187bfc18d7eefd43dcf9411de8fea880459f8cfb8c1ce84a52998
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2001-2016 Aspose Pty Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # groupdocs_platform_cloud
2
+
3
+ GroupDocsPlatformCloud - the Ruby gem for the Web API Swagger specification
4
+
5
+ No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
6
+
7
+ This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
8
+
9
+ - API version: 1.0
10
+ - Package version: 1.0.0
11
+ - Build package: io.swagger.codegen.languages.RubyClientCodegen
12
+
13
+ ## Installation
14
+
15
+ ### Build a gem
16
+
17
+ To build the Ruby code into a gem:
18
+
19
+ ```shell
20
+ gem build groupdocs_platform_cloud.gemspec
21
+ ```
22
+
23
+ Then either install the gem locally:
24
+
25
+ ```shell
26
+ gem install ./groupdocs_platform_cloud-1.0.0.gem
27
+ ```
28
+ (for development, run `gem install --dev ./groupdocs_platform_cloud-1.0.0.gem` to install the development dependencies)
29
+
30
+ or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
31
+
32
+ Finally add this to the Gemfile:
33
+
34
+ gem 'groupdocs_platform_cloud', '~> 1.0.0'
35
+
36
+ ### Install from Git
37
+
38
+ If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile:
39
+
40
+ gem 'groupdocs_platform_cloud', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git'
41
+
42
+ ### Include the Ruby code directly
43
+
44
+ Include the Ruby code directly using `-I` as follows:
45
+
46
+ ```shell
47
+ ruby -Ilib script.rb
48
+ ```
49
+
50
+ ## Getting Started
51
+
52
+ Please follow the [installation](#installation) procedure and then run the following code:
53
+ ```ruby
54
+ # Load the gem
55
+ require 'groupdocs_platform_cloud'
56
+
57
+ api_instance = GroupDocsPlatformCloud::AppApi.new
58
+
59
+ name = "name_example" # String | Application Name
60
+
61
+
62
+ begin
63
+ #Delete Application
64
+ result = api_instance.app_delete(name)
65
+ p result
66
+ rescue GroupDocsPlatformCloud::ApiError => e
67
+ puts "Exception when calling AppApi->app_delete: #{e}"
68
+ end
69
+
70
+ ```
71
+
72
+ ## Documentation for API Endpoints
73
+
74
+ All URIs are relative to *http://api-qa.groupdocs.cloud/v1/*
75
+
76
+ Class | Method | HTTP request | Description
77
+ ------------ | ------------- | ------------- | -------------
78
+ *GroupDocsPlatformCloud::AppApi* | [**app_delete**](docs/AppApi.md#app_delete) | **DELETE** /app/{name} | Delete Application
79
+ *GroupDocsPlatformCloud::AppApi* | [**app_get**](docs/AppApi.md#app_get) | **GET** /app | Get List of Applications
80
+ *GroupDocsPlatformCloud::AppApi* | [**app_get_by_name**](docs/AppApi.md#app_get_by_name) | **GET** /app/{name} | Get Application by Name
81
+ *GroupDocsPlatformCloud::AppApi* | [**app_get_usage**](docs/AppApi.md#app_get_usage) | **GET** /app/{name}/usage | Get Application Usage By Period
82
+ *GroupDocsPlatformCloud::AppApi* | [**app_post**](docs/AppApi.md#app_post) | **POST** /app | Create new Application
83
+ *GroupDocsPlatformCloud::AppApi* | [**app_put**](docs/AppApi.md#app_put) | **PUT** /app/{name} | Update Application Name
84
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics**](docs/AppStatisticsApi.md#app_statistics_get_statistics) | **GET** /statistics | Get service statistics in HTML form.
85
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_api**](docs/AppStatisticsApi.md#app_statistics_get_statistics_api) | **GET** /statistics/calls | Get API calls statistics.
86
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_by_hours**](docs/AppStatisticsApi.md#app_statistics_get_statistics_by_hours) | **GET** /statistics/hours | Get statistics for specific dates by hours.
87
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_by_hours_for_last30_days**](docs/AppStatisticsApi.md#app_statistics_get_statistics_by_hours_for_last30_days) | **GET** /statistics/hours/last30Days | Get statistics for last 30 days by hours.
88
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_current_users**](docs/AppStatisticsApi.md#app_statistics_get_statistics_current_users) | **GET** /statistics/currentUsers | Get clients with overdraft statistics.
89
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_errors**](docs/AppStatisticsApi.md#app_statistics_get_statistics_errors) | **GET** /statistics/errors | Get last errors statistics.
90
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_free**](docs/AppStatisticsApi.md#app_statistics_get_statistics_free) | **GET** /statistics/free | Get free users statistics.
91
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_like_gd**](docs/AppStatisticsApi.md#app_statistics_get_statistics_like_gd) | **GET** /statistics/likeGD | Get service statistics in HTML form like GroupDocs.
92
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_overdraft**](docs/AppStatisticsApi.md#app_statistics_get_statistics_overdraft) | **GET** /statistics/overdrafts | Get clients with overdraft statistics.
93
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_paid**](docs/AppStatisticsApi.md#app_statistics_get_statistics_paid) | **GET** /statistics/paid | Get paid clients statistics.
94
+ *GroupDocsPlatformCloud::AppStatisticsApi* | [**app_statistics_get_statistics_plans**](docs/AppStatisticsApi.md#app_statistics_get_statistics_plans) | **GET** /statistics/plans | Get users with plans statistics.
95
+ *GroupDocsPlatformCloud::AuthApi* | [**auth_delete_token**](docs/AuthApi.md#auth_delete_token) | **DELETE** /auth/token/{token} | Delete access token
96
+ *GroupDocsPlatformCloud::AuthApi* | [**auth_get_tokens**](docs/AuthApi.md#auth_get_tokens) | **GET** /auth/token | Get access tokens
97
+ *GroupDocsPlatformCloud::AuthApi* | [**auth_post_token**](docs/AuthApi.md#auth_post_token) | **POST** /auth/token | Create access token
98
+ *GroupDocsPlatformCloud::FileApi* | [**file_delete_file**](docs/FileApi.md#file_delete_file) | **DELETE** /storage/file | Remove a specific file. Parameters: path - file path e.g. /file.ext, versionID - file's version, storage - user's storage name.
99
+ *GroupDocsPlatformCloud::FileApi* | [**file_get_download**](docs/FileApi.md#file_get_download) | **GET** /storage/file | Download a specific file. Parameters: path - file path e.g. /file.ext, versionID - file's version, storage - user's storage name.
100
+ *GroupDocsPlatformCloud::FileApi* | [**file_post_move_file**](docs/FileApi.md#file_post_move_file) | **POST** /storage/file | Move a specific file.
101
+ *GroupDocsPlatformCloud::FileApi* | [**file_put_create**](docs/FileApi.md#file_put_create) | **PUT** /storage/file | Upload a specific file. Parameters: path - source file path e.g. /file.ext, versionID - source file's version, storage - user's source storage name, newdest - destination file path, destStorage - user's destination storage name.
102
+ *GroupDocsPlatformCloud::FolderApi* | [**folder_delete_folder**](docs/FolderApi.md#folder_delete_folder) | **DELETE** /storage/folder | Remove a specific folder. Parameters: path - folder path e.g. /Folder1, storage - user's storage name, recursive - is subfolders and files must be deleted for specified path.
103
+ *GroupDocsPlatformCloud::FolderApi* | [**folder_get_list_files**](docs/FolderApi.md#folder_get_list_files) | **GET** /storage/folder | Get the file listing of a specific folder. Parametres: path - start with name of storage e.g. root folder '/'or some folder '/folder1/..', storage - user's storage name.
104
+ *GroupDocsPlatformCloud::FolderApi* | [**folder_post_move_folder**](docs/FolderApi.md#folder_post_move_folder) | **POST** /storage/folder | Move a specific folder. Parameters: src - source folder path e.g. /Folder1, storage - user's source storage name, dest - destination folder path e.g. /Folder2, destStorage - user's destination storage name.
105
+ *GroupDocsPlatformCloud::FolderApi* | [**folder_put_create_folder**](docs/FolderApi.md#folder_put_create_folder) | **PUT** /storage/folder | Create the folder. Parameters: path - source folder path e.g. /Folder1, storage - user's source storage name, newdest - destination folder path e.g. /Folder2, destStorage - user's destination storage name.
106
+ *GroupDocsPlatformCloud::HerokuApi* | [**heroku_delete_resources**](docs/HerokuApi.md#heroku_delete_resources) | **DELETE** /heroku/resources/{id} | Unsubscribe Heroku User (set payment plan to Free)
107
+ *GroupDocsPlatformCloud::HerokuApi* | [**heroku_get_resources**](docs/HerokuApi.md#heroku_get_resources) | **GET** /heroku/resources/{id} | Provision. Get Heroku User
108
+ *GroupDocsPlatformCloud::HerokuApi* | [**heroku_post_resources**](docs/HerokuApi.md#heroku_post_resources) | **POST** /heroku/resources | Provision. Create Heroku User
109
+ *GroupDocsPlatformCloud::HerokuApi* | [**heroku_put_resources**](docs/HerokuApi.md#heroku_put_resources) | **PUT** /heroku/resources/{id} | Update Heroku User Payment Plan
110
+ *GroupDocsPlatformCloud::StorageApi* | [**storage_get_disc_usage**](docs/StorageApi.md#storage_get_disc_usage) | **GET** /storage/disc | Check the disk usage of the current account. Parameters: storage - user's storage name.
111
+ *GroupDocsPlatformCloud::StorageApi* | [**storage_get_is_exist**](docs/StorageApi.md#storage_get_is_exist) | **GET** /storage/exist | Check if a specific file or folder exists.Parameters: path - file or folder path e.g. /file.ext or /Folder1, versionID - file's version, storage - user's storage name.
112
+ *GroupDocsPlatformCloud::StorageApi* | [**storage_get_is_storage_exist**](docs/StorageApi.md#storage_get_is_storage_exist) | **GET** /storage/{name}/exist | Check if storage exists.
113
+ *GroupDocsPlatformCloud::StorageApi* | [**storage_get_list_file_versions**](docs/StorageApi.md#storage_get_list_file_versions) | **GET** /storage/version | Get the file's versions list. Parameters: path - file path e.g. /file.ext or /Folder1/file.ext, storage - user's storage name.
114
+ *GroupDocsPlatformCloud::UsageApi* | [**usage_get_user_usage**](docs/UsageApi.md#usage_get_user_usage) | **GET** /usage | Get usage logs for some period.
115
+ *GroupDocsPlatformCloud::UsageApi* | [**usage_get_user_usage_current_month**](docs/UsageApi.md#usage_get_user_usage_current_month) | **GET** /usage/currentPeriod | Get usage for current subscription period.
116
+ *GroupDocsPlatformCloud::UsageApi* | [**usage_get_user_usage_current_period_summary**](docs/UsageApi.md#usage_get_user_usage_current_period_summary) | **GET** /usage/summary | Get summary usage for current subscription period.
117
+ *GroupDocsPlatformCloud::UsageApi* | [**usage_get_user_usage_previous_month**](docs/UsageApi.md#usage_get_user_usage_previous_month) | **GET** /usage/previousPeriod | Get usage logs for previous subscription period.
118
+
119
+
120
+ ## Documentation for Models
121
+
122
+ - [GroupDocsPlatformCloud::App](docs/App.md)
123
+ - [GroupDocsPlatformCloud::AppUsage](docs/AppUsage.md)
124
+ - [GroupDocsPlatformCloud::DiscUsage](docs/DiscUsage.md)
125
+ - [GroupDocsPlatformCloud::File](docs/File.md)
126
+ - [GroupDocsPlatformCloud::FileExist](docs/FileExist.md)
127
+ - [GroupDocsPlatformCloud::HerokuRequest](docs/HerokuRequest.md)
128
+ - [GroupDocsPlatformCloud::HerokuRequestOptions](docs/HerokuRequestOptions.md)
129
+ - [GroupDocsPlatformCloud::SaaSposeResponse](docs/SaaSposeResponse.md)
130
+ - [GroupDocsPlatformCloud::UserUsageSummaryStatistics](docs/UserUsageSummaryStatistics.md)
131
+ - [GroupDocsPlatformCloud::AccessTokenListResponse](docs/AccessTokenListResponse.md)
132
+ - [GroupDocsPlatformCloud::AccessTokenResponse](docs/AccessTokenResponse.md)
133
+ - [GroupDocsPlatformCloud::ApplicationUsageResponse](docs/ApplicationUsageResponse.md)
134
+ - [GroupDocsPlatformCloud::DiscUsageResponse](docs/DiscUsageResponse.md)
135
+ - [GroupDocsPlatformCloud::FileExistResponse](docs/FileExistResponse.md)
136
+ - [GroupDocsPlatformCloud::FileVersion](docs/FileVersion.md)
137
+ - [GroupDocsPlatformCloud::FileVersionsResponse](docs/FileVersionsResponse.md)
138
+ - [GroupDocsPlatformCloud::MoveFileResponse](docs/MoveFileResponse.md)
139
+ - [GroupDocsPlatformCloud::MoveFolderResponse](docs/MoveFolderResponse.md)
140
+ - [GroupDocsPlatformCloud::RemoveFileResponse](docs/RemoveFileResponse.md)
141
+ - [GroupDocsPlatformCloud::RemoveFolderResponse](docs/RemoveFolderResponse.md)
142
+ - [GroupDocsPlatformCloud::StorageExistResponse](docs/StorageExistResponse.md)
143
+ - [GroupDocsPlatformCloud::UserUsageSummaryResponse](docs/UserUsageSummaryResponse.md)
144
+
145
+
146
+ ## Documentation for Authorization
147
+
148
+
149
+ ### appsid
150
+
151
+ - **Type**: API key
152
+ - **API key parameter name**: appsid
153
+ - **Location**: URL query string
154
+
155
+ ### signature
156
+
157
+ - **Type**: API key
158
+ - **API key parameter name**: signature
159
+ - **Location**: URL query string
160
+
@@ -0,0 +1 @@
1
+ I have made changes in the api_client.mustache template file. Please replace your cloned api_client.mustache with this file.
@@ -0,0 +1,441 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ require 'date'
6
+ require 'json'
7
+ require 'logger'
8
+ require 'tempfile'
9
+ require 'typhoeus'
10
+ require 'uri'
11
+ require 'openssl'
12
+ require 'base64'
13
+ require 'rexml/document'
14
+
15
+ module {{moduleName}}
16
+ class ApiClient
17
+
18
+ include AsposeStorageCloud
19
+
20
+ # The Configuration object holding settings to be used in the API client.
21
+ attr_accessor :config
22
+
23
+ # Defines the headers to be used in HTTP requests of all API calls by default.
24
+ #
25
+ # @return [Hash]
26
+ attr_accessor :default_headers
27
+
28
+ # Initializes the ApiClient
29
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
30
+ def initialize(config = Configuration.default)
31
+ @config = config
32
+ @user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/#{VERSION}/ruby{{/httpUserAgent}}"
33
+ @default_headers = {
34
+ 'Content-Type' => "application/json",
35
+ 'User-Agent' => @user_agent
36
+ }
37
+ end
38
+
39
+ def self.default
40
+ @@default ||= ApiClient.new
41
+ end
42
+
43
+ # Call an API with given options.
44
+ #
45
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
46
+ # the data deserialized from response body (could be nil), response status code and response headers.
47
+ def call_api(http_method, path, opts = {})
48
+ request = build_request(http_method, path, opts)
49
+ response = request.run
50
+
51
+ if @config.debugging
52
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
53
+ end
54
+
55
+ unless response.success?
56
+ if response.timed_out?
57
+ fail ApiError.new('Connection timed out')
58
+ elsif response.code == 0
59
+ # Errors from libcurl will be made visible here
60
+ fail ApiError.new(:code => 0,
61
+ :message => response.return_message)
62
+ else
63
+ fail ApiError.new(:code => response.code,
64
+ :response_headers => response.headers,
65
+ :response_body => response.body),
66
+ response.status_message
67
+ end
68
+ end
69
+
70
+ if opts[:return_type]
71
+ data = deserialize(response, opts[:return_type])
72
+ else
73
+ data = nil
74
+ end
75
+ return data, response.code, response.headers
76
+ end
77
+
78
+ # Builds the HTTP request
79
+ #
80
+ # @param [String] http_method HTTP method/verb (e.g. POST)
81
+ # @param [String] path URL path (e.g. /account/new)
82
+ # @option opts [Hash] :header_params Header parameters
83
+ # @option opts [Hash] :query_params Query parameters
84
+ # @option opts [Hash] :form_params Query parameters
85
+ # @option opts [Object] :body HTTP body (JSON/XML)
86
+ # @return [Typhoeus::Request] A Typhoeus Request
87
+ def build_request(http_method, path, opts = {})
88
+ url = build_request_url(path)
89
+ http_method = http_method.to_sym.downcase
90
+
91
+ header_params = @default_headers.merge(opts[:header_params] || {})
92
+ query_params = {}
93
+ form_params = opts[:form_params] || {}
94
+
95
+ {{#hasAuthMethods}}
96
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
97
+ {{/hasAuthMethods}}
98
+
99
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
100
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
101
+
102
+ req_opts = {
103
+ :method => http_method,
104
+ :headers => header_params,
105
+ :params => query_params,
106
+ :params_encoding => @config.params_encoding,
107
+ :timeout => @config.timeout,
108
+ :ssl_verifypeer => @config.verify_ssl,
109
+ :ssl_verifyhost => _verify_ssl_host,
110
+ :sslcert => @config.cert_file,
111
+ :sslkey => @config.key_file,
112
+ :verbose => @config.debugging
113
+ }
114
+
115
+ # set custom cert, if provided
116
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
117
+
118
+ if [:post, :patch, :put, :delete].include?(http_method)
119
+ req_body = build_request_body(header_params, form_params, opts[:body])
120
+ req_opts.update :body => req_body
121
+ if @config.debugging
122
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
123
+ end
124
+ end
125
+
126
+ url = sign(url, opts[:query_params])
127
+ request = Typhoeus::Request.new(url, req_opts)
128
+ download_file(request) if opts[:return_type] == 'File'
129
+ request
130
+ end
131
+
132
+ # Signs a URI with your appSID and Key.
133
+ # * :url describes the URL to sign
134
+
135
+ def sign(url, query_params)
136
+
137
+ puts "url: #{url}"
138
+ puts "query_params: #{query_params}"
139
+ fail "Please set Aspose App key and SID first. You can get App key and App SID from https://cloud.aspose.com" if AsposeApp.app_key.nil? || AsposeApp.app_sid.nil?
140
+
141
+ url = url[0..-2] if url[-1].eql? '/'
142
+
143
+ unless query_params.empty?
144
+ url = "#{url}?"
145
+ query_params.each { |key, value|
146
+ url = "#{url}#{key}=#{value}&"
147
+ }
148
+ url = url[0..-2]
149
+ end
150
+
151
+ parsed_url = URI.parse(url)
152
+
153
+ url_to_sign = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
154
+ url_to_sign += "?#{parsed_url.query}" if parsed_url.query
155
+ if parsed_url.query
156
+ url_to_sign += "&appSID=#{AsposeApp.app_sid}"
157
+ else
158
+ url_to_sign += "?appSID=#{AsposeApp.app_sid}"
159
+ end
160
+
161
+ # create a signature using the private key and the URL
162
+ raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), AsposeApp.app_key, url_to_sign)
163
+
164
+ #Convert raw to encoded string
165
+ signature = Base64.strict_encode64(raw_signature).tr('+/', '-_')
166
+
167
+ #remove invalid character
168
+ signature = signature.gsub(/[=_-]/, '=' => '', '_' => '%2f', '-' => '%2b')
169
+
170
+ #Define expression
171
+ pat = Regexp.new('%[0-9a-f]{2}')
172
+
173
+ #Replace the portion matched to the above pattern to upper case
174
+ 6.times do
175
+ signature = signature.sub(pat, pat.match(signature).to_s.upcase)
176
+ end
177
+
178
+ # prepend the server and append the signature.
179
+ url_to_sign + "&signature=#{signature}"
180
+
181
+ end
182
+
183
+ # Check if the given MIME is a JSON MIME.
184
+ # JSON MIME examples:
185
+ # application/json
186
+ # application/json; charset=UTF8
187
+ # APPLICATION/JSON
188
+ # */*
189
+ # @param [String] mime MIME
190
+ # @return [Boolean] True if the MIME is application/json
191
+ def json_mime?(mime)
192
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
193
+ end
194
+
195
+ # Deserialize the response to the given return type.
196
+ #
197
+ # @param [Response] response HTTP response
198
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
199
+ def deserialize(response, return_type)
200
+ body = response.body
201
+
202
+ # handle file downloading - return the File instance processed in request callbacks
203
+ # note that response body is empty when the file is written in chunks in request on_body callback
204
+ return @tempfile if return_type == 'File'
205
+
206
+ return nil if body.nil? || body.empty?
207
+
208
+ # return response body directly for String return type
209
+ return body if return_type == 'String'
210
+
211
+ # ensuring a default content type
212
+ content_type = response.headers['Content-Type'] || 'application/json'
213
+
214
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
215
+
216
+ begin
217
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
218
+ rescue JSON::ParserError => e
219
+ if %w(String Date DateTime).include?(return_type)
220
+ data = body
221
+ else
222
+ raise e
223
+ end
224
+ end
225
+
226
+ convert_to_type data, return_type
227
+ end
228
+
229
+ # Convert data to the given return type.
230
+ # @param [Object] data Data to be converted
231
+ # @param [String] return_type Return type
232
+ # @return [Mixed] Data in a particular type
233
+ def convert_to_type(data, return_type)
234
+ return nil if data.nil?
235
+ case return_type
236
+ when 'String'
237
+ data.to_s
238
+ when 'Integer'
239
+ data.to_i
240
+ when 'Float'
241
+ data.to_f
242
+ when 'BOOLEAN'
243
+ data == true
244
+ when 'DateTime'
245
+ # parse date time (expecting ISO 8601 format)
246
+ DateTime.parse data
247
+ when 'Date'
248
+ # parse date time (expecting ISO 8601 format)
249
+ Date.parse data
250
+ when 'Object'
251
+ # generic object (usually a Hash), return directly
252
+ data
253
+ when /\AArray<(.+)>\z/
254
+ # e.g. Array<Pet>
255
+ sub_type = $1
256
+ data.map {|item| convert_to_type(item, sub_type) }
257
+ when /\AHash\<String, (.+)\>\z/
258
+ # e.g. Hash<String, Integer>
259
+ sub_type = $1
260
+ {}.tap do |hash|
261
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
262
+ end
263
+ else
264
+ # models, e.g. Pet
265
+ {{moduleName}}.const_get(return_type).new.tap do |model|
266
+ model.build_from_hash data
267
+ end
268
+ end
269
+ end
270
+
271
+ # Save response body into a file in (the defined) temporary folder, using the filename
272
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
273
+ # The response body is written to the file in chunks in order to handle files which
274
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
275
+ # process can use.
276
+ #
277
+ # @see Configuration#temp_folder_path
278
+ def download_file(request)
279
+ tempfile = nil
280
+ encoding = nil
281
+ request.on_headers do |response|
282
+ content_disposition = response.headers['Content-Disposition']
283
+ if content_disposition and content_disposition =~ /filename=/i
284
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
285
+ prefix = sanitize_filename(filename)
286
+ else
287
+ prefix = 'download-'
288
+ end
289
+ prefix = prefix + '-' unless prefix.end_with?('-')
290
+ encoding = response.body.encoding
291
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
292
+ @tempfile = tempfile
293
+ end
294
+ request.on_body do |chunk|
295
+ chunk.force_encoding(encoding)
296
+ tempfile.write(chunk)
297
+ end
298
+ request.on_complete do |response|
299
+ tempfile.close
300
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
301
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
302
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
303
+ "explicitly with `tempfile.delete`"
304
+ end
305
+ end
306
+
307
+ # Sanitize filename by removing path.
308
+ # e.g. ../../sun.gif becomes sun.gif
309
+ #
310
+ # @param [String] filename the filename to be sanitized
311
+ # @return [String] the sanitized filename
312
+ def sanitize_filename(filename)
313
+ filename.gsub(/.*[\/\\]/, '')
314
+ end
315
+
316
+ def build_request_url(path)
317
+ # Add leading and trailing slashes to path
318
+ path = "/#{path}".gsub(/\/+/, '/')
319
+ URI.encode(@config.base_url + path)
320
+ end
321
+
322
+ # Builds the HTTP request body
323
+ #
324
+ # @param [Hash] header_params Header parameters
325
+ # @param [Hash] form_params Query parameters
326
+ # @param [Object] body HTTP body (JSON/XML)
327
+ # @return [String] HTTP body data in the form of string
328
+ def build_request_body(header_params, form_params, body)
329
+ # http form
330
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
331
+ header_params['Content-Type'] == 'multipart/form-data'
332
+ data = {}
333
+ form_params.each do |key, value|
334
+ case value
335
+ when File, Array, nil
336
+ # let typhoeus handle File, Array and nil parameters
337
+ data[key] = value
338
+ else
339
+ data[key] = value.to_s
340
+ end
341
+ end
342
+ elsif body
343
+ data = body.is_a?(String) ? body : body.to_json
344
+ else
345
+ data = nil
346
+ end
347
+ data
348
+ end
349
+
350
+ # Update hearder and query params based on authentication settings.
351
+ #
352
+ # @param [Hash] header_params Header parameters
353
+ # @param [Hash] query_params Query parameters
354
+ # @param [String] auth_names Authentication scheme name
355
+ def update_params_for_auth!(header_params, query_params, auth_names)
356
+ Array(auth_names).each do |auth_name|
357
+ auth_setting = @config.auth_settings[auth_name]
358
+ next unless auth_setting
359
+ case auth_setting[:in]
360
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
361
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
362
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
363
+ end
364
+ end
365
+ end
366
+
367
+ # Sets user agent in HTTP header
368
+ #
369
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
370
+ def user_agent=(user_agent)
371
+ @user_agent = user_agent
372
+ @default_headers['User-Agent'] = @user_agent
373
+ end
374
+
375
+ # Return Accept header based on an array of accepts provided.
376
+ # @param [Array] accepts array for Accept
377
+ # @return [String] the Accept header (e.g. application/json)
378
+ def select_header_accept(accepts)
379
+ return nil if accepts.nil? || accepts.empty?
380
+ # use JSON when present, otherwise use all of the provided
381
+ json_accept = accepts.find { |s| json_mime?(s) }
382
+ return json_accept || accepts.join(',')
383
+ end
384
+
385
+ # Return Content-Type header based on an array of content types provided.
386
+ # @param [Array] content_types array for Content-Type
387
+ # @return [String] the Content-Type header (e.g. application/json)
388
+ def select_header_content_type(content_types)
389
+ # use application/json by default
390
+ return 'application/json' if content_types.nil? || content_types.empty?
391
+ # use JSON when present, otherwise use the first one
392
+ json_content_type = content_types.find { |s| json_mime?(s) }
393
+ return json_content_type || content_types.first
394
+ end
395
+
396
+ # Convert object (array, hash, object, etc) to JSON string.
397
+ # @param [Object] model object to be converted into JSON string
398
+ # @return [String] JSON string representation of the object
399
+ def object_to_http_body(model)
400
+ return model if model.nil? || model.is_a?(String)
401
+ local_body = nil
402
+ if model.is_a?(Array)
403
+ local_body = model.map{|m| object_to_hash(m) }
404
+ else
405
+ local_body = object_to_hash(model)
406
+ end
407
+ local_body.to_json
408
+ end
409
+
410
+ # Convert object(non-array) to hash.
411
+ # @param [Object] obj object to be converted into JSON string
412
+ # @return [String] JSON string representation of the object
413
+ def object_to_hash(obj)
414
+ if obj.respond_to?(:to_hash)
415
+ obj.to_hash
416
+ else
417
+ obj
418
+ end
419
+ end
420
+
421
+ # Build parameter value according to the given collection format.
422
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
423
+ def build_collection_param(param, collection_format)
424
+ case collection_format
425
+ when :csv
426
+ param.join(',')
427
+ when :ssv
428
+ param.join(' ')
429
+ when :tsv
430
+ param.join("\t")
431
+ when :pipes
432
+ param.join('|')
433
+ when :multi
434
+ # return the array directly as typhoeus will handle it as expected
435
+ param
436
+ else
437
+ fail "unknown collection format: #{collection_format.inspect}"
438
+ end
439
+ end
440
+ end
441
+ end