Class: Abbyy::Client

Inherits:
Object
  • Object
show all
Includes:
Task, XML
Defined in:
lib/abbyy/client.rb

Constant Summary collapse

API_ENDPOINT =
"cloud.ocrsdk.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inflector

#camelize

Methods included from XML

#parse_error, #parse_task

Constructor Details

#initialize(application_id = Abbyy.application_id, password = Abbyy.password) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
# File 'lib/abbyy/client.rb', line 14

def initialize(application_id = Abbyy.application_id, password = Abbyy.password)
  @appliction_id = application_id
  @password = password
  @task = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



46
47
48
49
50
# File 'lib/abbyy/client.rb', line 46

def method_missing(meth, *args, &block)
  api = API.new self
  self.resource = api.execute meth, *args, &block
  current_task
end

Instance Attribute Details

#taskObject (readonly) Also known as: current_task

Returns the value of attribute task.



12
13
14
# File 'lib/abbyy/client.rb', line 12

def task
  @task
end

Instance Method Details

#get(url = task[:resultUrl]) ⇒ String

Retrieve the result of processing task

Parameters:

  • the (String)

    url of the task result

Returns:

  • (String)

    the xml representation



36
37
38
# File 'lib/abbyy/client.rb', line 36

def get(url = task[:resultUrl])
  RestClient.get(url)
end

#list_tasksArray

Returns:

  • (Array)

    the list of tasks created



42
43
44
# File 'lib/abbyy/client.rb', line 42

def list_tasks
  parse_task get("#{url}/listTasks")
end

#urlString

Returns the api url with credentials.

Returns:

  • (String)

    the api url with credentials



21
22
23
24
25
26
27
28
# File 'lib/abbyy/client.rb', line 21

def url
  @url ||= begin
    uri = URI::HTTP.build host: API_ENDPOINT
    uri.user = CGI.escape @appliction_id.to_s
    uri.password = CGI.escape @password.to_s if uri.user
    uri.to_s
  end
end