class Copyleaks::WritingAssistantClient

Public Class Methods

new(api_client) click to toggle source
# File lib/copyleaks/writing_assistant_client.rb, line 27
def initialize(api_client)
  @api_client = api_client
end

Public Instance Methods

get_correction_types(language_code) click to toggle source

Get a list of correction types supported within the Writing Assistant API. Correction types apply to all supported languages. The supplied language code for this request is used to determine the language of the texts returned.

  • Exceptions:

    • CommandExceptions: Server reject the request. See response status code, headers and content for more info.

@param [languageCode] The language for the returned texts to be in. Language codes are in ISO 639-1 standard. Supported Values: en - English

# File lib/copyleaks/writing_assistant_client.rb, line 39
def get_correction_types(language_code)
  path = "/v1/writing-feedback/correction-types/#{language_code}"

  headers = {
    'Content-Type' => 'application/json',
    'User-Agent' => Config.user_agent
  }

  request = Net::HTTP::Get.new(path, headers)
  ClientUtils.handle_response(@api_client.request(request), 'get_correction_types')
end
submit_text(authToken, scanId, submission) click to toggle source

Use Copyleaks Writing Assistant to generate grammar, spelling and sentence corrections for a given text.

  • Exceptions:

    • CommandExceptions: Server reject the request. See response status code, headers and content for more info.

@param [CopyleaksAuthToken] authToken Copyleaks authentication token @param [String] scanId Attach your own scan Id @param [SourceCodeSubmissionModel] submission document

# File lib/copyleaks/writing_assistant_client.rb, line 61
def submit_text(authToken, scanId, submission)
  raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
  raise 'submission is invalid, must be an instance of WritingAssistantSubmissionModel' if submission.nil? || !submission.instance_of?(Copyleaks::WritingAssistantSubmissionModel)

  ClientUtils.verify_auth_token(authToken)

  path = "/v1/writing-feedback/#{scanId}/check"

  headers = {
    'Content-Type' => 'application/json',
    'User-Agent' => Config.user_agent,
    'Authorization' => "Bearer #{authToken.accessToken}"
  }

  request = Net::HTTP::Post.new(path, headers)
  request.body = submission.to_json

  ClientUtils.handle_response(@api_client.request(request), 'submit_writing_assistant')
end