Class: Vasily::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/vasily/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(auth_token) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/vasily/client.rb', line 10

def initialize(auth_token)
  @auth = { auth_token: auth_token }
end

Instance Method Details

#queue(docs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vasily/client.rb', line 18

def queue(docs)
  body = docs.map(&:to_hash).to_json
  options = { body: body, query: @auth, headers: {'Content-Type' => 'application/json'} }
  response = self.class.post('/entity/queue', options)
  if response.code == 202
    return response['batchId'], response['status']
  else
    fail(Vasily::Error.from_message_and_code(response.body, response.code))
  end
end

#request(batch_id) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/vasily/client.rb', line 29

def request(batch_id)
  options = { query: @auth.merge({ batch_id: batch_id }) }
  response = self.class.get('/entity/request', options)
  if response.code == 200
    return response['status']
  else
    fail(Vasily::Error.from_message_and_code(response.body, response.code))
  end
end

#retrieve(batch_ids) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/vasily/client.rb', line 39

def retrieve(batch_ids)
  batch_ids_query = URI.encode_www_form("batch_id" => batch_ids)
  response = self.class.get('/entity/retrieve?' + batch_ids_query, { query: @auth })
  if response.code == 200
    return response['documents']
  else
    fail(Vasily::Error.from_message_and_code(response.body, response.code))
  end
end

#search(search_query) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/vasily/client.rb', line 49

def search(search_query)
  options = { query: @auth.merge({ search_query: search_query }) }
  response = self.class.get('/entity/search', options)
  if response.code == 200
    return response['documents']
  else
    fail(Vasily::Error.from_message_and_code(response.body, response.code))
  end
end

#statusObject



14
15
16
# File 'lib/vasily/client.rb', line 14

def status
  self.class.get('/status').code
end