pdf4me 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/README.md +472 -0
- data/Rakefile +8 -0
- data/docs/ActionFlow.md +8 -0
- data/docs/ApiUsageRes.md +11 -0
- data/docs/ArchiveConfig.md +11 -0
- data/docs/ArchiveJobReq.md +12 -0
- data/docs/ArchiveJobRes.md +9 -0
- data/docs/Color.md +10 -0
- data/docs/ConvertApi.md +102 -0
- data/docs/ConvertToPdf.md +10 -0
- data/docs/ConvertToPdfAction.md +10 -0
- data/docs/ConvertToPdfRes.md +8 -0
- data/docs/CreateImages.md +10 -0
- data/docs/CreateImagesRes.md +8 -0
- data/docs/CreatePdfA.md +10 -0
- data/docs/CreatePdfARes.md +8 -0
- data/docs/CustomCMSConfig.md +23 -0
- data/docs/DocAction.md +8 -0
- data/docs/DocLog.md +12 -0
- data/docs/DocMetadata.md +16 -0
- data/docs/Document.md +16 -0
- data/docs/DocumentApi.md +203 -0
- data/docs/DropDocumentReq.md +20 -0
- data/docs/DropDocumentRes.md +15 -0
- data/docs/ExecutionTrigger.md +10 -0
- data/docs/Extract.md +10 -0
- data/docs/ExtractAction.md +9 -0
- data/docs/ExtractApi.md +102 -0
- data/docs/ExtractRes.md +8 -0
- data/docs/GetDocumentListRes.md +13 -0
- data/docs/GetDocumentReq.md +14 -0
- data/docs/GetDocumentRes.md +14 -0
- data/docs/IFormFile.md +13 -0
- data/docs/Image.md +15 -0
- data/docs/ImageAction.md +30 -0
- data/docs/ImageApi.md +107 -0
- data/docs/Job.md +10 -0
- data/docs/JobApi.md +197 -0
- data/docs/JobConfig.md +18 -0
- data/docs/JobConfigRes.md +8 -0
- data/docs/KeyValuePairStringObject.md +9 -0
- data/docs/KeyValuePairStringString.md +9 -0
- data/docs/ManagementApi.md +92 -0
- data/docs/Merge.md +10 -0
- data/docs/MergeAction.md +8 -0
- data/docs/MergeApi.md +102 -0
- data/docs/MergeRes.md +8 -0
- data/docs/Notification.md +9 -0
- data/docs/OcrAction.md +12 -0
- data/docs/OcrApi.md +57 -0
- data/docs/Optimize.md +10 -0
- data/docs/OptimizeAction.md +35 -0
- data/docs/OptimizeApi.md +103 -0
- data/docs/OptimizeRes.md +9 -0
- data/docs/Page.md +14 -0
- data/docs/PageSelection.md +10 -0
- data/docs/Pdf4meAction.md +12 -0
- data/docs/Pdf4meDocument.md +32 -0
- data/docs/Pdf4meException.md +8 -0
- data/docs/PdfAAction.md +14 -0
- data/docs/PdfAApi.md +102 -0
- data/docs/PdfFont.md +9 -0
- data/docs/Pricing.md +13 -0
- data/docs/ProduceDocuments.md +14 -0
- data/docs/ProduceDocumentsRes.md +8 -0
- data/docs/ProduceOutput.md +8 -0
- data/docs/RGBSet.md +10 -0
- data/docs/RecognizeDocument.md +10 -0
- data/docs/RecognizeDocumentRes.md +9 -0
- data/docs/Rectangle.md +11 -0
- data/docs/Rotate.md +10 -0
- data/docs/RunJobRes.md +10 -0
- data/docs/SignatureConfig.md +7 -0
- data/docs/Split.md +10 -0
- data/docs/SplitAction.md +11 -0
- data/docs/SplitApi.md +103 -0
- data/docs/SplitRes.md +8 -0
- data/docs/Stamp.md +10 -0
- data/docs/StampAction.md +22 -0
- data/docs/StampApi.md +110 -0
- data/docs/StampRes.md +8 -0
- data/docs/StorageFolder.md +10 -0
- data/docs/Text.md +17 -0
- data/docs/Transform.md +13 -0
- data/docs/Translate.md +9 -0
- data/docs/UserFingerprint.md +9 -0
- data/docs/VersionRes.md +8 -0
- data/docs/java.md +425 -0
- data/git_push.sh +55 -0
- data/lib/pdf4me.rb +124 -0
- data/lib/pdf4me/api/convert_api.rb +130 -0
- data/lib/pdf4me/api/document_api.rb +218 -0
- data/lib/pdf4me/api/extract_api.rb +131 -0
- data/lib/pdf4me/api/image_api.rb +139 -0
- data/lib/pdf4me/api/job_api.rb +223 -0
- data/lib/pdf4me/api/management_api.rb +117 -0
- data/lib/pdf4me/api/merge_api.rb +131 -0
- data/lib/pdf4me/api/ocr_api.rb +74 -0
- data/lib/pdf4me/api/optimize_api.rb +139 -0
- data/lib/pdf4me/api/pdf_a_api.rb +134 -0
- data/lib/pdf4me/api/split_api.rb +135 -0
- data/lib/pdf4me/api/stamp_api.rb +159 -0
- data/lib/pdf4me/api_client.rb +380 -0
- data/lib/pdf4me/api_error.rb +38 -0
- data/lib/pdf4me/configuration.rb +109 -0
- data/lib/pdf4me/models/action_flow.rb +190 -0
- data/lib/pdf4me/models/api_usage_res.rb +219 -0
- data/lib/pdf4me/models/archive_config.rb +226 -0
- data/lib/pdf4me/models/archive_job_req.rb +249 -0
- data/lib/pdf4me/models/archive_job_res.rb +207 -0
- data/lib/pdf4me/models/color.rb +206 -0
- data/lib/pdf4me/models/convert_to_pdf.rb +209 -0
- data/lib/pdf4me/models/convert_to_pdf_action.rb +253 -0
- data/lib/pdf4me/models/convert_to_pdf_res.rb +189 -0
- data/lib/pdf4me/models/create_images.rb +209 -0
- data/lib/pdf4me/models/create_images_res.rb +189 -0
- data/lib/pdf4me/models/create_pdf_a.rb +209 -0
- data/lib/pdf4me/models/create_pdf_a_res.rb +189 -0
- data/lib/pdf4me/models/custom_cms_config.rb +323 -0
- data/lib/pdf4me/models/doc_action.rb +190 -0
- data/lib/pdf4me/models/doc_log.rb +257 -0
- data/lib/pdf4me/models/doc_metadata.rb +285 -0
- data/lib/pdf4me/models/document.rb +285 -0
- data/lib/pdf4me/models/drop_document_req.rb +348 -0
- data/lib/pdf4me/models/drop_document_res.rb +260 -0
- data/lib/pdf4me/models/execution_trigger.rb +206 -0
- data/lib/pdf4me/models/extract.rb +207 -0
- data/lib/pdf4me/models/extract_action.rb +201 -0
- data/lib/pdf4me/models/extract_res.rb +188 -0
- data/lib/pdf4me/models/get_document_list_res.rb +237 -0
- data/lib/pdf4me/models/get_document_req.rb +243 -0
- data/lib/pdf4me/models/get_document_res.rb +246 -0
- data/lib/pdf4me/models/i_form_file.rb +235 -0
- data/lib/pdf4me/models/image.rb +300 -0
- data/lib/pdf4me/models/image_action.rb +513 -0
- data/lib/pdf4me/models/job.rb +213 -0
- data/lib/pdf4me/models/job_config.rb +298 -0
- data/lib/pdf4me/models/job_config_res.rb +193 -0
- data/lib/pdf4me/models/key_value_pair_string_object.rb +197 -0
- data/lib/pdf4me/models/key_value_pair_string_string.rb +197 -0
- data/lib/pdf4me/models/merge.rb +209 -0
- data/lib/pdf4me/models/merge_action.rb +190 -0
- data/lib/pdf4me/models/merge_res.rb +188 -0
- data/lib/pdf4me/models/notification.rb +199 -0
- data/lib/pdf4me/models/ocr_action.rb +259 -0
- data/lib/pdf4me/models/optimize.rb +209 -0
- data/lib/pdf4me/models/optimize_action.rb +514 -0
- data/lib/pdf4me/models/optimize_res.rb +199 -0
- data/lib/pdf4me/models/page.rb +258 -0
- data/lib/pdf4me/models/page_selection.rb +246 -0
- data/lib/pdf4me/models/pdf4me_action.rb +259 -0
- data/lib/pdf4me/models/pdf4me_document.rb +511 -0
- data/lib/pdf4me/models/pdf4me_exception.rb +189 -0
- data/lib/pdf4me/models/pdf_a_action.rb +297 -0
- data/lib/pdf4me/models/pdf_font.rb +213 -0
- data/lib/pdf4me/models/pricing.rb +278 -0
- data/lib/pdf4me/models/produce_documents.rb +251 -0
- data/lib/pdf4me/models/produce_documents_res.rb +191 -0
- data/lib/pdf4me/models/produce_output.rb +221 -0
- data/lib/pdf4me/models/recognize_document.rb +209 -0
- data/lib/pdf4me/models/recognize_document_res.rb +198 -0
- data/lib/pdf4me/models/rectangle.rb +215 -0
- data/lib/pdf4me/models/rgb_set.rb +206 -0
- data/lib/pdf4me/models/rotate.rb +221 -0
- data/lib/pdf4me/models/run_job_res.rb +215 -0
- data/lib/pdf4me/models/signature_config.rb +179 -0
- data/lib/pdf4me/models/split.rb +207 -0
- data/lib/pdf4me/models/split_action.rb +219 -0
- data/lib/pdf4me/models/split_res.rb +190 -0
- data/lib/pdf4me/models/stamp.rb +209 -0
- data/lib/pdf4me/models/stamp_action.rb +387 -0
- data/lib/pdf4me/models/stamp_res.rb +189 -0
- data/lib/pdf4me/models/storage_folder.rb +239 -0
- data/lib/pdf4me/models/text.rb +320 -0
- data/lib/pdf4me/models/transform.rb +263 -0
- data/lib/pdf4me/models/translate.rb +207 -0
- data/lib/pdf4me/models/user_fingerprint.rb +197 -0
- data/lib/pdf4me/models/version_res.rb +188 -0
- data/lib/pdf4me/version.rb +15 -0
- data/pdf4me.gemspec +47 -0
- data/spec/api/convert_api_spec.rb +60 -0
- data/spec/api/document_api_spec.rb +83 -0
- data/spec/api/extract_api_spec.rb +60 -0
- data/spec/api/image_api_spec.rb +62 -0
- data/spec/api/job_api_spec.rb +82 -0
- data/spec/api/management_api_spec.rb +57 -0
- data/spec/api/merge_api_spec.rb +60 -0
- data/spec/api/ocr_api_spec.rb +47 -0
- data/spec/api/optimize_api_spec.rb +60 -0
- data/spec/api/pdf_a_api_spec.rb +60 -0
- data/spec/api/split_api_spec.rb +60 -0
- data/spec/api/stamp_api_spec.rb +63 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/action_flow_spec.rb +42 -0
- data/spec/models/api_usage_res_spec.rb +60 -0
- data/spec/models/archive_config_spec.rb +60 -0
- data/spec/models/archive_job_req_spec.rb +66 -0
- data/spec/models/archive_job_res_spec.rb +48 -0
- data/spec/models/color_spec.rb +54 -0
- data/spec/models/convert_to_pdf_action_spec.rb +62 -0
- data/spec/models/convert_to_pdf_res_spec.rb +42 -0
- data/spec/models/convert_to_pdf_spec.rb +54 -0
- data/spec/models/create_images_res_spec.rb +42 -0
- data/spec/models/create_images_spec.rb +54 -0
- data/spec/models/create_pdf_a_res_spec.rb +42 -0
- data/spec/models/create_pdf_a_spec.rb +54 -0
- data/spec/models/custom_cms_config_spec.rb +132 -0
- data/spec/models/doc_action_spec.rb +42 -0
- data/spec/models/doc_log_spec.rb +70 -0
- data/spec/models/doc_metadata_spec.rb +90 -0
- data/spec/models/document_spec.rb +90 -0
- data/spec/models/drop_document_req_spec.rb +118 -0
- data/spec/models/drop_document_res_spec.rb +84 -0
- data/spec/models/execution_trigger_spec.rb +54 -0
- data/spec/models/extract_action_spec.rb +48 -0
- data/spec/models/extract_res_spec.rb +42 -0
- data/spec/models/extract_spec.rb +54 -0
- data/spec/models/get_document_list_res_spec.rb +72 -0
- data/spec/models/get_document_req_spec.rb +78 -0
- data/spec/models/get_document_res_spec.rb +78 -0
- data/spec/models/i_form_file_spec.rb +72 -0
- data/spec/models/image_action_spec.rb +206 -0
- data/spec/models/image_spec.rb +88 -0
- data/spec/models/job_config_res_spec.rb +42 -0
- data/spec/models/job_config_spec.rb +102 -0
- data/spec/models/job_spec.rb +54 -0
- data/spec/models/key_value_pair_string_object_spec.rb +48 -0
- data/spec/models/key_value_pair_string_string_spec.rb +48 -0
- data/spec/models/merge_action_spec.rb +42 -0
- data/spec/models/merge_res_spec.rb +42 -0
- data/spec/models/merge_spec.rb +54 -0
- data/spec/models/notification_spec.rb +48 -0
- data/spec/models/ocr_action_spec.rb +70 -0
- data/spec/models/optimize_action_spec.rb +228 -0
- data/spec/models/optimize_res_spec.rb +48 -0
- data/spec/models/optimize_spec.rb +54 -0
- data/spec/models/page_selection_spec.rb +58 -0
- data/spec/models/page_spec.rb +78 -0
- data/spec/models/pdf4me_action_spec.rb +70 -0
- data/spec/models/pdf4me_document_spec.rb +202 -0
- data/spec/models/pdf4me_exception_spec.rb +42 -0
- data/spec/models/pdf_a_action_spec.rb +86 -0
- data/spec/models/pdf_font_spec.rb +48 -0
- data/spec/models/pricing_spec.rb +80 -0
- data/spec/models/produce_documents_res_spec.rb +42 -0
- data/spec/models/produce_documents_spec.rb +78 -0
- data/spec/models/produce_output_spec.rb +46 -0
- data/spec/models/recognize_document_res_spec.rb +48 -0
- data/spec/models/recognize_document_spec.rb +54 -0
- data/spec/models/rectangle_spec.rb +60 -0
- data/spec/models/rgb_set_spec.rb +54 -0
- data/spec/models/rotate_spec.rb +54 -0
- data/spec/models/run_job_res_spec.rb +54 -0
- data/spec/models/signature_config_spec.rb +36 -0
- data/spec/models/split_action_spec.rb +60 -0
- data/spec/models/split_res_spec.rb +42 -0
- data/spec/models/split_spec.rb +54 -0
- data/spec/models/stamp_action_spec.rb +142 -0
- data/spec/models/stamp_res_spec.rb +42 -0
- data/spec/models/stamp_spec.rb +54 -0
- data/spec/models/storage_folder_spec.rb +58 -0
- data/spec/models/text_spec.rb +104 -0
- data/spec/models/transform_spec.rb +72 -0
- data/spec/models/translate_spec.rb +48 -0
- data/spec/models/user_fingerprint_spec.rb +48 -0
- data/spec/models/version_res_spec.rb +42 -0
- data/spec/spec_helper.rb +111 -0
- metadata +594 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
=begin
|
2
|
+
#DmsApi
|
3
|
+
|
4
|
+
#No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
5
|
+
|
6
|
+
OpenAPI spec version: v1
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.3.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require "uri"
|
14
|
+
|
15
|
+
module Pdf4me
|
16
|
+
class PdfAApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# @param [Hash] opts the optional parameters
|
26
|
+
# @option opts [String] :pdf_compliance
|
27
|
+
# @option opts [String] :file
|
28
|
+
# @return [File]
|
29
|
+
def create_pdf_a(opts = {})
|
30
|
+
data, _status_code, _headers = create_pdf_a_with_http_info(opts)
|
31
|
+
return data
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# @param [Hash] opts the optional parameters
|
37
|
+
# @option opts [String] :pdf_compliance
|
38
|
+
# @option opts [String] :file
|
39
|
+
# @return [Array<(File, Fixnum, Hash)>] File data, response status code and response headers
|
40
|
+
def create_pdf_a_with_http_info(opts = {})
|
41
|
+
if @api_client.config.debugging
|
42
|
+
@api_client.config.logger.debug "Calling API: PdfAApi.create_pdf_a ..."
|
43
|
+
end
|
44
|
+
if @api_client.config.client_side_validation && opts[:'pdf_compliance'] && !['pdfA1b', 'pdfA1a', 'pdfA2b', 'pdfA2u', 'pdfA2a', 'pdfA3b', 'pdfA3u', 'pdfA3a'].include?(opts[:'pdf_compliance'])
|
45
|
+
fail ArgumentError, 'invalid value for "pdf_compliance", must be one of pdfA1b, pdfA1a, pdfA2b, pdfA2u, pdfA2a, pdfA3b, pdfA3u, pdfA3a'
|
46
|
+
end
|
47
|
+
# resource path
|
48
|
+
local_var_path = "/PdfA/CreatePdfA"
|
49
|
+
|
50
|
+
# query parameters
|
51
|
+
query_params = {}
|
52
|
+
# query_params[:'pdfCompliance'] = opts[:'pdf_compliance'] if !opts[:'pdf_compliance'].nil?
|
53
|
+
# query_params[:'file'] = opts[:'file'] if !opts[:'file'].nil?
|
54
|
+
|
55
|
+
# header parameters
|
56
|
+
header_params = {}
|
57
|
+
# HTTP header 'Accept' (if needed)
|
58
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream'])
|
59
|
+
header_params['Content-Type'] ='multipart/form-data'
|
60
|
+
|
61
|
+
# form parameters
|
62
|
+
form_params = {
|
63
|
+
pdfCompliance: opts[:pdf_compliance],
|
64
|
+
file: opts[:file]
|
65
|
+
}
|
66
|
+
|
67
|
+
# http body (model)
|
68
|
+
post_body = nil
|
69
|
+
auth_names = []
|
70
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
71
|
+
:header_params => header_params,
|
72
|
+
:query_params => query_params,
|
73
|
+
:form_params => form_params,
|
74
|
+
:body => post_body,
|
75
|
+
:auth_names => auth_names,
|
76
|
+
:return_type => 'File')
|
77
|
+
if @api_client.config.debugging
|
78
|
+
@api_client.config.logger.debug "API called: PdfAApi#create_pdf_a\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
79
|
+
end
|
80
|
+
return data, status_code, headers
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
#
|
85
|
+
# @param [Hash] opts the optional parameters
|
86
|
+
# @option opts [CreatePdfA] :req
|
87
|
+
# @return [CreatePdfARes]
|
88
|
+
def pdf_a(opts = {})
|
89
|
+
data, _status_code, _headers = pdf_a_with_http_info(opts)
|
90
|
+
return data
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
#
|
95
|
+
# @param [Hash] opts the optional parameters
|
96
|
+
# @option opts [CreatePdfA] :req
|
97
|
+
# @return [Array<(CreatePdfARes, Fixnum, Hash)>] CreatePdfARes data, response status code and response headers
|
98
|
+
def pdf_a_with_http_info(opts = {})
|
99
|
+
if @api_client.config.debugging
|
100
|
+
@api_client.config.logger.debug "Calling API: PdfAApi.pdf_a ..."
|
101
|
+
end
|
102
|
+
# resource path
|
103
|
+
local_var_path = "/PdfA/PdfA"
|
104
|
+
|
105
|
+
# query parameters
|
106
|
+
query_params = {}
|
107
|
+
|
108
|
+
# header parameters
|
109
|
+
header_params = {}
|
110
|
+
# HTTP header 'Accept' (if needed)
|
111
|
+
header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json', 'text/json', 'application/bson'])
|
112
|
+
# HTTP header 'Content-Type'
|
113
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json-patch+json', 'application/json', 'text/json', 'application/*+json', 'application/bson'])
|
114
|
+
|
115
|
+
# form parameters
|
116
|
+
form_params = {}
|
117
|
+
|
118
|
+
# http body (model)
|
119
|
+
post_body = @api_client.object_to_http_body(opts[:'req'])
|
120
|
+
auth_names = []
|
121
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
122
|
+
:header_params => header_params,
|
123
|
+
:query_params => query_params,
|
124
|
+
:form_params => form_params,
|
125
|
+
:body => post_body,
|
126
|
+
:auth_names => auth_names,
|
127
|
+
:return_type => 'CreatePdfARes')
|
128
|
+
if @api_client.config.debugging
|
129
|
+
@api_client.config.logger.debug "API called: PdfAApi#pdf_a\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
130
|
+
end
|
131
|
+
return data, status_code, headers
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
=begin
|
2
|
+
#DmsApi
|
3
|
+
|
4
|
+
#No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
5
|
+
|
6
|
+
OpenAPI spec version: v1
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.3.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require "uri"
|
14
|
+
|
15
|
+
module Pdf4me
|
16
|
+
class SplitApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# @param [Hash] opts the optional parameters
|
26
|
+
# @option opts [Split] :req
|
27
|
+
# @return [SplitRes]
|
28
|
+
def split(opts = {})
|
29
|
+
data, _status_code, _headers = split_with_http_info(opts)
|
30
|
+
return data
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# @param [Hash] opts the optional parameters
|
36
|
+
# @option opts [Split] :req
|
37
|
+
# @return [Array<(SplitRes, Fixnum, Hash)>] SplitRes data, response status code and response headers
|
38
|
+
def split_with_http_info(opts = {})
|
39
|
+
if @api_client.config.debugging
|
40
|
+
@api_client.config.logger.debug "Calling API: SplitApi.split ..."
|
41
|
+
end
|
42
|
+
# resource path
|
43
|
+
local_var_path = "/Split/Split"
|
44
|
+
|
45
|
+
# query parameters
|
46
|
+
query_params = {}
|
47
|
+
|
48
|
+
# header parameters
|
49
|
+
header_params = {}
|
50
|
+
# HTTP header 'Accept' (if needed)
|
51
|
+
header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json', 'text/json', 'application/bson'])
|
52
|
+
# HTTP header 'Content-Type'
|
53
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json-patch+json', 'application/json', 'text/json', 'application/*+json', 'application/bson'])
|
54
|
+
|
55
|
+
# form parameters
|
56
|
+
form_params = {}
|
57
|
+
|
58
|
+
# http body (model)
|
59
|
+
post_body = @api_client.object_to_http_body(opts[:'req'])
|
60
|
+
auth_names = []
|
61
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
62
|
+
:header_params => header_params,
|
63
|
+
:query_params => query_params,
|
64
|
+
:form_params => form_params,
|
65
|
+
:body => post_body,
|
66
|
+
:auth_names => auth_names,
|
67
|
+
:return_type => 'SplitRes')
|
68
|
+
if @api_client.config.debugging
|
69
|
+
@api_client.config.logger.debug "API called: SplitApi#split\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
70
|
+
end
|
71
|
+
return data, status_code, headers
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
#
|
76
|
+
# @param page_nr
|
77
|
+
# @param [Hash] opts the optional parameters
|
78
|
+
# @option opts [String] :file
|
79
|
+
# @return [SplitRes]
|
80
|
+
def split_by_page_nr(page_nr, opts = {})
|
81
|
+
data, _status_code, _headers = split_by_page_nr_with_http_info(page_nr, opts)
|
82
|
+
return data
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
#
|
87
|
+
# @param page_nr
|
88
|
+
# @param [Hash] opts the optional parameters
|
89
|
+
# @option opts [String] :file
|
90
|
+
# @return [Array<(SplitRes, Fixnum, Hash)>] SplitRes data, response status code and response headers
|
91
|
+
def split_by_page_nr_with_http_info(page_nr, opts = {})
|
92
|
+
if @api_client.config.debugging
|
93
|
+
@api_client.config.logger.debug "Calling API: SplitApi.split_by_page_nr ..."
|
94
|
+
end
|
95
|
+
# verify the required parameter 'page_nr' is set
|
96
|
+
if @api_client.config.client_side_validation && page_nr.nil?
|
97
|
+
fail ArgumentError, "Missing the required parameter 'page_nr' when calling SplitApi.split_by_page_nr"
|
98
|
+
end
|
99
|
+
# resource path
|
100
|
+
local_var_path = "/Split/SplitByPageNr"
|
101
|
+
|
102
|
+
# query parameters
|
103
|
+
query_params = {}
|
104
|
+
# query_params[:'pageNr'] = page_nr
|
105
|
+
# query_params[:'file'] = opts[:'file'] if !opts[:'file'].nil?
|
106
|
+
|
107
|
+
# header parameters
|
108
|
+
header_params = {}
|
109
|
+
# HTTP header 'Accept' (if needed)
|
110
|
+
header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json', 'text/json', 'application/bson'])
|
111
|
+
header_params['Content-Type'] ='multipart/form-data'
|
112
|
+
|
113
|
+
# form parameters
|
114
|
+
form_params = {
|
115
|
+
pageNr: page_nr,
|
116
|
+
file: opts[:file]
|
117
|
+
}
|
118
|
+
|
119
|
+
# http body (model)
|
120
|
+
post_body = nil
|
121
|
+
auth_names = []
|
122
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
123
|
+
:header_params => header_params,
|
124
|
+
:query_params => query_params,
|
125
|
+
:form_params => form_params,
|
126
|
+
:body => post_body,
|
127
|
+
:auth_names => auth_names,
|
128
|
+
:return_type => 'SplitRes')
|
129
|
+
if @api_client.config.debugging
|
130
|
+
@api_client.config.logger.debug "API called: SplitApi#split_by_page_nr\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
131
|
+
end
|
132
|
+
return data, status_code, headers
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
=begin
|
2
|
+
#DmsApi
|
3
|
+
|
4
|
+
#No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
5
|
+
|
6
|
+
OpenAPI spec version: v1
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.3.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require "uri"
|
14
|
+
|
15
|
+
module Pdf4me
|
16
|
+
class StampApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# @param [Hash] opts the optional parameters
|
26
|
+
# @option opts [Stamp] :req
|
27
|
+
# @return [StampRes]
|
28
|
+
def stamp(opts = {})
|
29
|
+
data, _status_code, _headers = stamp_with_http_info(opts)
|
30
|
+
return data
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# @param [Hash] opts the optional parameters
|
36
|
+
# @option opts [Stamp] :req
|
37
|
+
# @return [Array<(StampRes, Fixnum, Hash)>] StampRes data, response status code and response headers
|
38
|
+
def stamp_with_http_info(opts = {})
|
39
|
+
if @api_client.config.debugging
|
40
|
+
@api_client.config.logger.debug "Calling API: StampApi.stamp ..."
|
41
|
+
end
|
42
|
+
# resource path
|
43
|
+
local_var_path = "/Stamp/Stamp"
|
44
|
+
|
45
|
+
# query parameters
|
46
|
+
query_params = {}
|
47
|
+
|
48
|
+
# header parameters
|
49
|
+
header_params = {}
|
50
|
+
# HTTP header 'Accept' (if needed)
|
51
|
+
header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json', 'text/json', 'application/bson'])
|
52
|
+
# HTTP header 'Content-Type'
|
53
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json-patch+json', 'application/json', 'text/json', 'application/*+json', 'application/bson'])
|
54
|
+
|
55
|
+
# form parameters
|
56
|
+
form_params = {}
|
57
|
+
|
58
|
+
# http body (model)
|
59
|
+
post_body = @api_client.object_to_http_body(opts[:'req'])
|
60
|
+
auth_names = []
|
61
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
62
|
+
:header_params => header_params,
|
63
|
+
:query_params => query_params,
|
64
|
+
:form_params => form_params,
|
65
|
+
:body => post_body,
|
66
|
+
:auth_names => auth_names,
|
67
|
+
:return_type => 'StampRes')
|
68
|
+
if @api_client.config.debugging
|
69
|
+
@api_client.config.logger.debug "API called: StampApi#stamp\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
70
|
+
end
|
71
|
+
return data, status_code, headers
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
#
|
76
|
+
# @param align_x
|
77
|
+
# @param align_y
|
78
|
+
# @param [Hash] opts the optional parameters
|
79
|
+
# @option opts [String] :text
|
80
|
+
# @option opts [String] :pages
|
81
|
+
# @option opts [String] :file
|
82
|
+
# @return [File]
|
83
|
+
def text_stamp(align_x, align_y, opts = {})
|
84
|
+
data, _status_code, _headers = text_stamp_with_http_info(align_x, align_y, opts)
|
85
|
+
return data
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
#
|
90
|
+
# @param align_x
|
91
|
+
# @param align_y
|
92
|
+
# @param [Hash] opts the optional parameters
|
93
|
+
# @option opts [String] :text
|
94
|
+
# @option opts [String] :pages
|
95
|
+
# @option opts [String] :file
|
96
|
+
# @return [Array<(File, Fixnum, Hash)>] File data, response status code and response headers
|
97
|
+
def text_stamp_with_http_info(align_x, align_y, opts = {})
|
98
|
+
if @api_client.config.debugging
|
99
|
+
@api_client.config.logger.debug "Calling API: StampApi.text_stamp ..."
|
100
|
+
end
|
101
|
+
# verify the required parameter 'align_x' is set
|
102
|
+
if @api_client.config.client_side_validation && align_x.nil?
|
103
|
+
fail ArgumentError, "Missing the required parameter 'align_x' when calling StampApi.text_stamp"
|
104
|
+
end
|
105
|
+
# verify enum value
|
106
|
+
if @api_client.config.client_side_validation && !['left', 'center', 'right'].include?(align_x)
|
107
|
+
fail ArgumentError, "invalid value for 'align_x', must be one of left, center, right"
|
108
|
+
end
|
109
|
+
# verify the required parameter 'align_y' is set
|
110
|
+
if @api_client.config.client_side_validation && align_y.nil?
|
111
|
+
fail ArgumentError, "Missing the required parameter 'align_y' when calling StampApi.text_stamp"
|
112
|
+
end
|
113
|
+
# verify enum value
|
114
|
+
if @api_client.config.client_side_validation && !['top', 'middle', 'bottom'].include?(align_y)
|
115
|
+
fail ArgumentError, "invalid value for 'align_y', must be one of top, middle, bottom"
|
116
|
+
end
|
117
|
+
# resource path
|
118
|
+
local_var_path = "/Stamp/TextStamp"
|
119
|
+
|
120
|
+
# query parameters
|
121
|
+
query_params = {}
|
122
|
+
# query_params[:'alignX'] = align_x
|
123
|
+
# query_params[:'alignY'] = align_y
|
124
|
+
# query_params[:'text'] = opts[:'text'] if !opts[:'text'].nil?
|
125
|
+
# query_params[:'pages'] = opts[:'pages'] if !opts[:'pages'].nil?
|
126
|
+
# query_params[:'file'] = opts[:'file'] if !opts[:'file'].nil?
|
127
|
+
|
128
|
+
# header parameters
|
129
|
+
header_params = {}
|
130
|
+
# HTTP header 'Accept' (if needed)
|
131
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream'])
|
132
|
+
header_params['Content-Type'] ='multipart/form-data'
|
133
|
+
|
134
|
+
# form parameters
|
135
|
+
form_params = {
|
136
|
+
alignX: align_x,
|
137
|
+
alignY: align_y,
|
138
|
+
text: opts[:text],
|
139
|
+
pages: opts[:pages],
|
140
|
+
file: opts[:file]
|
141
|
+
}
|
142
|
+
|
143
|
+
# http body (model)
|
144
|
+
post_body = nil
|
145
|
+
auth_names = []
|
146
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
147
|
+
:header_params => header_params,
|
148
|
+
:query_params => query_params,
|
149
|
+
:form_params => form_params,
|
150
|
+
:body => post_body,
|
151
|
+
:auth_names => auth_names,
|
152
|
+
:return_type => 'File')
|
153
|
+
if @api_client.config.debugging
|
154
|
+
@api_client.config.logger.debug "API called: StampApi#text_stamp\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
155
|
+
end
|
156
|
+
return data, status_code, headers
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,380 @@
|
|
1
|
+
=begin
|
2
|
+
#DmsApi
|
3
|
+
|
4
|
+
#No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
5
|
+
|
6
|
+
OpenAPI spec version: v1
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.3.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'typhoeus'
|
18
|
+
require 'uri'
|
19
|
+
|
20
|
+
module Pdf4me
|
21
|
+
class ApiClient
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
23
|
+
attr_accessor :config
|
24
|
+
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :default_headers
|
29
|
+
|
30
|
+
# Initializes the ApiClient
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
|
+
def initialize(config = Configuration.default)
|
33
|
+
@config = config
|
34
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
35
|
+
@default_headers = {
|
36
|
+
'Content-Type' => "application/json",
|
37
|
+
'User-Agent' => @user_agent,
|
38
|
+
'Authorization' => "Bearer #{config.access_token}"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.default
|
43
|
+
@@default ||= ApiClient.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# Call an API with given options.
|
47
|
+
#
|
48
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
49
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
50
|
+
def call_api(http_method, path, opts = {})
|
51
|
+
request = build_request(http_method, path, opts)
|
52
|
+
response = request.run
|
53
|
+
|
54
|
+
if @config.debugging
|
55
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
unless response.success?
|
59
|
+
if response.timed_out?
|
60
|
+
fail ApiError.new('Connection timed out')
|
61
|
+
elsif response.code == 0
|
62
|
+
# Errors from libcurl will be made visible here
|
63
|
+
fail ApiError.new(:code => 0,
|
64
|
+
:message => response.return_message)
|
65
|
+
else
|
66
|
+
fail ApiError.new(:code => response.code,
|
67
|
+
:response_headers => response.headers,
|
68
|
+
:response_body => response.body),
|
69
|
+
response.status_message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if opts[:return_type]
|
74
|
+
data = deserialize(response, opts[:return_type])
|
75
|
+
else
|
76
|
+
data = nil
|
77
|
+
end
|
78
|
+
return data, response.code, response.headers
|
79
|
+
end
|
80
|
+
|
81
|
+
# Builds the HTTP request
|
82
|
+
#
|
83
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
84
|
+
# @param [String] path URL path (e.g. /account/new)
|
85
|
+
# @option opts [Hash] :header_params Header parameters
|
86
|
+
# @option opts [Hash] :query_params Query parameters
|
87
|
+
# @option opts [Hash] :form_params Query parameters
|
88
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
89
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
90
|
+
def build_request(http_method, path, opts = {})
|
91
|
+
url = build_request_url(path)
|
92
|
+
http_method = http_method.to_sym.downcase
|
93
|
+
|
94
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
95
|
+
query_params = opts[:query_params] || {}
|
96
|
+
form_params = opts[:form_params] || {}
|
97
|
+
|
98
|
+
req_opts = {
|
99
|
+
:method => http_method,
|
100
|
+
:headers => header_params,
|
101
|
+
:params => query_params,
|
102
|
+
:params_encoding => @config.params_encoding,
|
103
|
+
:timeout => @config.timeout,
|
104
|
+
:ssl_verifypeer => true,
|
105
|
+
:ssl_verifyhost => 2,
|
106
|
+
:verbose => @config.debugging
|
107
|
+
}
|
108
|
+
|
109
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
110
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
111
|
+
req_opts.update :body => req_body
|
112
|
+
if @config.debugging
|
113
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
request = Typhoeus::Request.new(url, req_opts)
|
118
|
+
download_file(request) if opts[:return_type] == 'File'
|
119
|
+
request
|
120
|
+
end
|
121
|
+
|
122
|
+
# Check if the given MIME is a JSON MIME.
|
123
|
+
# JSON MIME examples:
|
124
|
+
# application/json
|
125
|
+
# application/json; charset=UTF8
|
126
|
+
# APPLICATION/JSON
|
127
|
+
# */*
|
128
|
+
# @param [String] mime MIME
|
129
|
+
# @return [Boolean] True if the MIME is application/json
|
130
|
+
def json_mime?(mime)
|
131
|
+
(mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
# Deserialize the response to the given return type.
|
135
|
+
#
|
136
|
+
# @param [Response] response HTTP response
|
137
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
138
|
+
def deserialize(response, return_type)
|
139
|
+
body = response.body
|
140
|
+
|
141
|
+
# handle file downloading - return the File instance processed in request callbacks
|
142
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
143
|
+
return @tempfile if return_type == 'File'
|
144
|
+
|
145
|
+
return nil if body.nil? || body.empty?
|
146
|
+
|
147
|
+
# return response body directly for String return type
|
148
|
+
return body if return_type == 'String'
|
149
|
+
|
150
|
+
# ensuring a default content type
|
151
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
152
|
+
|
153
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
154
|
+
|
155
|
+
begin
|
156
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
157
|
+
rescue JSON::ParserError => e
|
158
|
+
if %w(String Date DateTime).include?(return_type)
|
159
|
+
data = body
|
160
|
+
else
|
161
|
+
raise e
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
convert_to_type data, return_type
|
166
|
+
end
|
167
|
+
|
168
|
+
# Convert data to the given return type.
|
169
|
+
# @param [Object] data Data to be converted
|
170
|
+
# @param [String] return_type Return type
|
171
|
+
# @return [Mixed] Data in a particular type
|
172
|
+
def convert_to_type(data, return_type)
|
173
|
+
return nil if data.nil?
|
174
|
+
case return_type
|
175
|
+
when 'String'
|
176
|
+
data.to_s
|
177
|
+
when 'Integer'
|
178
|
+
data.to_i
|
179
|
+
when 'Float'
|
180
|
+
data.to_f
|
181
|
+
when 'BOOLEAN'
|
182
|
+
data == true
|
183
|
+
when 'DateTime'
|
184
|
+
# parse date time (expecting ISO 8601 format)
|
185
|
+
DateTime.parse data
|
186
|
+
when 'Date'
|
187
|
+
# parse date time (expecting ISO 8601 format)
|
188
|
+
Date.parse data
|
189
|
+
when 'Object'
|
190
|
+
# generic object (usually a Hash), return directly
|
191
|
+
data
|
192
|
+
when /\AArray<(.+)>\z/
|
193
|
+
# e.g. Array<Pet>
|
194
|
+
sub_type = $1
|
195
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
196
|
+
when /\AHash\<String, (.+)\>\z/
|
197
|
+
# e.g. Hash<String, Integer>
|
198
|
+
sub_type = $1
|
199
|
+
{}.tap do |hash|
|
200
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
201
|
+
end
|
202
|
+
else
|
203
|
+
# models, e.g. Pet
|
204
|
+
Pdf4me.const_get(return_type).new.tap do |model|
|
205
|
+
model.build_from_hash data
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
211
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
212
|
+
# The response body is written to the file in chunks in order to handle files which
|
213
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
214
|
+
# process can use.
|
215
|
+
#
|
216
|
+
# @see Configuration#temp_folder_path
|
217
|
+
def download_file(request)
|
218
|
+
tempfile = nil
|
219
|
+
encoding = nil
|
220
|
+
request.on_headers do |response|
|
221
|
+
content_disposition = response.headers['Content-Disposition']
|
222
|
+
if content_disposition and content_disposition =~ /filename=/i
|
223
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
224
|
+
prefix = sanitize_filename(filename)
|
225
|
+
else
|
226
|
+
prefix = 'download-'
|
227
|
+
end
|
228
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
229
|
+
encoding = response.body.encoding
|
230
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
231
|
+
@tempfile = tempfile
|
232
|
+
end
|
233
|
+
request.on_body do |chunk|
|
234
|
+
chunk.force_encoding(encoding)
|
235
|
+
tempfile.write(chunk)
|
236
|
+
end
|
237
|
+
request.on_complete do |response|
|
238
|
+
tempfile.close
|
239
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
240
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
241
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
242
|
+
"explicitly with `tempfile.delete`"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
# Sanitize filename by removing path.
|
247
|
+
# e.g. ../../sun.gif becomes sun.gif
|
248
|
+
#
|
249
|
+
# @param [String] filename the filename to be sanitized
|
250
|
+
# @return [String] the sanitized filename
|
251
|
+
def sanitize_filename(filename)
|
252
|
+
filename.gsub(/.*[\/\\]/, '')
|
253
|
+
end
|
254
|
+
|
255
|
+
def build_request_url(path)
|
256
|
+
# Add leading and trailing slashes to path
|
257
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
258
|
+
URI.encode(@config.base_url + path)
|
259
|
+
end
|
260
|
+
|
261
|
+
# Builds the HTTP request body
|
262
|
+
#
|
263
|
+
# @param [Hash] header_params Header parameters
|
264
|
+
# @param [Hash] form_params Query parameters
|
265
|
+
# @param [Object] body HTTP body (JSON/XML)
|
266
|
+
# @return [String] HTTP body data in the form of string
|
267
|
+
def build_request_body(header_params, form_params, body)
|
268
|
+
# http form
|
269
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
270
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
271
|
+
data = {}
|
272
|
+
form_params.each do |key, value|
|
273
|
+
case value
|
274
|
+
when ::File, ::Array, nil
|
275
|
+
# let typhoeus handle File, Array and nil parameters
|
276
|
+
data[key] = value
|
277
|
+
else
|
278
|
+
data[key] = value.to_s
|
279
|
+
end
|
280
|
+
end
|
281
|
+
elsif body
|
282
|
+
data = body.is_a?(String) ? body : body.to_json
|
283
|
+
else
|
284
|
+
data = nil
|
285
|
+
end
|
286
|
+
data
|
287
|
+
end
|
288
|
+
|
289
|
+
# Update hearder and query params based on authentication settings.
|
290
|
+
#
|
291
|
+
# @param [Hash] header_params Header parameters
|
292
|
+
# @param [Hash] query_params Query parameters
|
293
|
+
# @param [String] auth_names Authentication scheme name
|
294
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
295
|
+
Array(auth_names).each do |auth_name|
|
296
|
+
auth_setting = @config.auth_settings[auth_name]
|
297
|
+
next unless auth_setting
|
298
|
+
case auth_setting[:in]
|
299
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
300
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
301
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
# Sets user agent in HTTP header
|
307
|
+
#
|
308
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
309
|
+
def user_agent=(user_agent)
|
310
|
+
@user_agent = user_agent
|
311
|
+
@default_headers['User-Agent'] = @user_agent
|
312
|
+
end
|
313
|
+
|
314
|
+
# Return Accept header based on an array of accepts provided.
|
315
|
+
# @param [Array] accepts array for Accept
|
316
|
+
# @return [String] the Accept header (e.g. application/json)
|
317
|
+
def select_header_accept(accepts)
|
318
|
+
return nil if accepts.nil? || accepts.empty?
|
319
|
+
# use JSON when present, otherwise use all of the provided
|
320
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
321
|
+
return json_accept || accepts.join(',')
|
322
|
+
end
|
323
|
+
|
324
|
+
# Return Content-Type header based on an array of content types provided.
|
325
|
+
# @param [Array] content_types array for Content-Type
|
326
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
327
|
+
def select_header_content_type(content_types)
|
328
|
+
# use application/json by default
|
329
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
330
|
+
# use JSON when present, otherwise use the first one
|
331
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
332
|
+
return json_content_type || content_types.first
|
333
|
+
end
|
334
|
+
|
335
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
336
|
+
# @param [Object] model object to be converted into JSON string
|
337
|
+
# @return [String] JSON string representation of the object
|
338
|
+
def object_to_http_body(model)
|
339
|
+
return model if model.nil? || model.is_a?(String)
|
340
|
+
local_body = nil
|
341
|
+
if model.is_a?(Array)
|
342
|
+
local_body = model.map{|m| object_to_hash(m) }
|
343
|
+
else
|
344
|
+
local_body = object_to_hash(model)
|
345
|
+
end
|
346
|
+
local_body.to_json
|
347
|
+
end
|
348
|
+
|
349
|
+
# Convert object(non-array) to hash.
|
350
|
+
# @param [Object] obj object to be converted into JSON string
|
351
|
+
# @return [String] JSON string representation of the object
|
352
|
+
def object_to_hash(obj)
|
353
|
+
if obj.respond_to?(:to_hash)
|
354
|
+
obj.to_hash
|
355
|
+
else
|
356
|
+
obj
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
# Build parameter value according to the given collection format.
|
361
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
362
|
+
def build_collection_param(param, collection_format)
|
363
|
+
case collection_format
|
364
|
+
when :csv
|
365
|
+
param.join(',')
|
366
|
+
when :ssv
|
367
|
+
param.join(' ')
|
368
|
+
when :tsv
|
369
|
+
param.join("\t")
|
370
|
+
when :pipes
|
371
|
+
param.join('|')
|
372
|
+
when :multi
|
373
|
+
# return the array directly as typhoeus will handle it as expected
|
374
|
+
param
|
375
|
+
else
|
376
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|