iodruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +168 -0
- data/Rakefile +2 -0
- data/examples/.DS_Store +0 -0
- data/examples/examples.rb +67 -0
- data/examples/testhelper.rb +2 -0
- data/iodruby.gemspec +25 -0
- data/lib/.DS_Store +0 -0
- data/lib/iodruby/.DS_Store +0 -0
- data/lib/iodruby/version.rb +3 -0
- data/lib/iodruby.rb +364 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59f5c08725693815e3dea872861326aa283defd2
|
4
|
+
data.tar.gz: 87f72a722a9ff5b182a0cae77d52c6ce433d51bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e9b480e267116ae47bba410d8f5bfac5e835d1f9f51f6d3f1b345714a95833ac8f510492dd6dc69a7a30110524f8bdac5cf5e40ae7bc678a32a51cf7ffd569b
|
7
|
+
data.tar.gz: 80db91a0040c189eb9e87bdc786b8cc4bc4950a2b1434444e7647904bb0fa76804bacc4e648b267024f91c0e69e1d8bdd98c89e272c9aef7fe8ee3a72d55355a
|
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# Iodruby
|
2
|
+
|
3
|
+
Ruby Gem to help call IDOL OnDemand API.
|
4
|
+
[http://idolondemand.com](http://idolondemand.com)
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To install from this git repo use the specific_install gem.
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install specific_install
|
13
|
+
gem specific_install http://github.com/lemoogle/iodruby
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
|
20
|
+
### Importing
|
21
|
+
|
22
|
+
```
|
23
|
+
require "iodruby"
|
24
|
+
```
|
25
|
+
|
26
|
+
###Initializing the client
|
27
|
+
|
28
|
+
```
|
29
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
30
|
+
```
|
31
|
+
|
32
|
+
All that is needed to initialize the client is an apikey and the url of the API.
|
33
|
+
|
34
|
+
|
35
|
+
###Sending requests
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
r=client.post('analyzesentiment',{:text=>'I like cats'})
|
39
|
+
```
|
40
|
+
The client's *post* method takes the apipath that you're sending your request to as well as an object containing the parameters you want to send to the api. You do not need to send your apikey each time as the client will handle that automatically
|
41
|
+
|
42
|
+
###Posting files
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
r=client.post('ocrdocument',{:file=>File.new("/path/to/file", 'rb')})
|
46
|
+
```
|
47
|
+
Sending files is just as easy.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
r=client.post('ocrdocument',{:mode=>'photo',:file=>File.new("/path/to/file", 'rb')})
|
51
|
+
r=client.post('ocrdocument',{:mode=>'photo',:file=>File.new("/path/to/file", 'rb')})
|
52
|
+
```
|
53
|
+
Any extra parameters should be added in the same way as regular calls, or in the data parameter.
|
54
|
+
|
55
|
+
###Parsing the output
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
myjson=r.json()
|
59
|
+
```
|
60
|
+
|
61
|
+
The object returned is a response object from the python [requests library](http://docs.python-requests.org/en/latest/) and can easily be turned to json.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
docs=myjson["documents"]
|
65
|
+
array.each {|doc| puts doc["title"] }
|
66
|
+
```
|
67
|
+
|
68
|
+
###Indexing
|
69
|
+
|
70
|
+
**Creating an index**
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
index=client.createIndex("mytestindex",flavor="explorer")
|
74
|
+
```
|
75
|
+
|
76
|
+
An Index object can easily be created
|
77
|
+
|
78
|
+
**Fetching indexes/an index**
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
index = client.getIndex('myindex')
|
82
|
+
```
|
83
|
+
The getIndex call will return an iodindex Index object but will not check for existence.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
indexes = client.listIndexes()
|
87
|
+
indexes.fetch('myindex',client.createIndex('myindex'))
|
88
|
+
```
|
89
|
+
|
90
|
+
Here we first check the list of our indexes and return a newly created index if the index does not already exist
|
91
|
+
|
92
|
+
**Deleting an index**
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
index.delete()
|
96
|
+
client.deleteIndex('myindex')
|
97
|
+
```
|
98
|
+
An index can be deleted in two equivalent ways
|
99
|
+
|
100
|
+
**Indexing documents**
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
doc1=IODDoc.new({title:"title1",reference:"doc1",content:"my content 1"})
|
104
|
+
doc2=IODDoc.new({title:"title2",reference:"doc2",content:"my content 2"})
|
105
|
+
```
|
106
|
+
Documents can be created as regular python objects
|
107
|
+
|
108
|
+
```
|
109
|
+
index.addDoc(doc1)
|
110
|
+
index.addDocs([doc1,doc2])
|
111
|
+
```
|
112
|
+
|
113
|
+
They can be added directly one at a time or in a batch.
|
114
|
+
|
115
|
+
```
|
116
|
+
for doc in docs:
|
117
|
+
index.pushDoc(doc)
|
118
|
+
index.commit()
|
119
|
+
```
|
120
|
+
|
121
|
+
An alternative to *addDocs* and easy way to keep batch documents is to use the pushDoc method, the index will keep in memory a list of the documents it needs to index.
|
122
|
+
|
123
|
+
```
|
124
|
+
if index.countDocs()>10:
|
125
|
+
index.commit()
|
126
|
+
```
|
127
|
+
|
128
|
+
It makes it easy to batch together groups of documents.
|
129
|
+
|
130
|
+
####Indexing - Connectors
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
134
|
+
conn=IODConnector.new("mytestconnector",client)
|
135
|
+
conn.create(type="web",config={ "url" => "http://www.idolondemand.com" })
|
136
|
+
conn.delete()
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
### Asynchronous request
|
141
|
+
|
142
|
+
For each call the Async parameter can be set to true to send an asynchronous request.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
r=client.post('analyzesentiment',{:text=>'I like cats'},async=True)
|
146
|
+
print r.json()
|
147
|
+
|
148
|
+
# will return status of call, queued or finished
|
149
|
+
puts r.status().json()
|
150
|
+
# Will wait until result to return
|
151
|
+
puts r.result().json()
|
152
|
+
```
|
153
|
+
|
154
|
+
Same thing for indexing.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
r=index.commit(async=True)
|
158
|
+
```
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
1. Fork it ( https://github.com/lemoogle/iodruby/fork )
|
165
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
166
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
167
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
168
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/examples/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative "../lib/iodruby.rb"
|
2
|
+
|
3
|
+
$apikey="yourapikey"
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
def test_post
|
8
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
9
|
+
r=client.post("querytextindex",{:text=>"hello",:absolute_max_result=>1000})
|
10
|
+
puts "\n",r.json()["documents"][0]["reference"],"\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_post_async
|
15
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
16
|
+
r=client.post("querytextindex",{:text=>"hello"},async=true)
|
17
|
+
#returns jobid
|
18
|
+
puts r.jobID
|
19
|
+
# will return status of call, queued or finished
|
20
|
+
puts r.status().json()
|
21
|
+
# Will wait until result to return
|
22
|
+
puts r.result().json()
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def test_indexing(index="mytestindex")
|
28
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
29
|
+
index=client.getIndex("myrssdb")
|
30
|
+
|
31
|
+
doc={:title=>"title",:reference=>"ref",:content=>"content"}
|
32
|
+
index.pushDoc(doc)
|
33
|
+
puts index.commit().json()
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
def test_createIndex
|
39
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
40
|
+
index=client.createIndex("mytestindex",flavor="explorer")
|
41
|
+
puts index.json()
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
def test_deleteIndex
|
47
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
48
|
+
puts client.deleteIndex("mytestindex")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_createConnector
|
52
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
53
|
+
conn=IODConnector.new("mytestconnector",client)
|
54
|
+
puts conn.create(type="web",config={ "url" => "http://www.idolondemand.com" })
|
55
|
+
puts conn.delete()
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_sentiment
|
59
|
+
|
60
|
+
client= IODClient.new("http://api.idolondemand.com",$apikey)
|
61
|
+
r=client.post('analyzesentiment',{'text'=>'I like cats'})
|
62
|
+
puts r.json()
|
63
|
+
end
|
64
|
+
|
65
|
+
test_sentiment()
|
66
|
+
|
67
|
+
#test_createIndex()
|
data/iodruby.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iodruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iodruby"
|
8
|
+
spec.version = Iodruby::VERSION
|
9
|
+
spec.authors = ["Tyler Nappy" ," Martin Zerbib"]
|
10
|
+
spec.email = ["tyler.nappy@hpe.com" ,"martin.zerbib@hp.com"]
|
11
|
+
spec.summary = %q{Idol OnDemand Ruby Client}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/HP-IDOL-OnDemand/iodruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "unirest"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
data/lib/iodruby.rb
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'Unirest'
|
4
|
+
require 'json'
|
5
|
+
#require 'httpclient'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
class IODError < StandardError
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
class IODResponse
|
19
|
+
|
20
|
+
attr_accessor :response
|
21
|
+
|
22
|
+
def initialize(response)
|
23
|
+
#@query=query
|
24
|
+
|
25
|
+
@response=response
|
26
|
+
end
|
27
|
+
|
28
|
+
def json()
|
29
|
+
@response.body
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class IODAsyncResponse < IODResponse
|
35
|
+
|
36
|
+
attr_accessor :response
|
37
|
+
attr_accessor :jobID
|
38
|
+
def initialize(response,client)
|
39
|
+
#@query=query
|
40
|
+
@response=response
|
41
|
+
@client=client
|
42
|
+
@jobID =response.body["jobID"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def status()
|
46
|
+
@client.getStatus(@jobID)
|
47
|
+
end
|
48
|
+
|
49
|
+
def result()
|
50
|
+
@client.getResult(@jobID)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
class IODClient
|
58
|
+
@@version=1
|
59
|
+
@@apidefault=1
|
60
|
+
def initialize(url, apikey)
|
61
|
+
# Instance variables
|
62
|
+
|
63
|
+
@url = url
|
64
|
+
@apikey = apikey
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def getStatus(jobID)
|
70
|
+
data={"apikey"=>@apikey}
|
71
|
+
response=Unirest.post "#{@url}/#{@@version}/job/status/#{jobID}",
|
72
|
+
headers:{ "Accept" => "application/json" },
|
73
|
+
parameters:data
|
74
|
+
return IODResponse.new(response)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def getResult(jobID)
|
79
|
+
data={"apikey"=>@apikey}
|
80
|
+
response=Unirest.post "#{@url}/#{@@version}/job/result/#{jobID}",
|
81
|
+
headers:{ "Accept" => "application/json" },
|
82
|
+
parameters:data
|
83
|
+
return IODResponse.new(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
def deleteIndex(index)
|
87
|
+
if index.class.name=="IODIndex"
|
88
|
+
index=index.name
|
89
|
+
end
|
90
|
+
|
91
|
+
data=Hash.new
|
92
|
+
data[:index]=index
|
93
|
+
|
94
|
+
delete=post("deletetextindex",data)
|
95
|
+
confirm=delete.json()["confirm"]
|
96
|
+
data[:confirm]=confirm
|
97
|
+
delete=post("deletetextindex",data)
|
98
|
+
return delete
|
99
|
+
end
|
100
|
+
|
101
|
+
def deleteConnector(connector)
|
102
|
+
data=connectorUtil(connector)
|
103
|
+
delete=post("deleteconnector",data)
|
104
|
+
return delete
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def connectorUtil(connector)
|
109
|
+
if index.class.name=="IODConnector"
|
110
|
+
connector=connector.name
|
111
|
+
end
|
112
|
+
data=Hash.new
|
113
|
+
data[:connector]=connector
|
114
|
+
return data
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def startConnector(connector)
|
119
|
+
data=connectorUtil(connector)
|
120
|
+
return post("startconnector",data)
|
121
|
+
end
|
122
|
+
|
123
|
+
def retrieveConnectorConfig(connector)
|
124
|
+
data=connectorUtil(connector)
|
125
|
+
return post("retrieveconfig",data)
|
126
|
+
end
|
127
|
+
|
128
|
+
def connectorstatus(connector)
|
129
|
+
data=connectorUtil(connector)
|
130
|
+
return post("connectorstatus",data)
|
131
|
+
end
|
132
|
+
|
133
|
+
def post(handler, data=Hash.new, async=false)
|
134
|
+
data[:apikey]=@apikey
|
135
|
+
syncpath="sync"
|
136
|
+
if async
|
137
|
+
syncpath="async"
|
138
|
+
end
|
139
|
+
Unirest.timeout(30)
|
140
|
+
response=Unirest.post "#{@url}/#{@@version}/api/#{syncpath}/#{handler}/v#{@@apidefault}",
|
141
|
+
headers:{ "Accept" => "application/json" },
|
142
|
+
parameters:data
|
143
|
+
if response.code == 200
|
144
|
+
|
145
|
+
if async
|
146
|
+
return IODAsyncResponse.new(response,self)
|
147
|
+
end
|
148
|
+
return IODResponse.new(response)
|
149
|
+
else
|
150
|
+
puts response.body
|
151
|
+
#puts data[:json].encoding.name
|
152
|
+
raise IODError.new "Error #{response.body["error"]} -- #{response.body["reason"]}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
def getIndex(name)
|
159
|
+
#indexes=self.listIndexes()
|
160
|
+
|
161
|
+
index=IODIndex.new(name,client:self)
|
162
|
+
#puts (index in indexes)
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
def createIndex(name,flavor="standard",parametric_fields=[],index_fields=[])
|
169
|
+
data=Hash.new
|
170
|
+
data[:index]=name
|
171
|
+
data[:flavor]=flavor
|
172
|
+
data[:parametric_fields]=parametric_fields
|
173
|
+
data[:index_fields]=index_fields
|
174
|
+
self.post("createtextindex",data)
|
175
|
+
return IODIndex.new(name,client:self)
|
176
|
+
end
|
177
|
+
|
178
|
+
def listIndexes()
|
179
|
+
r=post("listindex")
|
180
|
+
|
181
|
+
indexes=r["index"].map { |index| IODIndex.new(index["index"],index["flavor"],index["type"],client:self)}
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
def addDoc(doc, index)
|
187
|
+
self.addDocs([doc],index)
|
188
|
+
end
|
189
|
+
|
190
|
+
def addDocs(docs, index,async=false)
|
191
|
+
|
192
|
+
|
193
|
+
# puts docs
|
194
|
+
# puts docs.length
|
195
|
+
#jsondocs= docs.map { |doc| doc.data}
|
196
|
+
jsondocs=docs
|
197
|
+
#puts jsondocs
|
198
|
+
docs=Hash.new
|
199
|
+
docs[:documents]=jsondocs
|
200
|
+
|
201
|
+
#puts docs.to_json
|
202
|
+
docs=docs.to_json
|
203
|
+
puts docs.length
|
204
|
+
#puts docs
|
205
|
+
#docs=render :json => JSON::dump(docs)
|
206
|
+
data={json:docs,index:index}
|
207
|
+
|
208
|
+
return self.post("addtotextindex",data,async)
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
class IODConnector
|
214
|
+
|
215
|
+
attr_reader :client
|
216
|
+
attr_reader :name
|
217
|
+
|
218
|
+
|
219
|
+
def initialize(name,client=nil)
|
220
|
+
@name=name
|
221
|
+
@client=client
|
222
|
+
end
|
223
|
+
|
224
|
+
def create(type="web",config=Hash.new, destination="", schedule="",description="")
|
225
|
+
config("addtotextindex",type,config,destination,schedule,description)
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
def update(type="web",config=Hash.new, destination="", schedule="",description="")
|
230
|
+
config("addtotextindex",type,config,destination,schedule,description)
|
231
|
+
end
|
232
|
+
|
233
|
+
def config(method,type="",config="", destination="", schedule="",description="")
|
234
|
+
data=Hash.new
|
235
|
+
data[:connector]=@name
|
236
|
+
if type!=""
|
237
|
+
data[:type]=type
|
238
|
+
end
|
239
|
+
if config!=""
|
240
|
+
data[:config]=JSON.dump config
|
241
|
+
end
|
242
|
+
if destination!=""
|
243
|
+
destination={"action"=>"addtotextindex", "index" => destination }
|
244
|
+
data[:destination]=JSON.dump destination
|
245
|
+
end
|
246
|
+
if schedule != ""
|
247
|
+
data[:schedule]=JSON.dump schedule
|
248
|
+
end
|
249
|
+
data[:description]=description
|
250
|
+
result=@client.post(method,data)
|
251
|
+
puts result
|
252
|
+
end
|
253
|
+
|
254
|
+
def delete()
|
255
|
+
@client.deleteConnector(@name)
|
256
|
+
end
|
257
|
+
|
258
|
+
def config()
|
259
|
+
@client.retrieveConnectorConfig(@name)
|
260
|
+
end
|
261
|
+
|
262
|
+
def status()
|
263
|
+
@client.connectorStatus(@name)
|
264
|
+
end
|
265
|
+
|
266
|
+
def ==(other_object)
|
267
|
+
comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && @name == other_object.name)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
class IODIndex
|
276
|
+
|
277
|
+
attr_reader :client
|
278
|
+
attr_reader :name
|
279
|
+
|
280
|
+
|
281
|
+
def initialize(name,flavor="standard",type="normal",client:nil)
|
282
|
+
@name=name
|
283
|
+
|
284
|
+
@client=client
|
285
|
+
@docs=[]
|
286
|
+
end
|
287
|
+
|
288
|
+
def query(text,data=Hash.new)
|
289
|
+
data[:database_match]=@name
|
290
|
+
|
291
|
+
data[:text]=text
|
292
|
+
result=@client.post("querytextindex",data)
|
293
|
+
result["documents"].map!{|doc| IODDoc.new(doc) }
|
294
|
+
return result
|
295
|
+
end
|
296
|
+
def size()
|
297
|
+
return @docs.length
|
298
|
+
end
|
299
|
+
def pushDoc(doc)
|
300
|
+
@docs.push(doc)
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
def commit(async=false)
|
305
|
+
# docs={document:@docs}
|
306
|
+
# data={json:docs.to_json,index:@name}
|
307
|
+
# puts docs.to_json
|
308
|
+
|
309
|
+
#r=@client.post("addtotextindex",data)
|
310
|
+
#@docs=[]
|
311
|
+
response=addDocs(@docs,async)
|
312
|
+
@docs=[]
|
313
|
+
return response
|
314
|
+
end
|
315
|
+
|
316
|
+
def addDoc(doc)
|
317
|
+
docs=Hash.new
|
318
|
+
|
319
|
+
# docs[:document]=[doc.data]
|
320
|
+
# data={json:docs.to_json,index:@name}
|
321
|
+
# @client.postasync("addtotextindex",data)
|
322
|
+
puts @client.addDoc(doc,@name)
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
def addDocs(docs,async=false)
|
327
|
+
|
328
|
+
# docs[:document]=[doc.data]
|
329
|
+
# data={json:docs.to_json,index:@name}
|
330
|
+
# @client.postasync("addtotextindex",data)
|
331
|
+
|
332
|
+
return @client.addDocs(docs,@name,async)
|
333
|
+
end
|
334
|
+
|
335
|
+
def delete()
|
336
|
+
clientcheck()
|
337
|
+
@client.deleteIndex(self)
|
338
|
+
end
|
339
|
+
|
340
|
+
def ==(other_object)
|
341
|
+
comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && @name == other_object.name)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
class IODDoc
|
348
|
+
|
349
|
+
attr_accessor :data
|
350
|
+
attr_accessor :sentiment
|
351
|
+
attr_accessor :entities
|
352
|
+
def initialize(data)
|
353
|
+
#@query=query
|
354
|
+
@entities=Hash.new
|
355
|
+
@data=data
|
356
|
+
end
|
357
|
+
|
358
|
+
def to_json(options={})
|
359
|
+
return render :json => JSON::dump(@data)
|
360
|
+
end
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iodruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Nappy
|
8
|
+
- " Martin Zerbib"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: unirest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.7'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.7'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
description: ''
|
57
|
+
email:
|
58
|
+
- tyler.nappy@hpe.com
|
59
|
+
- martin.zerbib@hp.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".DS_Store"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- examples/.DS_Store
|
70
|
+
- examples/examples.rb
|
71
|
+
- examples/testhelper.rb
|
72
|
+
- iodruby.gemspec
|
73
|
+
- lib/.DS_Store
|
74
|
+
- lib/iodruby.rb
|
75
|
+
- lib/iodruby/.DS_Store
|
76
|
+
- lib/iodruby/version.rb
|
77
|
+
homepage: https://github.com/HP-IDOL-OnDemand/iodruby
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Idol OnDemand Ruby Client
|
101
|
+
test_files: []
|