Skip to content

Commit 4c42fde

Browse files
committed
Updated sources
1 parent 0141c44 commit 4c42fde

File tree

5 files changed

+407
-2
lines changed

5 files changed

+407
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gem install groupdocs_conversion_cloud
1212
To add dependency to your app copy following into your Gemfile and run `bundle install`:
1313

1414
```
15-
gem "groupdocs_conversion_cloud", "~> 21.10"
15+
gem "groupdocs_conversion_cloud", "~> 21.12"
1616
```
1717

1818
## Getting Started

lib/groupdocs_conversion_cloud.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
require_relative 'groupdocs_conversion_cloud/configuration'
3131

3232
# Models
33+
require_relative 'groupdocs_conversion_cloud/models/consumption_result'
3334
require_relative 'groupdocs_conversion_cloud/models/convert_options'
3435
require_relative 'groupdocs_conversion_cloud/models/convert_settings'
3536
require_relative 'groupdocs_conversion_cloud/models/disc_usage'
@@ -206,4 +207,5 @@
206207
require_relative 'groupdocs_conversion_cloud/api/file_api'
207208
require_relative 'groupdocs_conversion_cloud/api/folder_api'
208209
require_relative 'groupdocs_conversion_cloud/api/info_api'
210+
require_relative 'groupdocs_conversion_cloud/api/license_api'
209211
require_relative 'groupdocs_conversion_cloud/api/storage_api'
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# -----------------------------------------------------------------------------------
2+
# <copyright company="Aspose Pty Ltd" file="license.rb">
3+
# Copyright (c) 2003-2021 Aspose Pty Ltd
4+
# </copyright>
5+
# <summary>
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
# </summary>
24+
# -----------------------------------------------------------------------------------
25+
26+
require 'uri'
27+
require 'date'
28+
29+
module GroupDocsConversionCloud
30+
#
31+
# GroupDocs.Conversion Cloud API
32+
#
33+
class LicenseApi
34+
attr_accessor :config
35+
36+
#make LicenseApi.new private
37+
private_class_method :new
38+
39+
# Initializes new instance of LicenseApi
40+
#
41+
# @param [config] Configuration
42+
# @return [LicenseApi] New instance of LicenseApi
43+
def initialize(config)
44+
@config = config
45+
@api_client = ApiClient.new(config)
46+
@access_token = nil
47+
end
48+
49+
# Initializes new instance of LicenseApi
50+
#
51+
# @param [app_sid] Application identifier (App SID)
52+
# @param [app_key] Application private key (App Key)
53+
# @return [LicenseApi] New instance of LicenseApi
54+
def self.from_keys(app_sid, app_key)
55+
config = Configuration.new(app_sid, app_key)
56+
return new(config)
57+
end
58+
59+
# Initializes new instance of LicenseApi
60+
#
61+
# @param [config] Configuration
62+
# @return [LicenseApi] New instance of LicenseApi
63+
def self.from_config(config)
64+
return new(config)
65+
end
66+
67+
# Get license consumption
68+
#
69+
# @return [ConsumptionResult]
70+
def get_consumption_credit()
71+
data, _status_code, _headers = get_consumption_credit_with_http_info()
72+
data
73+
end
74+
75+
# Get license consumption
76+
#
77+
78+
# @return [Array<(ConsumptionResult, Fixnum, Hash)>]
79+
# ConsumptionResult data, response status code and response headers
80+
def get_consumption_credit_with_http_info()
81+
82+
83+
@api_client.config.logger.debug 'Calling API: LicenseApi.get_consumption_credit ...' if @api_client.config.debugging
84+
# resource path
85+
local_var_path = '/conversion/consumption'
86+
87+
# query parameters
88+
query_params = {}
89+
90+
# header parameters
91+
header_params = {}
92+
# HTTP header 'Accept' (if needed)
93+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
94+
# HTTP header 'Content-Type'
95+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
96+
97+
# form parameters
98+
form_params = {}
99+
100+
# http body (model)
101+
post_body = nil
102+
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
103+
header_params: header_params,
104+
query_params: query_params,
105+
form_params: form_params,
106+
body: post_body,
107+
access_token: get_access_token,
108+
return_type: 'ConsumptionResult')
109+
if @api_client.config.debugging
110+
@api_client.config.logger.debug "API called:
111+
LicenseApi#get_consumption_credit\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
112+
end
113+
[data, status_code, headers]
114+
end
115+
116+
#
117+
# Helper method to convert first letter to downcase
118+
#
119+
private def downcase_first_letter(str)
120+
value = str[0].downcase + str[1..-1]
121+
value
122+
end
123+
124+
#
125+
# Retrieves access token
126+
#
127+
private def get_access_token
128+
if @access_token.nil? then
129+
request_access_token
130+
end
131+
132+
@access_token
133+
end
134+
135+
#
136+
# Gets a access token from server
137+
#
138+
private def request_access_token
139+
auth_config = Configuration.new(@config.app_sid, @config.app_key)
140+
auth_config.api_base_url = @config.api_base_url
141+
auth_config.debugging = @config.debugging
142+
auth_config.logger = @config.logger
143+
auth_config.temp_folder_path = @config.temp_folder_path
144+
auth_config.client_side_validation = @config.client_side_validation
145+
auth_config.api_version = ''
146+
147+
auth_api_client = ApiClient.new(auth_config)
148+
149+
request_url = "/connect/token"
150+
post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
151+
152+
data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
153+
154+
@access_token = data[:access_token]
155+
156+
expires_in_seconds = data[:expires_in].to_i - 5 * 60
157+
expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
158+
@access_token_expires_at = DateTime.now + expires_in_days
159+
end
160+
161+
# requires all files inside a directory from current dir
162+
# @param _dir can be relative path like '/lib' or "../lib"
163+
private def require_all(_dir)
164+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
165+
require file
166+
end
167+
end
168+
end
169+
end

0 commit comments

Comments
 (0)