Class: OnlyofficeDocumentserverTestingFramework::IntegrationExampleApi
- Inherits:
-
Object
- Object
- OnlyofficeDocumentserverTestingFramework::IntegrationExampleApi
- Defined in:
- lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb
Overview
Class for working with integration example api
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
readonly
Url of api endpoint.
Instance Method Summary collapse
-
#delete_file(file_name, sleep_after_delete: 3) ⇒ nil
Delete file on server by name.
-
#file_data(name) ⇒ String?
Get file data by it’s name.
-
#files ⇒ Array<Hash>
List of file on example.
-
#initialize(instance, api_endpoint: "#{instance.doc_server_base_url}/example") ⇒ IntegrationExampleApi
constructor
A new instance of IntegrationExampleApi.
-
#upload_file(file_path) ⇒ String
Upload file by it’s path.
Constructor Details
#initialize(instance, api_endpoint: "#{instance.doc_server_base_url}/example") ⇒ IntegrationExampleApi
Returns a new instance of IntegrationExampleApi.
12 13 14 15 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 12 def initialize(instance, api_endpoint: "#{instance.doc_server_base_url}/example") @instance = instance @api_endpoint = api_endpoint end |
Instance Attribute Details
#api_endpoint ⇒ String (readonly)
Returns url of api endpoint.
10 11 12 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 10 def api_endpoint @api_endpoint end |
Instance Method Details
#delete_file(file_name, sleep_after_delete: 3) ⇒ nil
Delete file on server by name
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 44 def delete_file(file_name, sleep_after_delete: 3) raise 'File name is not found on server' unless file_data(file_name) url = URI::DEFAULT_PARSER.escape("#{@api_endpoint}/file?filename=#{file_name}") request = Net::HTTP::Delete.new(url) response = http_from_url(url).request(request) result = JSON.parse(response.read_body) sleep(sleep_after_delete) result end |
#file_data(name) ⇒ String?
Get file data by it’s name
58 59 60 61 62 63 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 58 def file_data(name) files.each do |file| return file if file['title'] == name end nil end |
#files ⇒ Array<Hash>
Returns list of file on example.
18 19 20 21 22 23 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 18 def files url = "#{@api_endpoint}/files/" request = Net::HTTP::Get.new(url) response = http_from_url(url).request(request) JSON.parse(response.read_body) end |
#upload_file(file_path) ⇒ String
Upload file by it’s path
28 29 30 31 32 33 34 35 36 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/integration_example_api.rb', line 28 def upload_file(file_path) url = URI("#{@api_endpoint}/upload/") request = Net::HTTP::Post.new(url) form_data = [['uploadedFile', File.open(file_path)]] request.set_form(form_data, 'multipart/form-data') response = http_from_url(url).request(request) JSON.parse(response.read_body)['filename'] end |