Class: IODClient
- Inherits:
-
Object
- Object
- IODClient
- Defined in:
- lib/iodruby.rb
Constant Summary collapse
- @@version =
1
- @@apidefault =
1
Instance Method Summary collapse
- #addDoc(doc, index) ⇒ Object
- #addDocs(docs, index, async = false) ⇒ Object
- #connectorstatus(connector) ⇒ Object
- #connectorUtil(connector) ⇒ Object
- #createIndex(name, flavor = "standard", parametric_fields = [], index_fields = []) ⇒ Object
- #deleteConnector(connector) ⇒ Object
- #deleteIndex(index) ⇒ Object
- #getIndex(name) ⇒ Object
- #getResult(jobID) ⇒ Object
- #getStatus(jobID) ⇒ Object
-
#initialize(url, apikey) ⇒ IODClient
constructor
A new instance of IODClient.
- #listIndexes ⇒ Object
- #post(handler, data = Hash.new, async = false) ⇒ Object
- #retrieveConnectorConfig(connector) ⇒ Object
- #startConnector(connector) ⇒ Object
Constructor Details
#initialize(url, apikey) ⇒ IODClient
Returns a new instance of IODClient.
60 61 62 63 64 65 66 |
# File 'lib/iodruby.rb', line 60 def initialize(url, apikey) # Instance variables @url = url @apikey = apikey end |
Instance Method Details
#addDoc(doc, index) ⇒ Object
186 187 188 |
# File 'lib/iodruby.rb', line 186 def addDoc(doc, index) self.addDocs([doc],index) end |
#addDocs(docs, index, async = false) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/iodruby.rb', line 190 def addDocs(docs, index,async=false) # puts docs # puts docs.length #jsondocs= docs.map { |doc| doc.data} jsondocs=docs #puts jsondocs docs=Hash.new docs[:documents]=jsondocs #puts docs.to_json docs=docs.to_json puts docs.length #puts docs #docs=render :json => JSON::dump(docs) data={json:docs,index:index} return self.post("addtotextindex",data,async) end |
#connectorstatus(connector) ⇒ Object
128 129 130 131 |
# File 'lib/iodruby.rb', line 128 def connectorstatus(connector) data=connectorUtil(connector) return post("connectorstatus",data) end |
#connectorUtil(connector) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/iodruby.rb', line 108 def connectorUtil(connector) if index.class.name=="IODConnector" connector=connector.name end data=Hash.new data[:connector]=connector return data end |
#createIndex(name, flavor = "standard", parametric_fields = [], index_fields = []) ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/iodruby.rb', line 168 def createIndex(name,flavor="standard",parametric_fields=[],index_fields=[]) data=Hash.new data[:index]=name data[:flavor]=flavor data[:parametric_fields]=parametric_fields data[:index_fields]=index_fields self.post("createtextindex",data) return IODIndex.new(name,client:self) end |
#deleteConnector(connector) ⇒ Object
101 102 103 104 105 |
# File 'lib/iodruby.rb', line 101 def deleteConnector(connector) data=connectorUtil(connector) delete=post("deleteconnector",data) return delete end |
#deleteIndex(index) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/iodruby.rb', line 86 def deleteIndex(index) if index.class.name=="IODIndex" index=index.name end data=Hash.new data[:index]=index delete=post("deletetextindex",data) confirm=delete.json()["confirm"] data[:confirm]=confirm delete=post("deletetextindex",data) return delete end |
#getIndex(name) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/iodruby.rb', line 158 def getIndex(name) #indexes=self.listIndexes() index=IODIndex.new(name,client:self) #puts (index in indexes) end |
#getResult(jobID) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/iodruby.rb', line 78 def getResult(jobID) data={"apikey"=>@apikey} response=Unirest.post "#{@url}/#{@@version}/job/result/#{jobID}", headers:{ "Accept" => "application/json" }, parameters:data return IODResponse.new(response) end |
#getStatus(jobID) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/iodruby.rb', line 69 def getStatus(jobID) data={"apikey"=>@apikey} response=Unirest.post "#{@url}/#{@@version}/job/status/#{jobID}", headers:{ "Accept" => "application/json" }, parameters:data return IODResponse.new(response) end |
#listIndexes ⇒ Object
178 179 180 181 182 183 |
# File 'lib/iodruby.rb', line 178 def listIndexes() r=post("listindex") indexes=r["index"].map { |index| IODIndex.new(index["index"],index["flavor"],index["type"],client:self)} end |
#post(handler, data = Hash.new, async = false) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/iodruby.rb', line 133 def post(handler, data=Hash.new, async=false) data[:apikey]=@apikey syncpath="sync" if async syncpath="async" end Unirest.timeout(30) response=Unirest.post "#{@url}/#{@@version}/api/#{syncpath}/#{handler}/v#{@@apidefault}", headers:{ "Accept" => "application/json", "Content-Type" => "application/json"}, parameters:data.to_json if response.code == 200 if async return IODAsyncResponse.new(response,self) end return IODResponse.new(response) else puts response.body #puts data[:json].encoding.name raise IODError.new "Error #{response.body["error"]} -- #{response.body["reason"]}" end end |
#retrieveConnectorConfig(connector) ⇒ Object
123 124 125 126 |
# File 'lib/iodruby.rb', line 123 def retrieveConnectorConfig(connector) data=connectorUtil(connector) return post("retrieveconfig",data) end |
#startConnector(connector) ⇒ Object
118 119 120 121 |
# File 'lib/iodruby.rb', line 118 def startConnector(connector) data=connectorUtil(connector) return post("startconnector",data) end |