class Copyleaks::API
Public Class Methods
Source
# File lib/copyleaks/api.rb, line 34 def initialize # copyleaks identity http client _identity_server_uri = URI.parse(Config.identity_server_uri) @id_client = Net::HTTP.new(_identity_server_uri.host, _identity_server_uri.port) @id_client.use_ssl = true # copyleaks api http client _api_server_uri = URI.parse(Config.api_server_uri) @api_client = Net::HTTP.new(_api_server_uri.host, _api_server_uri.port) @api_client.use_ssl = true # Initialize clients @ai_detection_client = AIDetectionClient.new(@api_client) @writing_assistant_client = WritingAssistantClient.new(@api_client) @text_moderation_client = TextModerationClient.new(@api_client) end
Public Instance Methods
Source
# File lib/copyleaks/api.rb, line 454 def ai_detection_client @ai_detection_client end
Source
# File lib/copyleaks/api.rb, line 278 def delete(authToken, data) if data.nil? || !data.instance_of?(CopyleaksDeleteRequestModel) raise 'data is Invalid, must be instance of CopyleaksDeleteRequestModel' end verify_auth_token(authToken) path = "/v3.1/scans/delete" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Patch.new(path, headers) request.body = data.to_json handle_response(@api_client.request(request), 'delete') end
Delete the specific process from the server. For more info: api.copyleaks.com/documentation/v3/scans/delete
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token @param [CopyleaksDeleteRequestModel] data
Source
# File lib/copyleaks/api.rb, line 212 def export(authToken, scanId, exportId, model) raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String) raise 'exportId is Invalid, must be instance of String' if exportId.nil? || !exportId.instance_of?(String) if model.nil? || !model.instance_of?(CopyleaksExportModel) raise 'model is Invalid, must be instance of type CopyleaksExportModel' end verify_auth_token(authToken) path = "/v3/downloads/#{scanId}/export/#{exportId}" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Post.new(path, headers) request.body = model.to_json handle_response(@api_client.request(request), 'export') end
Exporting scans artifact into your server. For more info: api.copyleaks.com/documentation/v3/downloads/export
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Your login token to Copyleaks
server @param [String] scanId The scan ID of the specific scan to export. @param [String] exportId A new Id for the export process. @param [CopyleaksExportModel] model Request of which artifact should be exported.
Source
# File lib/copyleaks/api.rb, line 338 def get_credits_balance(authToken) verify_auth_token(authToken) path = "/v3/scans/credits" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Get.new(path, headers) handle_response(@api_client.request(request), 'get_credits_balance') end
Get current credits balance for the Copyleaks
account. For more info: api.copyleaks.com/documentation/v3/scans/credits
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
-
RateLimitException: Too many requests. Please wait before calling again.
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token
Source
# File lib/copyleaks/api.rb, line 395 def get_ocr_supported_languages path = '/v3/miscellaneous/ocr-languages-list' headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent } request = Net::HTTP::Get.new(path, headers) handle_response(@api_client.request(request), 'get_ocr_supported_languages') end
Get a list of the supported languages for OCR (this is not a list of supported languages for the api, but only for the OCR files scan). For more info: api.copyleaks.com/documentation/v3/specifications/ocr-languages/list
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
-
RateLimitException: Too many requests. Please wait before calling again.
-
@return array List of supported OCR languages.
Source
# File lib/copyleaks/api.rb, line 438 def get_release_notes path = '/v3/release-logs.json' header = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent } request = Net::HTTP::Get.new(path, header) handle_response(@api_client.request(request), 'get_release_notes') end
Get updates about copyleaks api release notes. For more info: api.copyleaks.com/documentation/v3/release-notes
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
-
RateLimitException: Too many requests. Please wait before calling again.
-
@return mixed List of release notes.
Source
# File lib/copyleaks/api.rb, line 416 def get_supported_file_types path = '/v3/miscellaneous/supported-file-types' headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent } request = Net::HTTP::Get.new(path, headers) handle_response(@api_client.request(request), 'get_supported_file_types') end
Get a list of the supported file types. For more info: api.copyleaks.com/documentation/v3/specifications/supported-file-types
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
-
RateLimitException: Too many requests. Please wait before calling again.
-
@return mixed List of supported file types.
Source
# File lib/copyleaks/api.rb, line 367 def get_usages_history_csv(authToken, startDate, endDate) raise 'startDate is Invalid, must be instance of String' if startDate.nil? || !startDate.instance_of?(String) raise 'endDate is Invalid, must be instance of String' if endDate.nil? || !endDate.instance_of?(String) verify_auth_token(authToken) path = "/v3/scans/usages/history?start=#{startDate}&end=#{endDate}" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Get.new(path, headers) handle_response(@api_client.request(request), 'get_usages_history_csv') end
This endpoint allows you to export your usage history between two dates. The output results will be exported to a csv file and it will be attached to the response. For more info: api.copyleaks.com/documentation/v3/scans/usages/history
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
-
RateLimitException: Too many requests. Please wait before calling again.
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token. @param [String] startDate The start date to collect usage history from. Date Format: ‘dd-MM-yyyy`. @param [String] endDate The end date to collect usage history from. Date Format: `dd-MM-yyyy`.
Source
# File lib/copyleaks/api.rb, line 450 def handle_response(response, used_by) Copyleaks::ClientUtils.handle_response(response, used_by) end
this methods is a helper for hanlding reponse data and exceptions.
Source
# File lib/copyleaks/api.rb, line 58 def login(email, key) raise 'email is Invalid, must be instance of String' if email.nil? || !email.instance_of?(String) raise 'key is Invalid, must be instance of String' if key.nil? || !email.instance_of?(String) path = '/v3/account/login/api' headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent } payload = { email: email, key: key } request = Net::HTTP::Post.new(path, headers) request.body = payload.to_json res_data = handle_response(@id_client.request(request), 'login') CopyleaksAuthToken.new(res_data['.expires'], res_data['access_token'], res_data['.issued']) end
Login to Copyleaks
authentication server. For more info: api.copyleaks.com/documentation/v3/account/login.
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [String] email Copyleaks
account email address. @param [String] key Copyleaks
account secret key. @return A authentication token that being expired after certain amount of time.
Source
# File lib/copyleaks/api.rb, line 310 def resend_webhook(authToken, scanId) raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String) verify_auth_token(authToken) path = "/v3/scans/#{scanId}/webhooks/resend" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Post.new(path, headers) handle_response(@api_client.request(request), 'resend_webhook') end
Resend status webhooks for existing scans. For more info: api.copyleaks.com/documentation/v3/scans/webhook-resend
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token @param [String] scanId Copyleaks
scan Id
Source
# File lib/copyleaks/api.rb, line 245 def start(authToken, data) if data.nil? || !data.instance_of?(CopyleaksStartRequestModel) raise 'data is Invalid, must be instance of type CopyleaksStartRequestModel' end verify_auth_token(authToken) path = "/v3/scans/start" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Patch.new(path, headers) request.body = data.to_json handle_response(@api_client.request(request), 'start') end
Start scanning all the files you submitted for a price-check. For more info: api.copyleaks.com/documentation/v3/scans/start
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Your login token to Copyleaks
server. @param [CopyleaksStartRequestModel] data Include information about which scans should be started.
Source
# File lib/copyleaks/api.rb, line 109 def submit_file(authToken, scanId, submission) raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String) if submission.nil? || !submission.instance_of?(CopyleaksFileSubmissionModel) raise 'submission is Invalid, must be instance of type CopyleaksFileSubmissionModel' end verify_auth_token(authToken) path = "/v3/scans/submit/file/#{scanId}" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Put.new(path, headers) request.body = submission.to_json handle_response(@api_client.request(request), 'submit_file') end
Starting a new process by providing a file to scan. For more info: api.copyleaks.com/documentation/v3/scans/submit/file
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token @param [String] scanId Attach your own scan Id @param [CopyleaksFileSubmissionModel] submission Submission properties
Source
# File lib/copyleaks/api.rb, line 143 def submit_file_ocr(authToken, scanId, submission) raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String) if submission.nil? || !submission.instance_of?(CopyleaksFileOcrSubmissionModel) raise 'submission is Invalid, must be instance of type CopyleaksFileOcrSubmissionModel' end verify_auth_token(authToken) path = "/v3/scans/submit/ocr/#{scanId}" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Put.new(path, headers) request.body = submission.to_json handle_response(@api_client.request(request), 'submit_file_ocr') end
Starting a new process by providing a OCR image file to scan. For more info: api.copyleaks.com/documentation/v3/scans/submit/ocr
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token @param [String] scanId Attach your own scan Id @param [CopyleaksFileOcrSubmissionModel] submission Submission properties
Source
# File lib/copyleaks/api.rb, line 177 def submit_url(authToken, scanId, submission) raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String) if submission.nil? || !submission.instance_of?(CopyleaksURLSubmissionModel) raise 'submission is Invalid, must be instance of CopyleaksURLSubmissionModel' end verify_auth_token(authToken) path = "/v3/scans/submit/url/#{scanId}" headers = { 'Content-Type' => 'application/json', 'User-Agent' => Config.user_agent, 'Authorization' => "Bearer #{authToken.accessToken}" } request = Net::HTTP::Put.new(path, headers) request.body = submission.to_json handle_response(@api_client.request(request), 'submit_url') end
Starting a new process by providing a URL to scan. For more info: api.copyleaks.com/documentation/v3/scans/submit/url
-
Exceptions:
-
CommandExceptions: Server reject the request. See response status code, headers and content for more info.
-
-
UnderMaintenanceException:
Copyleaks
servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: api.copyleaks.com/documentation/v3/exponential-backoff
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token @param [String] scanId Attach your own scan Id @param [CopyleaksURLSubmissionModel] submission Submission properties
Source
# File lib/copyleaks/api.rb, line 461 def text_moderation_client @text_moderation_client end
Source
# File lib/copyleaks/api.rb, line 83 def verify_auth_token(authToken) if authToken.nil? || !authToken.instance_of?(CopyleaksAuthToken) raise 'authToken is Invalid, must be instance of CopyleaksAuthToken' end _time = DateTime.now _expiresTime = DateTime.parse(authToken.expires) if _expiresTime <= _time raise AuthExpiredException # expired end end
Verify that Copyleaks
authentication token is exists and not exipired.
-
Exceptions:
-
AuthExpiredException: authentication expired. Need to login again.
-
@param [CopyleaksAuthToken] authToken Copyleaks
authentication token
Source
# File lib/copyleaks/api.rb, line 458 def writing_assistant_client @writing_assistant_client end