Class: Vasily::Client
Instance Method Summary collapse
-
#initialize(auth_token) ⇒ Client
constructor
A new instance of Client.
- #queue(docs) ⇒ Object
- #request(batch_id) ⇒ Object
- #retrieve(batch_ids) ⇒ Object
- #search(search_query) ⇒ Object
- #status ⇒ Object
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 = { body: body, query: @auth, headers: {'Content-Type' => 'application/json'} } response = self.class.post('/entity/queue', ) if response.code == 202 return response['batchId'], response['status'] else fail(Vasily::Error.(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) = { query: @auth.merge({ batch_id: batch_id }) } response = self.class.get('/entity/request', ) if response.code == 200 return response['status'] else fail(Vasily::Error.(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.(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) = { query: @auth.merge({ search_query: search_query }) } response = self.class.get('/entity/search', ) if response.code == 200 return response['documents'] else fail(Vasily::Error.(response.body, response.code)) end end |
#status ⇒ Object
14 15 16 |
# File 'lib/vasily/client.rb', line 14 def status self.class.get('/status').code end |