This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from ibm-developer/testcases-part3
Testcases part3
- Loading branch information
Showing
7 changed files
with
329 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Postgre | ||
|
||
Postgres is a powerful, open source object-relational database that is highly customizable. Build apps quickly and scale easily with hosted and fully managed PostgreSQL, a feature-rich open source SQL database. Compose for PostgreSQL makes Postgres even better by managing it for you. This includes offering an easy, auto-scaling deployment system which delivers high availability and redundancy, automated no-stop backups and much more. | ||
|
||
## Credentials | ||
|
||
### LocalDevConfig | ||
|
||
This is where your local configuration is stored for Postgre. | ||
``` | ||
{ | ||
"postgre_uri": "{{uri}}" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
The `service_manager` returns an instance of a `postgre-client` instance configured to connect to the supplied database. Database management is done using the `pg` client, whose full documentation can [be found here](https://www.npmjs.com/package/pg), | ||
but a small getting started example can be found below: | ||
|
||
```javascript | ||
pair = (100, "abc'def") | ||
|
||
var client = serviceManager.get('postgre-client'); | ||
|
||
client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 integer NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { | ||
if (err) { | ||
console.log('error:', err); | ||
return; | ||
} | ||
|
||
client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { | ||
if (err) { | ||
console.log('error:', err); | ||
return; | ||
} | ||
}); | ||
client.query('SELECT * FROM "sch.test";', function (err, result) { | ||
if (err) { | ||
console.log('error:', err); | ||
} else { | ||
console.log(JSON.stringify(result, null, 2)); | ||
} | ||
|
||
}); | ||
|
||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Redis | ||
|
||
Redis is a powerful, in-memory key/value store which can act as a cache, queue or transient store in your database stack. The Redis platform is designed to solve practical problems in the modern application stack and offers a chance to use counters, queues, lists and hyperloglogs to handle complex data issues simply. Redis is the modern developers’ multi-bladed tool with something to offer in every use case. | ||
|
||
## Credentials | ||
|
||
### LocalDevConfig | ||
|
||
This is where your local configuration is stored for Redis. | ||
``` | ||
{ | ||
"redis_uri": "{{{uri}}}" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
The `service_manager` returns an instance of a `redis` instance configured to connect to the supplied database. Database management is done using the `redis` client, whose full documentation can [be found here](https://www.npmjs.com/package/redis), | ||
but a small getting started example can be found below: | ||
|
||
```javascript | ||
var redis = serviceManager.get('redis'); | ||
|
||
redis.set("test-key", "test-val"); | ||
|
||
redis.get("test-key", function (err, response) { | ||
if (err) { | ||
console.log('error:', err); | ||
} | ||
else { | ||
console.log(JSON.stringify(response, null, 2)); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Watson Conversation | ||
|
||
The IBM Watson™ Conversation service combines machine learning, natural language understanding, and integrated dialog tools to create conversation flows between your apps and your users. | ||
|
||
## Credentials | ||
|
||
### LocalDevConfig | ||
|
||
This is where your local configuration is stored for Watson Conversation. | ||
``` | ||
{ | ||
"watson_conversation_url": "{{{url}}}", | ||
"watson_conversation_username": "{{username}}", | ||
"watson_conversation_password": "{{password}}" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
The `service_manager` returns an instance of a `ConversationV1` client which is preconfigured to use the credentials supplied. You will need to specify the `workspace_id` for the conversation workspace you have created, as each service integration can include multiple workspaces. The full documentation for the `IBM Watson Conversation` service for Node can [be found here](https://www.ibm.com/watson/developercloud/conversation/api/v1/?node), | ||
but a small getting started example can be found below: | ||
|
||
```javascript | ||
var workspace_id = 'the-workspace-id-from-your-generated-service'; | ||
|
||
var serviceManager = require('./services/service-manager'); | ||
|
||
var conversation = serviceManager.get('watson-conversation'); | ||
|
||
conversation.message({ | ||
workspace_id: workspace_id, | ||
input: { 'text': 'Hello!' } | ||
}, function (err, response) { | ||
if (err) | ||
console.log('error:', err); | ||
else | ||
console.log(JSON.stringify(response, null, 2)); | ||
}); | ||
``` | ||
|
||
## Extended Example | ||
|
||
An extended example of basic usages can be found in the [Watson Developer Cloud GitHub Repo](https://github.com/watson-developer-cloud/node-sdk/blob/master/examples/conversation.v1.js). | ||
|
||
Reference the full [ConversationV1 API to leverage its full power](https://www.ibm.com/watson/developercloud/conversation/api/v1/?node). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable */ | ||
app.get('/postgre-test', function (req, res) { | ||
|
||
let messages = []; | ||
var pair = [1, "two"] | ||
|
||
var client = serviceManager.get('postgre-client'); | ||
|
||
if (!client) { | ||
res.status(500).send('postgre-client is not defined in serviceManager'); | ||
return; | ||
} | ||
|
||
client.query('CREATE TABLE IF NOT EXISTS "sch.test" (num integer NOT NULL, data varchar(256) NOT NULL);', function (err, result) { | ||
|
||
if (err) { | ||
res.status(400).send(err); | ||
return; | ||
} | ||
|
||
client.query('INSERT INTO "sch.test" (num, data) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { | ||
if (err) { | ||
res.status(400).send(err); | ||
return; | ||
} | ||
}); | ||
client.query('SELECT * FROM "sch.test";', function (err, result) { | ||
if (err) { | ||
res.status(400).send(err); | ||
} else { | ||
|
||
if (result.rows[0].num == pair[0] && result.rows[0].data == pair[1]) { | ||
messages.push('created and fetched data') | ||
client.query('DROP TABLE IF EXISTS "sch.test";'); | ||
res.status(202).json(messages); | ||
} | ||
else { | ||
res.status(400).send('error processing data'); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable */ | ||
app.get('/redis-test', function (req, res) { | ||
|
||
let messages = []; | ||
let key = "test-key"; | ||
let val = "test-val"; | ||
|
||
var redis = serviceManager.get('redis'); | ||
|
||
if (!redis) { | ||
res.status(500).send('redis is not defined in serviceManager'); | ||
return; | ||
} | ||
|
||
redis.set(key, val); | ||
|
||
messages.push("set data"); | ||
|
||
redis.get(key, function (err, response) { | ||
if (err) { | ||
res.status(400).json(err); | ||
} | ||
else { | ||
if (response == val) { | ||
messages.push("got data"); | ||
res.status(202).json(messages); | ||
} | ||
else { | ||
res.status(400).send('error processing data'); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable */ | ||
app.get('/watson-conversation-test', function (req, res) { | ||
let messages = []; | ||
|
||
/* workspace_id is not a supplied credential from service_manager, | ||
* as each conversation service can have several workspaces. | ||
* thus exposing the credential, while not ideal, in this case is okay | ||
*/ | ||
|
||
var workspace_id = 'df5a2ec4-943d-410e-835f-e85bd63e3a7c'; | ||
var conversation = serviceManager.get('watson-conversation'); | ||
|
||
if (!conversation) { | ||
res.status(500).send('watson-conversation is not defined in serviceManager'); | ||
return; | ||
} | ||
|
||
messages.push("received response for conversation"); | ||
|
||
conversation.message({ | ||
workspace_id: workspace_id, | ||
input: { 'text': 'Hello' } | ||
}, function (err, response) { | ||
if (err) { | ||
res.status(400).json(err); | ||
} | ||
else if (response.output.text) { | ||
res.status(202).json(messages); | ||
} | ||
else { | ||
res.status(400).json('Error processing response') | ||
} | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.