Class: Semantria::Client
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
Instance Method Summary collapse
- #check_status ⇒ Object
- #get_processed_documents ⇒ Object
-
#initialize(consumer_key, consumer_secret) ⇒ Client
constructor
A new instance of Client.
- #queue_batch(batch) ⇒ Object
- #queue_document(text) ⇒ Object
Constructor Details
#initialize(consumer_key, consumer_secret) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/semantria.rb', line 14 def initialize(consumer_key, consumer_secret) @auth = Authenticator.new(consumer_key, consumer_secret) @consumer_secret, @consumer_key = consumer_secret, consumer_key end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
12 13 14 |
# File 'lib/semantria.rb', line 12 def auth @auth end |
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
12 13 14 |
# File 'lib/semantria.rb', line 12 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
12 13 14 |
# File 'lib/semantria.rb', line 12 def consumer_secret @consumer_secret end |
Instance Method Details
#check_status ⇒ Object
19 20 21 22 |
# File 'lib/semantria.rb', line 19 def check_status auth.uri = URI.parse(self.class.base_uri + "/status.json") self.class.get("/status.json", verify: false, headers: auth.headers, query: auth.parameters_hash) end |
#get_processed_documents ⇒ Object
41 42 43 44 |
# File 'lib/semantria.rb', line 41 def get_processed_documents auth.uri = URI.parse(self.class.base_uri + "/document/processed.json") self.class.get("/document/processed.json", verify: false, headers: auth.headers, query: auth.parameters_hash, body: nil) end |
#queue_batch(batch) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/semantria.rb', line 32 def queue_batch(batch) auth.uri = URI.parse(self.class.base_uri + "/document/batch") batch = batch.map do |document| {'id' => rand(10 ** 10).to_s.rjust(10, '0'), 'text' => document} end json = JSON.generate batch self.class.post("/document/batch", verify: false, headers: auth.headers, query: auth.parameters_hash, body: json) end |
#queue_document(text) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/semantria.rb', line 24 def queue_document(text) doc = {'id' => rand(10 ** 10).to_s.rjust(10, '0'), 'text' => text} auth.uri = URI.parse(self.class.base_uri + "/document") json = JSON.generate doc self.class.post("/document", verify: false, headers: auth.headers, query: auth.parameters_hash, body: json) end |