havenondemand 1.0.0
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/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +190 -0
- data/Rakefile +2 -0
- data/examples/.DS_Store +0 -0
- data/examples/examples.rb +67 -0
- data/examples/testhelper.rb +2 -0
- data/havenondemand.gemspec +25 -0
- data/lib/.DS_Store +0 -0
- data/lib/havenondemand.rb +364 -0
- data/lib/havenondemand/.DS_Store +0 -0
- data/lib/havenondemand/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a52f32e712338fbd323f1e7a584ab9f3fc44cc03
|
4
|
+
data.tar.gz: e37d432c750aea108909076cf0a0e63e1f2c02bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9831a62983b60163edd61293f9462825769bacae05331037af3994745dc7be5aa7f5aa3c77da47d7a1bee8bfd32798342cc2907e63a98b43b184cd1257542ca9
|
7
|
+
data.tar.gz: 30f9608b194bdbb656a0895509ba6af352466f9f3fbb95fc4b9b69ff635ac3cb90b4dc90d679238b98d6a6f8c69f5c81aa2c4ff08d6d31699611448ab6a1e8cc
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
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,190 @@
|
|
1
|
+
# Ruby gem for Haven OnDemand
|
2
|
+
Official client library to help with calling Haven OnDemand APIs [http://havenondemand.com](http://havenondemand.com).
|
3
|
+
|
4
|
+
## What is Haven OnDemand?
|
5
|
+
Haven OnDemand is a set of over 70 APIs for handling all sorts of unstructured data. Here are just some of our APIs' capabilities:
|
6
|
+
* Speech to text
|
7
|
+
* OCR
|
8
|
+
* Text extraction
|
9
|
+
* Indexing documents
|
10
|
+
* Smart search
|
11
|
+
* Language identification
|
12
|
+
* Concept extraction
|
13
|
+
* Sentiment analysis
|
14
|
+
* Web crawlers
|
15
|
+
* Machine learning
|
16
|
+
|
17
|
+
For a full list of all the APIs and to try them out, check out https://www.havenondemand.com/developer/apis
|
18
|
+
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
To install from rubygems.org.
|
23
|
+
|
24
|
+
```
|
25
|
+
gem install havenondemand
|
26
|
+
```
|
27
|
+
|
28
|
+
To install the latest version from this github repo, use the specific_install gem.
|
29
|
+
|
30
|
+
```
|
31
|
+
gem install specific_install
|
32
|
+
gem specific_install https://github.com/HP-Haven-OnDemand/havenondemand-ruby
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
|
39
|
+
### Importing
|
40
|
+
When using rails and other frameworks with a gem file, include it in it.
|
41
|
+
```ruby
|
42
|
+
gem "havenondemand"
|
43
|
+
```
|
44
|
+
Or, require it directly in your app.
|
45
|
+
```ruby
|
46
|
+
require "havenondemand"
|
47
|
+
```
|
48
|
+
|
49
|
+
###Initializing the client
|
50
|
+
*Note*: URL endpoint will change in the near future to
|
51
|
+
```ruby
|
52
|
+
client = HODClient.new("http://api.idolondemand.com", $apikey)
|
53
|
+
```
|
54
|
+
|
55
|
+
All that is needed to initialize the client is an apikey and the url of the API.
|
56
|
+
|
57
|
+
|
58
|
+
###Sending requests
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
r = client.post('analyzesentiment', {:text=>'I like cats'})
|
62
|
+
```
|
63
|
+
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
|
64
|
+
|
65
|
+
###Posting files
|
66
|
+
```ruby
|
67
|
+
r = client.post('ocrdocument', {:file=>File.new("/path/to/file", 'rb')})
|
68
|
+
```
|
69
|
+
Sending files is just as easy.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
r = client.post('ocrdocument', {:mode=>'photo',:file=>File.new("/path/to/file", 'rb')})
|
73
|
+
r = client.post('ocrdocument', {:mode=>'photo',:file=>File.new("/path/to/file", 'rb')})
|
74
|
+
```
|
75
|
+
Any extra parameters should be added in the same way as regular calls, or in the data parameter.
|
76
|
+
|
77
|
+
###Parsing the output
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
myjson = r.json()
|
81
|
+
```
|
82
|
+
|
83
|
+
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.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
docs = myjson["documents"]
|
87
|
+
array.each {|doc| puts doc["title"] }
|
88
|
+
```
|
89
|
+
|
90
|
+
###Indexing
|
91
|
+
|
92
|
+
**Creating an index**
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
index = client.createIndex("mytestindex", flavor="explorer")
|
96
|
+
```
|
97
|
+
|
98
|
+
An Index object can easily be created
|
99
|
+
|
100
|
+
**Fetching indexes/an index**
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
index = client.getIndex('myindex')
|
104
|
+
```
|
105
|
+
The getIndex call will return an hodindex Index object but will not check for existence.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
indexes = client.listIndexes()
|
109
|
+
indexes.fetch('myindex', client.createIndex('myindex'))
|
110
|
+
```
|
111
|
+
|
112
|
+
Here we first check the list of our indexes and return a newly created index if the index does not already exist
|
113
|
+
|
114
|
+
**Deleting an index**
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
index.delete()
|
118
|
+
client.deleteIndex('myindex')
|
119
|
+
```
|
120
|
+
An index can be deleted in two equivalent ways
|
121
|
+
|
122
|
+
**Indexing documents**
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
doc1 = HODDoc.new({title: "title1", reference: "doc1", content: "my content 1"})
|
126
|
+
doc2 = HODDoc.new({title: "title2", reference: "doc2", content: "my content 2"})
|
127
|
+
```
|
128
|
+
Documents can be created as regular python objects
|
129
|
+
|
130
|
+
```
|
131
|
+
index.addDoc(doc1)
|
132
|
+
index.addDocs([doc1,doc2])
|
133
|
+
```
|
134
|
+
|
135
|
+
They can be added directly one at a time or in a batch.
|
136
|
+
|
137
|
+
```
|
138
|
+
for doc in docs:
|
139
|
+
index.pushDoc(doc)
|
140
|
+
index.commit()
|
141
|
+
```
|
142
|
+
|
143
|
+
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.
|
144
|
+
|
145
|
+
```
|
146
|
+
if index.countDocs()>10:
|
147
|
+
index.commit()
|
148
|
+
```
|
149
|
+
|
150
|
+
It makes it easy to batch together groups of documents.
|
151
|
+
|
152
|
+
####Indexing - Connectors
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
client = HODClient.new("http://api.idolondemand.com", $apikey)
|
156
|
+
conn = HODConnector.new("mytestconnector", client)
|
157
|
+
conn.create(type="web", config = { "url" => "http://www.idolondemand.com" })
|
158
|
+
conn.delete()
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
### Asynchronous request
|
163
|
+
|
164
|
+
For each call the Async parameter can be set to true to send an asynchronous request.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
r = client.post('analyzesentiment', {:text => 'I like cats'}, async = true)
|
168
|
+
print r.json()
|
169
|
+
|
170
|
+
# will return status of call, queued or finished
|
171
|
+
puts r.status().json()
|
172
|
+
# Will wait until result to return
|
173
|
+
puts r.result().json()
|
174
|
+
```
|
175
|
+
|
176
|
+
Same thing for indexing.
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
r = index.commit(async = true)
|
180
|
+
```
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
1. Fork it ( https://github.com/HP-Haven-OnDemand/havenondemand-ruby/fork )
|
187
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
188
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
189
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
190
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/examples/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative "../lib/havenondemand.rb"
|
2
|
+
|
3
|
+
$apikey="yourapikey"
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
def test_post
|
8
|
+
client= HODClient.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= HODClient.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= HODClient.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= HODClient.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= HODClient.new("http://api.idolondemand.com",$apikey)
|
48
|
+
puts client.deleteIndex("mytestindex")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_createConnector
|
52
|
+
client= HODClient.new("http://api.idolondemand.com",$apikey)
|
53
|
+
conn=HODConnector.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= HODClient.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()
|
@@ -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 'havenondemand/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "havenondemand"
|
8
|
+
spec.version = Havenondemand::VERSION
|
9
|
+
spec.authors = ["Tyler Nappy" ," Martin Zerbib"]
|
10
|
+
spec.email = ["tyler.nappy@hpe.com"]
|
11
|
+
spec.summary = %q{Haven OnDemand Ruby Client}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/HP-Haven-OnDemand/havenondemand-ruby"
|
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
|
@@ -0,0 +1,364 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'Unirest'
|
4
|
+
require 'json'
|
5
|
+
#require 'httpclient'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
class HODError < StandardError
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
class HODResponse
|
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 HODAsyncResponse < HODResponse
|
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 HODClient
|
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 HODResponse.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 HODResponse.new(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
def deleteIndex(index)
|
87
|
+
if index.class.name=="HODIndex"
|
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=="HODConnector"
|
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", "Content-Type" => "application/json"},
|
142
|
+
parameters:data.to_json
|
143
|
+
if response.code == 200
|
144
|
+
|
145
|
+
if async
|
146
|
+
return HODAsyncResponse.new(response,self)
|
147
|
+
end
|
148
|
+
return HODResponse.new(response)
|
149
|
+
else
|
150
|
+
puts response.body
|
151
|
+
#puts data[:json].encoding.name
|
152
|
+
raise HODError.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=HODIndex.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 HODIndex.new(name,client:self)
|
176
|
+
end
|
177
|
+
|
178
|
+
def listIndexes()
|
179
|
+
r=post("listindex")
|
180
|
+
|
181
|
+
indexes=r["index"].map { |index| HODIndex.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 HODConnector
|
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 HODIndex
|
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| HODDoc.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 HODDoc
|
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
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: havenondemand
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Nappy
|
8
|
+
- " Martin Zerbib"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-08 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
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".DS_Store"
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- examples/.DS_Store
|
70
|
+
- examples/examples.rb
|
71
|
+
- examples/testhelper.rb
|
72
|
+
- havenondemand.gemspec
|
73
|
+
- lib/.DS_Store
|
74
|
+
- lib/havenondemand.rb
|
75
|
+
- lib/havenondemand/.DS_Store
|
76
|
+
- lib/havenondemand/version.rb
|
77
|
+
homepage: https://github.com/HP-Haven-OnDemand/havenondemand-ruby
|
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: Haven OnDemand Ruby Client
|
101
|
+
test_files: []
|