Class: Semantria::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#authObject (readonly)

Returns the value of attribute auth.



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

def auth
  @auth
end

#consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



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

def consumer_key
  @consumer_key
end

#consumer_secretObject (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_statusObject



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_document(id) ⇒ Object



46
47
48
49
# File 'lib/semantria.rb', line 46

def get_document(id)
  auth.uri = URI.parse(self.class.base_uri + "/document/#{id}.json")
  self.class.get("/document/#{id}.json", verify: false, headers: auth.headers, query: auth.parameters_hash, body: nil)
end

#get_processed_documentsObject



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, id = rand(10 ** 10).to_s) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/semantria.rb', line 24

def queue_document(text, id=rand(10 ** 10).to_s)
  doc = {'id' => id, '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