Class: CopyleaksApi::CopyleaksCloud
- Inherits:
-
Object
- Object
- CopyleaksApi::CopyleaksCloud
- Defined in:
- lib/copyleaks_api/copyleaks_cloud.rb
Constant Summary collapse
- ALLOWED_ENDPOINTS =
[:publisher, :academic]
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#endpoint_type ⇒ Object
readonly
Returns the value of attribute endpoint_type.
Instance Method Summary collapse
- #api ⇒ Object
-
#balance ⇒ Object
returns account balance from endpoint.
-
#create_by_file(file_path, options = {}) ⇒ Object
uses create-by-file endpoint to create process.
-
#create_by_ocr(ocr_file_path, options = {}) ⇒ Object
uses create-by-file-ocr endpoint to create process.
-
#create_by_text(text, options = {}) ⇒ Object
uses create-by-text endpoint to create process.
-
#create_by_url(url, options = {}) ⇒ Object
uses create-by-url endpoint to create process.
-
#delete(id) ⇒ Object
deletes process by given id.
-
#initialize(email, api_key, type) ⇒ CopyleaksCloud
constructor
constructor.
-
#list ⇒ Object
retries all processes.
-
#result(id, options = {}) ⇒ Object
retries result information of process with given id.
-
#status(id, options = {}) ⇒ Object
retries status information of process with given id.
Constructor Details
#initialize(email, api_key, type) ⇒ CopyleaksCloud
constructor
11 12 13 14 15 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 11 def initialize(email, api_key, type) raise ArgumentError, "Endpoint type '#{type}' is invalid" unless ALLOWED_ENDPOINTS.include?(type.to_sym) @access_token = AccessToken.new(self, email, api_key) @endpoint_type = type end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 7 def access_token @access_token end |
#endpoint_type ⇒ Object (readonly)
Returns the value of attribute endpoint_type.
8 9 10 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 8 def endpoint_type @endpoint_type end |
Instance Method Details
#api ⇒ Object
17 18 19 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 17 def api @api ||= CopyleaksApi::Api.new end |
#balance ⇒ Object
returns account balance from endpoint
22 23 24 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 22 def balance api.get(url('count-credits'), token: @access_token.token)['Amount'].to_i end |
#create_by_file(file_path, options = {}) ⇒ Object
uses create-by-file endpoint to create process
33 34 35 36 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 33 def create_by_file(file_path, = {}) response = api.post_file(url('create-by-file'), file_path, .merge(token: @access_token.token)) CopyleaksProcess.create(self, response) end |
#create_by_ocr(ocr_file_path, options = {}) ⇒ Object
uses create-by-file-ocr endpoint to create process
39 40 41 42 43 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 39 def create_by_ocr(ocr_file_path, = {}) response = api.post_file(url_with_language('create-by-file-ocr', ), ocr_file_path, .merge(token: @access_token.token)) CopyleaksProcess.create(self, response) end |
#create_by_text(text, options = {}) ⇒ Object
uses create-by-text endpoint to create process
46 47 48 49 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 46 def create_by_text(text, = {}) response = api.post(url('create-by-text'), text, .merge(token: @access_token.token)) CopyleaksProcess.create(self, response) end |
#create_by_url(url, options = {}) ⇒ Object
uses create-by-url endpoint to create process
27 28 29 30 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 27 def create_by_url(url, = {}) response = api.post(url('create-by-url'), { 'Url' => url }.to_json, .merge(token: @access_token.token)) CopyleaksProcess.create(self, response) end |
#delete(id) ⇒ Object
deletes process by given id
52 53 54 55 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 52 def delete(id) api.delete(url(:delete, id), token: @access_token.token) true end |
#list ⇒ Object
retries all processes
58 59 60 61 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 58 def list response = api.get(url(:list), token: @access_token.token) response.map { |hash| CopyleaksProcess.create_from_list(self, hash) } end |
#result(id, options = {}) ⇒ Object
retries result information of process with given id
71 72 73 74 75 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 71 def result(id, = {}) response = api.get(url(:result, id), no_callbacks: true, token: @access_token.token) return response if [:raw] CopyleaksApi::CopyleaksProcess.create_from_result(self, id, response) end |
#status(id, options = {}) ⇒ Object
retries status information of process with given id
64 65 66 67 68 |
# File 'lib/copyleaks_api/copyleaks_cloud.rb', line 64 def status(id, = {}) response = api.get(url(:status, id), no_callbacks: true, token: @access_token.token) return response if [:raw] CopyleaksApi::CopyleaksProcess.create_from_status(self, id, response) end |