aspose_email_cloud 19.11.0 → 20.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aspose-email-cloud.rb +155 -2
- data/lib/aspose-email-cloud/api/email_api.rb +1039 -577
- data/lib/aspose-email-cloud/api_client.rb +385 -381
- data/lib/aspose-email-cloud/api_error.rb +41 -41
- data/lib/aspose-email-cloud/configuration.rb +240 -236
- data/lib/aspose-email-cloud/models/account_base_request.rb +154 -141
- data/lib/aspose-email-cloud/models/add_attachment_request.rb +150 -143
- data/lib/aspose-email-cloud/models/ai_bcr_base64_image.rb +231 -0
- data/lib/aspose-email-cloud/models/ai_bcr_base64_rq.rb +228 -0
- data/lib/aspose-email-cloud/models/ai_bcr_image.rb +218 -0
- data/lib/aspose-email-cloud/models/ai_bcr_image_storage_file.rb +231 -0
- data/lib/aspose-email-cloud/models/ai_bcr_ocr_data.rb +256 -0
- data/lib/aspose-email-cloud/models/ai_bcr_ocr_data_part.rb +300 -0
- data/lib/aspose-email-cloud/models/ai_bcr_options.rb +226 -0
- data/lib/aspose-email-cloud/models/ai_bcr_parse_ocr_data_rq.rb +233 -0
- data/lib/aspose-email-cloud/models/ai_bcr_parse_storage_rq.rb +251 -0
- data/lib/aspose-email-cloud/models/ai_bcr_rq.rb +213 -0
- data/lib/aspose-email-cloud/models/ai_bcr_storage_image_rq.rb +233 -0
- data/lib/aspose-email-cloud/models/ai_name_component.rb +267 -0
- data/lib/aspose-email-cloud/models/ai_name_cultural_context.rb +270 -0
- data/lib/aspose-email-cloud/models/ai_name_extracted.rb +233 -0
- data/lib/aspose-email-cloud/models/ai_name_extracted_component.rb +231 -0
- data/lib/aspose-email-cloud/models/ai_name_formatted.rb +226 -0
- data/lib/aspose-email-cloud/models/ai_name_gender_hypothesis.rb +236 -0
- data/lib/aspose-email-cloud/models/ai_name_match_result.rb +233 -0
- data/lib/aspose-email-cloud/models/ai_name_mismatch.rb +249 -0
- data/lib/aspose-email-cloud/models/ai_name_parsed_match_rq.rb +266 -0
- data/lib/aspose-email-cloud/models/ai_name_parsed_rq.rb +246 -0
- data/lib/aspose-email-cloud/models/ai_name_weighted.rb +231 -0
- data/lib/aspose-email-cloud/models/ai_name_weighted_variants.rb +228 -0
- data/lib/aspose-email-cloud/models/alternate_view.rb +282 -0
- data/lib/aspose-email-cloud/models/append_email_account_base_request.rb +162 -144
- data/lib/aspose-email-cloud/models/append_email_base_request.rb +167 -147
- data/lib/aspose-email-cloud/models/append_email_mime_base_request.rb +166 -146
- data/lib/aspose-email-cloud/models/append_email_model_rq.rb +336 -0
- data/lib/aspose-email-cloud/models/associated_person.rb +244 -0
- data/lib/aspose-email-cloud/models/attachment.rb +324 -0
- data/lib/aspose-email-cloud/models/attachment_base.rb +254 -0
- data/lib/aspose-email-cloud/models/base_object.rb +91 -84
- data/lib/aspose-email-cloud/models/calendar_dto.rb +557 -0
- data/lib/aspose-email-cloud/models/calendar_dto_alternate_rq.rb +268 -0
- data/lib/aspose-email-cloud/models/calendar_dto_list.rb +215 -0
- data/lib/aspose-email-cloud/models/calendar_reminder.rb +318 -0
- data/lib/aspose-email-cloud/models/contact_dto.rb +699 -0
- data/lib/aspose-email-cloud/models/contact_dto_list.rb +215 -0
- data/lib/aspose-email-cloud/models/contact_photo.rb +231 -0
- data/lib/aspose-email-cloud/models/content_type.rb +267 -0
- data/lib/aspose-email-cloud/models/content_type_parameter.rb +226 -0
- data/lib/aspose-email-cloud/models/create_email_request.rb +150 -143
- data/lib/aspose-email-cloud/models/create_folder_base_request.rb +162 -146
- data/lib/aspose-email-cloud/models/customer_event.rb +231 -0
- data/lib/aspose-email-cloud/models/delete_email_thread_account_rq.rb +276 -0
- data/lib/aspose-email-cloud/models/delete_folder_base_request.rb +162 -146
- data/lib/aspose-email-cloud/models/delete_message_base_request.rb +177 -148
- data/lib/aspose-email-cloud/models/disc_usage.rb +149 -143
- data/lib/aspose-email-cloud/models/discover_email_config_oauth.rb +391 -0
- data/lib/aspose-email-cloud/models/discover_email_config_password.rb +304 -0
- data/lib/aspose-email-cloud/models/discover_email_config_rq.rb +268 -0
- data/lib/aspose-email-cloud/models/email_account_config.rb +323 -0
- data/lib/aspose-email-cloud/models/email_account_config_list.rb +215 -0
- data/lib/aspose-email-cloud/models/email_account_request.rb +210 -155
- data/lib/aspose-email-cloud/models/email_address.rb +283 -0
- data/lib/aspose-email-cloud/models/email_client_account.rb +350 -0
- data/lib/aspose-email-cloud/models/email_client_account_credentials.rb +261 -0
- data/lib/aspose-email-cloud/models/email_client_account_oauth_credentials.rb +385 -0
- data/lib/aspose-email-cloud/models/email_client_account_password_credentials.rb +298 -0
- data/lib/aspose-email-cloud/models/email_client_multi_account.rb +233 -0
- data/lib/aspose-email-cloud/models/email_document.rb +150 -143
- data/lib/aspose-email-cloud/models/email_document_response.rb +146 -141
- data/lib/aspose-email-cloud/models/email_dto.rb +681 -0
- data/lib/aspose-email-cloud/models/email_dto_list.rb +215 -0
- data/lib/aspose-email-cloud/models/email_properties.rb +150 -142
- data/lib/aspose-email-cloud/models/email_property.rb +154 -142
- data/lib/aspose-email-cloud/models/email_property_response.rb +146 -141
- data/lib/aspose-email-cloud/models/email_thread.rb +254 -0
- data/lib/aspose-email-cloud/models/email_thread_list.rb +215 -0
- data/lib/aspose-email-cloud/models/email_thread_read_flag_rq.rb +294 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_associated_person_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_email_address_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_event_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_instant_messenger_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_phone_number_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_postal_address_category.rb +230 -0
- data/lib/aspose-email-cloud/models/enum_with_custom_of_url_category.rb +230 -0
- data/lib/aspose-email-cloud/models/error.rb +157 -147
- data/lib/aspose-email-cloud/models/error_details.rb +149 -143
- data/lib/aspose-email-cloud/models/file_version.rb +169 -153
- data/lib/aspose-email-cloud/models/file_versions.rb +145 -141
- data/lib/aspose-email-cloud/models/files_list.rb +145 -141
- data/lib/aspose-email-cloud/models/files_upload_result.rb +149 -143
- data/lib/aspose-email-cloud/models/hierarchical_object.rb +106 -97
- data/lib/aspose-email-cloud/models/hierarchical_object_request.rb +150 -143
- data/lib/aspose-email-cloud/models/hierarchical_object_response.rb +150 -143
- data/lib/aspose-email-cloud/models/indexed_hierarchical_object.rb +124 -113
- data/lib/aspose-email-cloud/models/indexed_primitive_object.rb +122 -111
- data/lib/aspose-email-cloud/models/instant_messenger_address.rb +244 -0
- data/lib/aspose-email-cloud/models/link.rb +158 -147
- data/lib/aspose-email-cloud/models/linked_resource.rb +267 -0
- data/lib/aspose-email-cloud/models/list_response_of_ai_bcr_ocr_data.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_ai_name_component.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_ai_name_extracted.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_ai_name_gender_hypothesis.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_contact_dto.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_email_account_config.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_email_dto.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_email_thread.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_hierarchical_object.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_hierarchical_object_response.rb +145 -139
- data/lib/aspose-email-cloud/models/list_response_of_mail_server_folder.rb +145 -139
- data/lib/aspose-email-cloud/models/list_response_of_storage_file_location.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_storage_model_of_calendar_dto.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_storage_model_of_contact_dto.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_storage_model_of_email_dto.rb +214 -0
- data/lib/aspose-email-cloud/models/list_response_of_string.rb +145 -139
- data/lib/aspose-email-cloud/models/mail_address.rb +257 -0
- data/lib/aspose-email-cloud/models/mail_server_folder.rb +150 -143
- data/lib/aspose-email-cloud/models/mime_response.rb +146 -141
- data/lib/aspose-email-cloud/models/move_email_message_rq.rb +302 -0
- data/lib/aspose-email-cloud/models/move_email_thread_rq.rb +276 -0
- data/lib/aspose-email-cloud/models/name_value_pair.rb +226 -0
- data/lib/aspose-email-cloud/models/object_exist.rb +149 -143
- data/lib/aspose-email-cloud/models/phone_number.rb +244 -0
- data/lib/aspose-email-cloud/models/postal_address.rb +353 -0
- data/lib/aspose-email-cloud/models/primitive_object.rb +104 -95
- data/lib/aspose-email-cloud/models/reminder_attendee.rb +213 -0
- data/lib/aspose-email-cloud/models/reminder_trigger.rb +249 -0
- data/lib/aspose-email-cloud/models/requests/add_calendar_attachment_request_data.rb +99 -89
- data/lib/aspose-email-cloud/models/requests/add_contact_attachment_request_data.rb +109 -101
- data/lib/aspose-email-cloud/models/requests/add_email_attachment_request_data.rb +99 -89
- data/lib/aspose-email-cloud/models/requests/add_mapi_attachment_request_data.rb +99 -89
- data/lib/aspose-email-cloud/models/requests/ai_bcr_ocr_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_bcr_ocr_storage_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_bcr_parse_model_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_bcr_parse_ocr_data_model_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_bcr_parse_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_bcr_parse_storage_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_complete_request_data.rb +110 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_expand_parsed_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_expand_request_data.rb +110 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_format_parsed_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_format_request_data.rb +116 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_genderize_parsed_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_genderize_request_data.rb +110 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_match_parsed_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_match_request_data.rb +121 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_parse_email_address_request_data.rb +110 -0
- data/lib/aspose-email-cloud/models/requests/ai_name_parse_request_data.rb +110 -0
- data/lib/aspose-email-cloud/models/requests/append_email_message_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/append_email_model_message_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/append_mime_message_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/convert_calendar_model_to_alternate_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/convert_calendar_model_to_file_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/convert_calendar_request_data.rb +90 -0
- data/lib/aspose-email-cloud/models/requests/convert_contact_model_to_file_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/convert_contact_request_data.rb +100 -0
- data/lib/aspose-email-cloud/models/requests/convert_email_model_to_file_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/convert_email_request_data.rb +90 -0
- data/lib/aspose-email-cloud/models/requests/copy_file_request_data.rb +107 -92
- data/lib/aspose-email-cloud/models/requests/copy_folder_request_data.rb +101 -89
- data/lib/aspose-email-cloud/models/requests/create_calendar_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/create_contact_request_data.rb +99 -94
- data/lib/aspose-email-cloud/models/requests/create_email_folder_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/create_email_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/create_folder_request_data.rb +84 -78
- data/lib/aspose-email-cloud/models/requests/create_mapi_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/delete_calendar_property_request_data.rb +109 -96
- data/lib/aspose-email-cloud/models/requests/delete_contact_property_request_data.rb +119 -108
- data/lib/aspose-email-cloud/models/requests/delete_email_folder_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/delete_email_message_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/delete_email_thread_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/delete_file_request_data.rb +90 -81
- data/lib/aspose-email-cloud/models/requests/delete_folder_request_data.rb +90 -81
- data/lib/aspose-email-cloud/models/requests/delete_mapi_attachment_request_data.rb +99 -89
- data/lib/aspose-email-cloud/models/requests/delete_mapi_properties_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/discover_email_config_oauth_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/discover_email_config_password_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/discover_email_config_request_data.rb +86 -0
- data/lib/aspose-email-cloud/models/requests/download_file_request_data.rb +90 -81
- data/lib/aspose-email-cloud/models/requests/email_request.rb +75 -75
- data/lib/aspose-email-cloud/models/requests/fetch_email_message_request_data.rb +115 -93
- data/lib/aspose-email-cloud/models/requests/fetch_email_model_request_data.rb +115 -0
- data/lib/aspose-email-cloud/models/requests/fetch_email_thread_messages_request_data.rb +114 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_as_file_request_data.rb +101 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_attachment_request_data.rb +101 -88
- data/lib/aspose-email-cloud/models/requests/get_calendar_file_as_model_request_data.rb +80 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_list_request_data.rb +108 -95
- data/lib/aspose-email-cloud/models/requests/get_calendar_model_as_alternate_request_data.rb +107 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_model_list_request_data.rb +98 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_model_request_data.rb +91 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_request_data.rb +91 -81
- data/lib/aspose-email-cloud/models/requests/get_contact_as_file_request_data.rb +111 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_attachment_request_data.rb +111 -100
- data/lib/aspose-email-cloud/models/requests/get_contact_file_as_model_request_data.rb +90 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_list_request_data.rb +103 -92
- data/lib/aspose-email-cloud/models/requests/get_contact_model_list_request_data.rb +103 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_model_request_data.rb +101 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_properties_request_data.rb +101 -93
- data/lib/aspose-email-cloud/models/requests/get_disc_usage_request_data.rb +74 -71
- data/lib/aspose-email-cloud/models/requests/get_email_as_file_request_data.rb +101 -0
- data/lib/aspose-email-cloud/models/requests/get_email_attachment_request_data.rb +101 -88
- data/lib/aspose-email-cloud/models/requests/get_email_client_account_request_data.rb +102 -0
- data/lib/aspose-email-cloud/models/requests/get_email_client_multi_account_request_data.rb +102 -0
- data/lib/aspose-email-cloud/models/requests/get_email_file_as_model_request_data.rb +80 -0
- data/lib/aspose-email-cloud/models/requests/get_email_model_list_request_data.rb +103 -0
- data/lib/aspose-email-cloud/models/requests/get_email_model_request_data.rb +101 -0
- data/lib/aspose-email-cloud/models/requests/get_email_property_request_data.rb +101 -88
- data/lib/aspose-email-cloud/models/requests/get_email_request_data.rb +91 -81
- data/lib/aspose-email-cloud/models/requests/get_file_versions_request_data.rb +84 -78
- data/lib/aspose-email-cloud/models/requests/get_files_list_request_data.rb +84 -78
- data/lib/aspose-email-cloud/models/requests/get_mapi_attachment_request_data.rb +101 -88
- data/lib/aspose-email-cloud/models/requests/get_mapi_attachments_request_data.rb +91 -81
- data/lib/aspose-email-cloud/models/requests/get_mapi_list_request_data.rb +93 -80
- data/lib/aspose-email-cloud/models/requests/get_mapi_properties_request_data.rb +91 -81
- data/lib/aspose-email-cloud/models/requests/http_request.rb +51 -51
- data/lib/aspose-email-cloud/models/requests/is_email_address_disposable_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/list_email_folders_request_data.rb +104 -88
- data/lib/aspose-email-cloud/models/requests/list_email_messages_request_data.rb +127 -105
- data/lib/aspose-email-cloud/models/requests/list_email_models_request_data.rb +122 -0
- data/lib/aspose-email-cloud/models/requests/list_email_threads_request_data.rb +121 -0
- data/lib/aspose-email-cloud/models/requests/move_email_message_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/move_email_thread_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/move_file_request_data.rb +107 -92
- data/lib/aspose-email-cloud/models/requests/move_folder_request_data.rb +101 -89
- data/lib/aspose-email-cloud/models/requests/object_exists_request_data.rb +90 -81
- data/lib/aspose-email-cloud/models/requests/save_calendar_model_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/save_contact_model_request_data.rb +99 -0
- data/lib/aspose-email-cloud/models/requests/save_email_client_account_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/save_email_client_multi_account_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/save_email_model_request_data.rb +99 -0
- data/lib/aspose-email-cloud/models/requests/save_mail_account_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/save_mail_o_auth_account_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/send_email_mime_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/send_email_model_request_data.rb +79 -0
- data/lib/aspose-email-cloud/models/requests/send_email_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/set_email_property_request_data.rb +99 -89
- data/lib/aspose-email-cloud/models/requests/set_email_read_flag_request_data.rb +79 -75
- data/lib/aspose-email-cloud/models/requests/set_email_thread_read_flag_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/storage_exists_request_data.rb +78 -75
- data/lib/aspose-email-cloud/models/requests/update_calendar_properties_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/update_contact_properties_request_data.rb +99 -94
- data/lib/aspose-email-cloud/models/requests/update_mapi_properties_request_data.rb +89 -82
- data/lib/aspose-email-cloud/models/requests/upload_file_request_data.rb +96 -87
- data/lib/aspose-email-cloud/models/save_email_account_request.rb +214 -157
- data/lib/aspose-email-cloud/models/save_o_auth_email_account_request.rb +240 -166
- data/lib/aspose-email-cloud/models/send_email_base_request.rb +159 -145
- data/lib/aspose-email-cloud/models/send_email_mime_base_request.rb +158 -144
- data/lib/aspose-email-cloud/models/send_email_model_rq.rb +276 -0
- data/lib/aspose-email-cloud/models/set_email_property_request.rb +150 -143
- data/lib/aspose-email-cloud/models/set_message_read_flag_account_base_request.rb +162 -146
- data/lib/aspose-email-cloud/models/storage_exist.rb +145 -141
- data/lib/aspose-email-cloud/models/storage_file.rb +161 -149
- data/lib/aspose-email-cloud/models/storage_file_location.rb +154 -145
- data/lib/aspose-email-cloud/models/storage_file_rq_of_email_client_account.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_file_rq_of_email_client_multi_account.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_folder_location.rb +150 -143
- data/lib/aspose-email-cloud/models/storage_model_of_calendar_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_model_of_contact_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_model_of_email_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_model_rq_of_calendar_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_model_rq_of_contact_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/storage_model_rq_of_email_dto.rb +225 -0
- data/lib/aspose-email-cloud/models/url.rb +244 -0
- data/lib/aspose-email-cloud/models/value_response.rb +146 -141
- data/lib/aspose-email-cloud/models/value_t_of_boolean.rb +217 -0
- data/lib/aspose-email-cloud/version.rb +15 -15
- metadata +206 -53
- data/lib/aspose-email-cloud/models/contact_format.rb +0 -45
@@ -1,381 +1,385 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
|
-
# <copyright company="Aspose" file="api_client.rb">
|
3
|
-
# Copyright (c) 2018-
|
4
|
-
# </copyright>
|
5
|
-
# <summary>
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
-
# copy of this software and associated documentation files (the "Software"),
|
8
|
-
# to deal in the Software without restriction, including without limitation
|
9
|
-
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
-
# and/or sell copies of the Software, and to permit persons to whom the
|
11
|
-
# Software is furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all 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
|
21
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
-
# DEALINGS IN THE SOFTWARE.
|
23
|
-
# </summary>
|
24
|
-
# ----------------------------------------------------------------------------
|
25
|
-
|
26
|
-
require 'date'
|
27
|
-
require 'json'
|
28
|
-
require 'logger'
|
29
|
-
require 'tempfile'
|
30
|
-
require 'faraday'
|
31
|
-
require 'mimemagic'
|
32
|
-
require 'uri'
|
33
|
-
|
34
|
-
module AsposeEmailCloud
|
35
|
-
# Generic API client
|
36
|
-
# Swagger generic API client. This client handles the client-
|
37
|
-
# server communication, and is invariant across implementations.
|
38
|
-
class ApiClient
|
39
|
-
# The Configuration object holding settings to be used in the API client.
|
40
|
-
attr_accessor :config
|
41
|
-
|
42
|
-
# Defines the headers to be used in HTTP requests of all API calls by default.
|
43
|
-
#
|
44
|
-
# @return [Hash]
|
45
|
-
attr_accessor :default_headers
|
46
|
-
|
47
|
-
# Initializes the ApiClient
|
48
|
-
# @param [String] app_key Key to access the server.
|
49
|
-
# @param [String] app_sid ID to access the server.
|
50
|
-
# @param [String] base_url Server URL.
|
51
|
-
# @param [String] api_version Api version.
|
52
|
-
# @param [Object] debug Debug switch [true, false].
|
53
|
-
def initialize(app_key = nil, app_sid = nil, base_url = 'api-qa.aspose.cloud', api_version = 'v3.0', debug = false)
|
54
|
-
@config = Configuration.new(app_key, app_sid, base_url, api_version, debug)
|
55
|
-
@default_headers = {
|
56
|
-
'x-aspose-client' => 'ruby sdk',
|
57
|
-
'x-aspose-version' => '19.7'
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
# Call an API with given options.
|
62
|
-
#
|
63
|
-
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
64
|
-
# the data deserialized from response body (could be nil), response status code and response headers.
|
65
|
-
def call_api(http_method, path, opts = {})
|
66
|
-
response = build_request(http_method, path, opts)
|
67
|
-
download_file response if opts[:return_type] == 'File'
|
68
|
-
|
69
|
-
if @config.debugging
|
70
|
-
@config.logger.debug "'HTTP' response body '~BEGIN~'\n #{response.body}\n'~END~'\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
unless response.success?
|
74
|
-
if response.status.zero?
|
75
|
-
# Errors from libcurl will be made visible here
|
76
|
-
raise ApiError.new(response.return_message, 0)
|
77
|
-
else
|
78
|
-
begin
|
79
|
-
error = convert_to_type(JSON.parse(response.body, symbolize_names: true)[:error], "Error")
|
80
|
-
ensure
|
81
|
-
raise ApiError.new("#{response.status} Error connecting to the API #{path}; Message: #{error}",
|
82
|
-
response.status, error)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
data = (deserialize(response, opts[:return_type]) if opts[:return_type])
|
88
|
-
[data, response.status, response.headers]
|
89
|
-
end
|
90
|
-
|
91
|
-
# Builds the HTTP request
|
92
|
-
#
|
93
|
-
# @param [String] http_method HTTP method/verb (e.g. POST)
|
94
|
-
# @param [String] path URL path (e.g. /account/new)
|
95
|
-
# @option opts [Hash] :header_params Header parameters
|
96
|
-
# @option opts [Hash] :query_params Query parameters
|
97
|
-
# @option opts [Hash] :form_params Query parameters
|
98
|
-
# @option opts [Object] :body HTTP body (JSON/XML)
|
99
|
-
# @
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
f.request :
|
131
|
-
f.
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
# JSON MIME
|
150
|
-
#
|
151
|
-
# application/json
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
# @
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
#
|
162
|
-
#
|
163
|
-
# @param [
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
return body
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
#
|
196
|
-
# @param [
|
197
|
-
# @
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
#
|
243
|
-
#
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
#
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
def
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
#
|
288
|
-
#
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
when ::
|
301
|
-
data[key] = value
|
302
|
-
|
303
|
-
data[key] = value.
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
#
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
when :
|
370
|
-
param.join(
|
371
|
-
when :
|
372
|
-
param.join('
|
373
|
-
when :
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose" file="api_client.rb">
|
3
|
+
# Copyright (c) 2018-2020 Aspose Pty Ltd. All rights reserved.
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
+
# copy of this software and associated documentation files (the "Software"),
|
8
|
+
# to deal in the Software without restriction, including without limitation
|
9
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
11
|
+
# Software is furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all 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
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
+
# DEALINGS IN THE SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# ----------------------------------------------------------------------------
|
25
|
+
|
26
|
+
require 'date'
|
27
|
+
require 'json'
|
28
|
+
require 'logger'
|
29
|
+
require 'tempfile'
|
30
|
+
require 'faraday'
|
31
|
+
require 'mimemagic'
|
32
|
+
require 'uri'
|
33
|
+
|
34
|
+
module AsposeEmailCloud
|
35
|
+
# Generic API client
|
36
|
+
# Swagger generic API client. This client handles the client-
|
37
|
+
# server communication, and is invariant across implementations.
|
38
|
+
class ApiClient
|
39
|
+
# The Configuration object holding settings to be used in the API client.
|
40
|
+
attr_accessor :config
|
41
|
+
|
42
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
43
|
+
#
|
44
|
+
# @return [Hash]
|
45
|
+
attr_accessor :default_headers
|
46
|
+
|
47
|
+
# Initializes the ApiClient
|
48
|
+
# @param [String] app_key Key to access the server.
|
49
|
+
# @param [String] app_sid ID to access the server.
|
50
|
+
# @param [String] base_url Server URL.
|
51
|
+
# @param [String] api_version Api version.
|
52
|
+
# @param [Object] debug Debug switch [true, false].
|
53
|
+
def initialize(app_key = nil, app_sid = nil, base_url = 'api-qa.aspose.cloud', api_version = 'v3.0', debug = false)
|
54
|
+
@config = Configuration.new(app_key, app_sid, base_url, api_version, debug)
|
55
|
+
@default_headers = {
|
56
|
+
'x-aspose-client' => 'ruby sdk',
|
57
|
+
'x-aspose-version' => '19.7'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Call an API with given options.
|
62
|
+
#
|
63
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
64
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
65
|
+
def call_api(http_method, path, opts = {})
|
66
|
+
response = build_request(http_method, path, opts)
|
67
|
+
download_file response if opts[:return_type] == 'File'
|
68
|
+
|
69
|
+
if @config.debugging
|
70
|
+
@config.logger.debug "'HTTP' response body '~BEGIN~'\n #{response.body}\n'~END~'\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
unless response.success?
|
74
|
+
if response.status.zero?
|
75
|
+
# Errors from libcurl will be made visible here
|
76
|
+
raise ApiError.new(response.return_message, 0)
|
77
|
+
else
|
78
|
+
begin
|
79
|
+
error = convert_to_type(JSON.parse(response.body, symbolize_names: true)[:error], "Error")
|
80
|
+
ensure
|
81
|
+
raise ApiError.new("#{response.status} Error connecting to the API #{path}; Message: #{error}",
|
82
|
+
response.status, error)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
data = (deserialize(response, opts[:return_type]) if opts[:return_type])
|
88
|
+
[data, response.status, response.headers]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Builds the HTTP request
|
92
|
+
#
|
93
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
94
|
+
# @param [String] path URL path (e.g. /account/new)
|
95
|
+
# @option opts [Hash] :header_params Header parameters
|
96
|
+
# @option opts [Hash] :query_params Query parameters
|
97
|
+
# @option opts [Hash] :form_params Query parameters
|
98
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
99
|
+
# @option opts [String] :host Should not be used
|
100
|
+
# @return [Faraday::Response] A Faraday Response
|
101
|
+
def build_request(http_method, path, opts = {})
|
102
|
+
url = build_request_url(path, opts[:host])
|
103
|
+
http_method = http_method.to_sym.downcase
|
104
|
+
|
105
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
106
|
+
query_params = opts[:query_params] || {}
|
107
|
+
form_params = opts[:form_params] || {}
|
108
|
+
body = opts[:body] if opts[:body] || nil?
|
109
|
+
|
110
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
111
|
+
|
112
|
+
req_opts = {
|
113
|
+
:method => http_method,
|
114
|
+
:headers => header_params,
|
115
|
+
:params => query_params,
|
116
|
+
:body => body
|
117
|
+
}
|
118
|
+
|
119
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
120
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
121
|
+
req_opts.update :body => req_body
|
122
|
+
if @config.debugging
|
123
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
124
|
+
end
|
125
|
+
elsif http_method == :get && body.nil? && !form_params.any? && header_params['Content-Type'] == 'multipart/form-data'
|
126
|
+
req_opts[:headers].delete('Content-Type')
|
127
|
+
end
|
128
|
+
|
129
|
+
conn = Faraday.new url, { :params => query_params, :headers => header_params } do |f|
|
130
|
+
f.request :multipart
|
131
|
+
f.request :url_encoded
|
132
|
+
f.adapter Faraday.default_adapter
|
133
|
+
end
|
134
|
+
|
135
|
+
case http_method
|
136
|
+
when :post
|
137
|
+
return conn.post url, req_opts[:body]
|
138
|
+
when :put
|
139
|
+
return conn.put url, req_opts[:body]
|
140
|
+
when :get
|
141
|
+
return conn.get url, req_opts[:body]
|
142
|
+
else
|
143
|
+
return conn.delete url do |c|
|
144
|
+
c.body = req_opts[:body]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Check if the given MIME is a JSON MIME.
|
150
|
+
# JSON MIME examples:
|
151
|
+
# application/json
|
152
|
+
# application/json; charset=UTF8
|
153
|
+
# APPLICATION/JSON
|
154
|
+
# */*
|
155
|
+
# @param [String] mime MIME
|
156
|
+
# @return [Boolean] True if the MIME is application/json
|
157
|
+
def json_mime?(mime)
|
158
|
+
(mime == '*/*') || !(mime =~ %r{Application/.*json(?!p)(;.*)?}i).nil?
|
159
|
+
end
|
160
|
+
|
161
|
+
# Deserialize the response to the given return type.
|
162
|
+
#
|
163
|
+
# @param [Response] response HTTP response
|
164
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
165
|
+
def deserialize(response, return_type)
|
166
|
+
body = response.body
|
167
|
+
|
168
|
+
# handle file downloading - return the File instance processed in request callbacks
|
169
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
170
|
+
return @tempfile if return_type == 'File'
|
171
|
+
|
172
|
+
return nil if body.nil? || body.empty?
|
173
|
+
|
174
|
+
# return response body directly for String return type
|
175
|
+
return body if return_type == 'String'
|
176
|
+
|
177
|
+
# ensuring a default content type
|
178
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
179
|
+
|
180
|
+
raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
181
|
+
|
182
|
+
begin
|
183
|
+
data = JSON.parse("[#{body}]", symbolize_names: true)[0]
|
184
|
+
rescue JSON::ParserError => e
|
185
|
+
if %w[String Date DateTime].include?(return_type)
|
186
|
+
data = body
|
187
|
+
else
|
188
|
+
raise e
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
convert_to_type data, return_type
|
193
|
+
end
|
194
|
+
|
195
|
+
# Convert data to the given return type.
|
196
|
+
# @param [Object] data Data to be converted
|
197
|
+
# @param [String] return_type Return type
|
198
|
+
# @return [Mixed] Data in a particular type
|
199
|
+
def convert_to_type(data, return_type)
|
200
|
+
return nil if data.nil?
|
201
|
+
|
202
|
+
case return_type
|
203
|
+
when 'String'
|
204
|
+
data.to_s
|
205
|
+
when 'Integer'
|
206
|
+
data.to_i
|
207
|
+
when 'Float'
|
208
|
+
data.to_f
|
209
|
+
when 'BOOLEAN'
|
210
|
+
data == true
|
211
|
+
when 'DateTime'
|
212
|
+
# parse date time (expecting ISO 8601 format)
|
213
|
+
DateTime.parse data
|
214
|
+
when 'Date'
|
215
|
+
# parse date time (expecting ISO 8601 format)
|
216
|
+
Date.parse data
|
217
|
+
when 'Object'
|
218
|
+
# generic object (usually a Hash), return directly
|
219
|
+
data
|
220
|
+
when /\AArray<(.+)>\z/
|
221
|
+
# e.g. Array<Pet>
|
222
|
+
sub_type = Regexp.last_match(1)
|
223
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
224
|
+
when /\AHash\<String, (.+)\>\z/
|
225
|
+
# e.g. Hash<String, Integer>
|
226
|
+
sub_type = Regexp.last_match(1)
|
227
|
+
{}.tap do |hash|
|
228
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
229
|
+
end
|
230
|
+
else
|
231
|
+
# models, e.g. Pet
|
232
|
+
sub_type = data[:type] || data[:discriminator] || return_type
|
233
|
+
if AsposeEmailCloud.const_defined?(sub_type)
|
234
|
+
return_type = sub_type
|
235
|
+
end
|
236
|
+
AsposeEmailCloud.const_get(return_type).new.tap do |model|
|
237
|
+
model.build_from_hash data
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
243
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
244
|
+
# The response body is written to the file in chunks in order to handle files which
|
245
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
246
|
+
# process can use.
|
247
|
+
#
|
248
|
+
# @see Configuration#temp_folder_path
|
249
|
+
def download_file(response)
|
250
|
+
tempfile = nil
|
251
|
+
content_disposition = response.headers['Content-Disposition']
|
252
|
+
if content_disposition and content_disposition =~ /filename=/i
|
253
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
254
|
+
prefix = sanitize_filename(filename)
|
255
|
+
else
|
256
|
+
prefix = 'download-'
|
257
|
+
end
|
258
|
+
prefix += '-' unless prefix.end_with?('-')
|
259
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path)
|
260
|
+
tempfile.binmode
|
261
|
+
@tempfile = tempfile
|
262
|
+
tempfile.write(response.body)
|
263
|
+
response.on_complete do |resp|
|
264
|
+
tempfile.close
|
265
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
266
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
267
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
268
|
+
"explicitly with `tempfile.delete`"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# Sanitize filename by removing path.
|
273
|
+
# e.g. ../../sun.gif becomes sun.gif
|
274
|
+
#
|
275
|
+
# @param [String] filename the filename to be sanitized
|
276
|
+
# @return [String] the sanitized filename
|
277
|
+
def sanitize_filename(filename)
|
278
|
+
filename.gsub(%r{.*[/\\]}, '')
|
279
|
+
end
|
280
|
+
|
281
|
+
def build_request_url(path, host = nil)
|
282
|
+
# Add leading and trailing slashes to path
|
283
|
+
path = "/#{path}".gsub(%r{/+}, '/')
|
284
|
+
URI.encode((host || @config.base_url) + path)
|
285
|
+
end
|
286
|
+
|
287
|
+
# Builds the HTTP request body
|
288
|
+
#
|
289
|
+
# @param [Hash] header_params Header parameters
|
290
|
+
# @param [Hash] form_params Query parameters
|
291
|
+
# @param [Object] body HTTP body (JSON/XML)
|
292
|
+
# @return [String] HTTP body data in the form of string
|
293
|
+
def build_request_body(header_params, form_params, body)
|
294
|
+
# http form
|
295
|
+
if (header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
296
|
+
header_params['Content-Type'] == 'multipart/form-data') && form_params.any?
|
297
|
+
data = {}
|
298
|
+
form_params.each do |key, value|
|
299
|
+
case value
|
300
|
+
when ::File
|
301
|
+
data[key] = Faraday::UploadIO.new(value.path, MimeMagic.by_magic(value).to_s, key)
|
302
|
+
when ::Tempfile
|
303
|
+
data[key] = Faraday::UploadIO.new(value.path, key)
|
304
|
+
when ::Array, nil
|
305
|
+
data[key] = value
|
306
|
+
else
|
307
|
+
data[key] = value.to_s
|
308
|
+
end
|
309
|
+
end
|
310
|
+
elsif body
|
311
|
+
data = body.is_a?(String) ? body : body.to_json
|
312
|
+
else
|
313
|
+
data = nil
|
314
|
+
end
|
315
|
+
data
|
316
|
+
end
|
317
|
+
|
318
|
+
# Update hearder and query params based on authentication settings.
|
319
|
+
#
|
320
|
+
# @param [Hash] header_params Header parameters
|
321
|
+
# @param [Hash] query_params Query parameters
|
322
|
+
# @param [String] auth_names Authentication scheme name
|
323
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
324
|
+
Array(auth_names).each do |auth_name|
|
325
|
+
auth_setting = @config.auth_settings[auth_name.to_sym]
|
326
|
+
next unless auth_setting
|
327
|
+
|
328
|
+
case auth_setting[:in]
|
329
|
+
when 'header'
|
330
|
+
header_params[auth_setting[:key]] = auth_setting[:value]
|
331
|
+
when 'query'
|
332
|
+
query_params[auth_setting[:key]] = auth_setting[:value]
|
333
|
+
else
|
334
|
+
raise ArgumentError, 'Authentication token must be in `query` of `header`'
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
340
|
+
# @param [Object] model object to be converted into JSON string
|
341
|
+
# @return [String] JSON string representation of the object
|
342
|
+
def object_to_http_body(model)
|
343
|
+
return model if model.nil? || model.is_a?(String)
|
344
|
+
|
345
|
+
local_body = nil
|
346
|
+
local_body = if model.is_a?(Array)
|
347
|
+
model.map { |m| object_to_hash(m) }
|
348
|
+
else
|
349
|
+
object_to_hash(model)
|
350
|
+
end
|
351
|
+
local_body.to_json
|
352
|
+
end
|
353
|
+
|
354
|
+
# Convert object(non-array) to hash.
|
355
|
+
# @param [Object] obj object to be converted into JSON string
|
356
|
+
# @return [String] JSON string representation of the object
|
357
|
+
def object_to_hash(obj)
|
358
|
+
if obj.respond_to?(:to_hash)
|
359
|
+
obj.to_hash
|
360
|
+
else
|
361
|
+
obj
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
# Build parameter value according to the given collection format.
|
366
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
367
|
+
def build_collection_param(param, collection_format)
|
368
|
+
case collection_format
|
369
|
+
when :csv
|
370
|
+
param.join(',')
|
371
|
+
when :ssv
|
372
|
+
param.join(' ')
|
373
|
+
when :tsv
|
374
|
+
param.join("\t")
|
375
|
+
when :pipes
|
376
|
+
param.join('|')
|
377
|
+
when :multi
|
378
|
+
# return the array directly as typhoeus will handle it as expected
|
379
|
+
param
|
380
|
+
else
|
381
|
+
raise "unknown collection format: #{collection_format.inspect}"
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|