Class: Copyleaks::WritingAssistantClient

Inherits:
Object
  • Object
show all
Defined in:
lib/copyleaks/writing_assistant_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ WritingAssistantClient

Returns a new instance of WritingAssistantClient.



27
28
29
# File 'lib/copyleaks/writing_assistant_client.rb', line 27

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

#get_correction_types(language_code) ⇒ Object

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.

Parameters:

  • The (languageCode)

    language for the returned texts to be in. Language codes are in ISO 639-1 standard. Supported Values: en - English



39
40
41
42
43
44
45
46
47
48
49
# 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) ⇒ Object

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.

Parameters:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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