Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ccaf73d
updated README
tylerjnap Sep 22, 2015
e99589d
updated version
tylerjnap Sep 22, 2015
215bed6
updated README
tylerjnap Sep 22, 2015
0edca05
updated REDAME
tylerjnap Sep 27, 2015
8a837b8
added gitignore
tylerjnap Oct 7, 2015
9e388e2
updated to Haven from IDOL
tylerjnap Oct 7, 2015
c32d531
changed package name and added contributors
tylerjnap Oct 8, 2015
6bdcf62
updated README
tylerjnap Oct 8, 2015
54ad22e
changed url
tylerjnap Oct 8, 2015
332c3f6
updated verision number
tylerjnap Oct 8, 2015
b21a2d8
updated note at top of README for versioning
tylerjnap Oct 8, 2015
24738bb
updated constructor - removed typing URL and added optional parameter…
tylerjnap Dec 9, 2015
4bffa3c
changed to https
tylerjnap Dec 9, 2015
bcfe5bc
updated README and version
tylerjnap Dec 9, 2015
6454071
updated README
tylerjnap Mar 8, 2016
814b5fc
added LICENSE.txt
tylerjnap Mar 22, 2016
06ba681
updated for staging
tylerjnap Apr 7, 2016
a89b7f5
updated version
tylerjnap Apr 7, 2016
92c4c03
added status and result API
tylerjnap Apr 12, 2016
6ceae80
updated README
tylerjnap Apr 28, 2016
3d25653
updated for proxies
tylerjnap May 3, 2016
6d107dd
updated README and version
tylerjnap May 3, 2016
786230c
updated README for proxy example
tylerjnap May 3, 2016
ea83be8
updated error handling
tylerjnap May 20, 2016
1fdf796
updated version
tylerjnap May 20, 2016
77362de
added preliminary support for Job API
tylerjnap Jun 16, 2016
f9c6d7f
added error handling for async batch job
tylerjnap Jun 16, 2016
9118b8a
added post and get requests
tylerjnap Jun 22, 2016
b03bc0e
updated README for batch and get request
tylerjnap Jun 22, 2016
0e7a08f
updated error handling
tylerjnap Jul 15, 2016
c519a41
added POST request for combinations
tylerjnap Oct 25, 2016
b5c1fc3
updated README
tylerjnap Oct 26, 2016
89d544c
updated version to 1.3.0
tylerjnap Oct 26, 2016
4aa7700
fixed get requests
tylerjnap Nov 3, 2016
4218b17
fixed get requests
tylerjnap Nov 3, 2016
ca11e43
Merge remote-tracking branch 'origin/get_request'
PacoVu Nov 3, 2016
63a2c79
Major changes
PacoVu Dec 2, 2016
4dc5daf
Update index.js
PacoVu Dec 2, 2016
3f138e1
Updated lib structure
PacoVu Dec 2, 2016
360cbc1
Removed redundant codes
PacoVu Dec 2, 2016
5108866
Updated hodneedle
PacoVu Dec 2, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.DS_Store
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 TODO: Tyler Nappy

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
194 changes: 164 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,199 @@
# Node JS client library for IDOL OnDemand

Basic library to help with calling IDOL OnDemand APIs [http://idolondemand.com](http://idolondemand.com)
**Note:** formerly known as `iod-node`. For the older version, see the `iod` branch.

# Node JS client library for Haven OnDemand
Official client library to help with calling Haven OnDemand APIs [http://havenondemand.com](http://havenondemand.com).

## What is Haven OnDemand?
Haven OnDemand is a set of over 60 APIs for handling all sorts of unstructured data. Here are just some of our APIs' capabilities:
* Speech to text
* OCR
* Text extraction
* Indexing documents
* Smart search
* Language identification
* Concept extraction
* Sentiment analysis
* Web crawlers
* Machine learning

For a full list of all the APIs and to try them out, check out https://www.havenondemand.com/developer/apis

### Installation

To install, run the following command:
```
npm install git+<repourl>
npm install havenondemand
```
If you want to install the latest module directly from Github, use the following command:
```
npm install git+https://github.com/HP-Haven-OnDemand/havenondemand-node
```

### Start

### Include it
```js
var iod = require('iod-node')
client= new iod.IODClient('http://api.idolondemand.com','apikey')
var havenondemand = require('havenondemand')
var client = new havenondemand.HODClient(apikey, version, proxy)
```
You can find your API key [here](https://www.haveondemand.com/account/api-keys.html) after signing up.

### Callbacks
`version` is an optional parameter (defaults to `'v1'`) and can be either `'v1'` or `'v2'`.

`proxy` is an optional parameter. Please set this if you're behind a firewall. Here is an example of iniating the client if you're using a proxy:
```js
var havenondemand = require('havenondemand')
var client = new havenondemand.HODClient('123456-asdf', 'v1', 'http://user:pass@proxy.server.com:3128')
```
### Callback
We must define a callback function and pass it as an argument
```js
var callback = function(err,resp,body){
console.log(body)
}
var data = {'text' : 'I like cats'}
client.post('analyzesentiment', data, false, callback)
```

We can define our callbacks as functions and pass them as arguments

The order of the arguments is strict. It must be in the following order:
method("api_name", {params}, async=[true|false], callback_method)
```js
var data = {'text' : 'I like cats'}
client.post('analyzesentiment', data, false, callback)
```
var data= {'text':'I like cats'}
client.call('analyzesentiment',callback,data)

### GET request
APIs can be accessed via a GET request.
```js
var data = {'text' : 'I like cats'}
client.get('analyzesentiment', data, false, function(err, resp, body) {
if (!err) {
console.log(resp.body)
}
})
```

Or we can use the .on('data') hook to do the same thing.
### Async calls

While node will mostly deals with processes asynchronously, Haven OnDemand offers server side asynchronous call methods which should be used with large files and slow queries. Pass a boolean for the async parameter. The API response will return back a job ID which is used to check the status or result of your API request.
```js
var jobID
var data = {'text': 'I love dogs'}
client.post('analyzesentiment', data, true, function(err, resp, body) {
jobID = resp.body.jobID
console.log(jobID)
})
```
**(Recommended method)** To check the status of your API call, use the following code with the jobID from obtained from the async call above. This will tell you if it's still processing or if it's complete, and if so, it will return the result.
```js
client.getJobStatus(jobID, function(err, resp, body) {
console.log(resp.body)
})
```
client.call('analyzesentiment',data).on('data',callback)
Or, to check the result of your API call, use the following code with the jobID obtained from the async call. *Note: This method may timeout if your async API call is still processing.*
```js
client.getJobResult(jobID, function(err, resp, body) {
console.log(resp.body)
})
```

THe order of the arguments after the api name don't matter when passed.
### Posting files

```
client.call('analyzesentiment',data,callback)
File posting is handled using the "file" parameter name which is used for all current file postings in Haven OnDemand

```js
var data = {'file' : 'test.txt'}
client.post('analyzesentiment', data, false, function(err, resp, body) {
if (err) {
console.log(err)
} else {
console.log(resp.body)
}
})
```

### Combinations

### Async calls

While node will mostly deal with things asynchronously, IDOL OnDemand offers a servetr side asynchronous calls method which should be used with large files and slow queries.
Haven OnDemand allows to chain two ore more APIs together to create customizable, reusable services. These combinations enable one data input to have unlimited transformations and processing all from a single API call.

If you created a combination API name "sentimentanalysistoindex" which takes input as plain text. You can call the combination API from the code shown below:
```js
var params = {text : "Haven OnDemand is awesome."};
client.post_combination('sentimentanalysistoindex', params, false, function(err, resp, body) {
if (err) {
console.log(err)
} else {
console.log(resp.body)
}
})
```
client.call('analyzesentiment',callback,data,true)
If you created a combination API name "sentimentanalysistoindex" which takes JSON input and presumed that the name of your input is "jsoninput". And your combination API was defined to parse the jsonContent similar to the format below. You can call the combination API from the code as follows:
```js
var jsonContent = '{"arrayinput":[{"content":"Haven OnDemand is awesome."},{"content":"Sentiment Analysis API is very usefule."}]}'
var params = {}
params.jsoninput = jsonContent
client.get_combination('sentimentanalysistoindex', params, false, function(err, resp, body) {
if (err) {
console.log(err)
} else {
console.log(resp.body)
}
})
```
If you created a combination API name "sentimentanalysistoindex" which takes a file input and presumed that the name of your input is "textfile". And your combination API was defined to take also the language configuration. You can call the combination API from the code as follows:
```js
var files = [{"textfile":"path/document.txt"}]
var params = {}
params.file = files
params.language = "eng"
client.post_combination('sentimentanalysistoindex', params, false, function(err, resp, body) {
if (err) {
console.log(err)
} else {
console.log(resp.body)
}
})
```

Pass a boolean for the async parameter.

To find out more about combinations and how to create one, see [here](https://dev.havenondemand.com/combination/home).

### Posting files
### Batch jobs

File posting is handled using the "file" parameter name which is used for all current file postings in IDOL OnDemand
Haven OnDemand allows you to batch multiple API jobs in a single request using the Job API, for example, to analyze a batch of web pages, documents or social media messages where you need to analyze each text individually but want to be more efficient with your code, or where you want to execute multiple API calls on a single web page, document, or text. **Note: files are currently not supported in this wrapper for batch jobs.**

```js
var jobID
var data = [
{ "name": "analyzesentiment",
"version": "v1",
"params": {
'text': 'I love dogs'
}
},
{ "name": "extractconcepts",
"version": "v1",
"params": {
"url": "http://en.wikipedia.org/wiki/United_Kingdom"
}
}
]
client.batchJob(data, function(err, resp, body) {
jobID = resp.body.jobID
console.log(jobID)
})

//
// check result of async request with Status API after some time
//

client.getJobStatus(jobID, function(err, resp, body) {
console.log(resp.body)
})
```
var data={'file':'test.txt'}
client.call('analyzesentiment',data,callback)
```


## Contributing
We encourage you to contribute to this repo! Please send pull requests with modified and updated code.

1. Fork it ( https://github.com/HPE-Haven-OnDemand/havenondemand-node/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var iod = require('./lib/iodneedle')
var hod = require('./lib/hodneedle')

module.exports=iod
module.exports=hod
Loading