Skip to content

Commit

Permalink
Adding domain property in configuration for connecting from clients
Browse files Browse the repository at this point in the history
Domain property can be used to change the messaging URL. By default it uses the production Watson IoT server - internetofthings.ibmcloud.com.
  • Loading branch information
jeffdare committed Jun 30, 2016
1 parent 30e59e5 commit 9f5791a
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.settings
node_modules
coverage
.idea
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.settings
node_modules
coverage
.idea
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ configuration json containing the following :
- auth-method - Method of authentication (the only value currently
supported is “token”)
- auth-token - API key token (required if auth-method is “token”)
- domain - (Optional)The messaging endpoint URL. By default the value is "internetofthings.ibmcloud.com"(Watson IoT Production server).

If you want to use quickstart, then send only the first three
properties.
If you want to use quickstart, then enter only the first three properties.

``` {.sourceCode .javascript}
var Client = require("ibmiotf");
var config = {
"org" : "organization",
"id" : "deviceId",
"domain": "internetofthings.ibmcloud.com",
"type" : "deviceType",
"auth-method" : "token",
"auth-token" : "authToken"
Expand Down Expand Up @@ -263,6 +264,7 @@ configuration json containing the following :
- auth-key - API key
- auth-token - API key token
- type - use 'shared' to enable shared subscription
- domain - (Optional)The messaging endpoint URL. By default the value is "internetofthings.ibmcloud.com"(Watson IoT Production server).

If you want to use quickstart, then send only the first two properties.

Expand All @@ -271,6 +273,7 @@ var Client = require("ibmiotf");
var appClientConfig = {
"org" : orgId,
"id" : appId,
"domain": "internetofthings.ibmcloud.com",
"auth-key" : apiKey,
"auth-token" : apiToken
}
Expand Down Expand Up @@ -677,6 +680,7 @@ configuration json containing the following :
- id - The ID of your gateway
- auth-method - Method of authentication (the only value currently supported is “token”)
- auth-token - API key token (required if auth-method is “token”)
- domain - (Optional)The messaging endpoint URL. By default the value is "internetofthings.ibmcloud.com"(Watson IoT Production server).


``` {.sourceCode .javascript}
Expand All @@ -685,6 +689,7 @@ var config = {
"org" : "organization",
"type" : "gatewayType",
"id" : "gatewayId",
"domain": "internetofthings.ibmcloud.com",
"auth-method" : "token",
"auth-token" : "authToken"
};
Expand Down
14 changes: 2 additions & 12 deletions dist/clients/ApplicationClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,7 @@

return new _Promise['default'](function (resolve, reject) {
// const API_HOST = "https://%s.internetofthings.ibmcloud.com/api/v0002";
var uri = "";
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002", _this2.org);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002", _this2.org, _this2.domainName);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002", _this2.org, _this2.domainName);

if (Array.isArray(paths)) {
for (var i = 0, l = paths.length; i < l; i++) {
Expand Down Expand Up @@ -690,12 +685,7 @@
this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _Promise['default'](function (resolve, reject) {

var uri = "";
if (_this3.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, deviceType, deviceId, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, _this3.domainName, deviceType, deviceId, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, _this3.domainName, deviceType, deviceId, eventType);

var xhrConfig = {
url: uri,
Expand Down
15 changes: 6 additions & 9 deletions dist/clients/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
_get(Object.getPrototypeOf(BaseClient.prototype), 'constructor', this).call(this);
this.log = _log['default'];
this.log.setDefaultLevel("warn");
this.staging = false;
if (process.env.STAGING === '1') {
this.staging = true;
}
//removed as now we have support of domain name in config.
/* this.staging = false;
if(process.env.STAGING === '1') {
this.staging = true;
}*/
if (!config) {
throw new Error('Client instantiated with missing properties');
}
Expand Down Expand Up @@ -94,11 +95,7 @@
throw new Error('auth-token must be a string');
}

if (this.staging) {
this.host = "wss://" + config.org + ".messaging.staging.internetofthings.ibmcloud.com:8883";
} else {
this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";
}
this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";

this.isQuickstart = false;
this.mqttConfig = {
Expand Down
8 changes: 2 additions & 6 deletions dist/clients/DeviceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@

this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _Promise['default'](function (resolve, reject) {
var uri = "";
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.typeId, _this2.deviceId, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.typeId, _this2.deviceId, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.typeId, _this2.deviceId, eventType);

var xhrConfig = {
url: uri,
method: 'POST',
Expand Down
8 changes: 2 additions & 6 deletions dist/clients/GatewayClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,8 @@

this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _Promise['default'](function (resolve, reject) {
var uri = undefined;
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.type, _this2.id, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.type, _this2.id, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.type, _this2.id, eventType);

var xhrConfig = {
url: uri,
method: 'POST',
Expand Down
51 changes: 15 additions & 36 deletions dist/iotf-client-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20985,12 +20985,7 @@ var ApplicationClient = (function (_BaseClient) {

return new _bluebird2['default'](function (resolve, reject) {
// const API_HOST = "https://%s.internetofthings.ibmcloud.com/api/v0002";
var uri = "";
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002", _this2.org);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002", _this2.org, _this2.domainName);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002", _this2.org, _this2.domainName);

if (Array.isArray(paths)) {
for (var i = 0, l = paths.length; i < l; i++) {
Expand Down Expand Up @@ -21341,12 +21336,7 @@ var ApplicationClient = (function (_BaseClient) {
this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _bluebird2['default'](function (resolve, reject) {

var uri = "";
if (_this3.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, deviceType, deviceId, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, _this3.domainName, deviceType, deviceId, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this3.org, _this3.domainName, deviceType, deviceId, eventType);

var xhrConfig = {
url: uri,
Expand Down Expand Up @@ -21430,7 +21420,7 @@ exports['default'] = ApplicationClient;
module.exports = exports['default'];

},{"../util/util.js":116,"./BaseClient.js":110,"axios":1,"bluebird":16,"btoa":50,"format":51}],110:[function(require,module,exports){
(function (process,__dirname){
(function (__dirname){
/**
*****************************************************************************
Copyright (c) 2014, 2015 IBM Corporation and other Contributors.
Expand Down Expand Up @@ -21485,10 +21475,11 @@ var BaseClient = (function (_events$EventEmitter) {
_get(Object.getPrototypeOf(BaseClient.prototype), 'constructor', this).call(this);
this.log = _loglevel2['default'];
this.log.setDefaultLevel("warn");
this.staging = false;
if (process.env.STAGING === '1') {
this.staging = true;
}
//removed as now we have support of domain name in config.
/* this.staging = false;
if(process.env.STAGING === '1') {
this.staging = true;
}*/
if (!config) {
throw new Error('Client instantiated with missing properties');
}
Expand Down Expand Up @@ -21526,11 +21517,7 @@ var BaseClient = (function (_events$EventEmitter) {
throw new Error('auth-token must be a string');
}

if (this.staging) {
this.host = "wss://" + config.org + ".messaging.staging.internetofthings.ibmcloud.com:8883";
} else {
this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";
}
this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";

this.isQuickstart = false;
this.mqttConfig = {
Expand Down Expand Up @@ -21620,8 +21607,8 @@ var BaseClient = (function (_events$EventEmitter) {
exports['default'] = BaseClient;
module.exports = exports['default'];

}).call(this,require('_process'),"/src/clients")
},{"../util/util.js":116,"_process":25,"events":22,"loglevel":52,"mqtt":54}],111:[function(require,module,exports){
}).call(this,"/src/clients")
},{"../util/util.js":116,"events":22,"loglevel":52,"mqtt":54}],111:[function(require,module,exports){
/**
*****************************************************************************
Copyright (c) 2014, 2015 IBM Corporation and other Contributors.
Expand Down Expand Up @@ -21784,12 +21771,8 @@ var DeviceClient = (function (_BaseClient) {

this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _bluebird2['default'](function (resolve, reject) {
var uri = "";
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.typeId, _this2.deviceId, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.typeId, _this2.deviceId, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.typeId, _this2.deviceId, eventType);

var xhrConfig = {
url: uri,
method: 'POST',
Expand Down Expand Up @@ -22007,12 +21990,8 @@ var GatewayClient = (function (_BaseClient) {

this.log.debug("Publishing event of Type: " + eventType + " with payload : " + payload);
return new _bluebird2['default'](function (resolve, reject) {
var uri = undefined;
if (_this2.staging) {
uri = (0, _format2['default'])("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.type, _this2.id, eventType);
} else {
uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.type, _this2.id, eventType);
}
var uri = (0, _format2['default'])("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", _this2.org, _this2.domainName, _this2.type, _this2.id, eventType);

var xhrConfig = {
url: uri,
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions dist/iotf-client-bundle.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions samples/ApplicationSample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var iotf = require("../");
var appClientConfig = {
org: 'xxxxx',
id: 'myapp',
"domain": "internetofthings.ibmcloud.com",
"auth-key": 'a-xxxxxxx-zenkqyfiea',
"auth-token": 'xxxxxxxxxx'
};
Expand Down
15 changes: 3 additions & 12 deletions src/clients/ApplicationClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,7 @@ export default class ApplicationClient extends BaseClient {
callApi(method, expectedHttpCode, expectJsonContent, paths, body, params){
return new Promise((resolve, reject) => {
// const API_HOST = "https://%s.internetofthings.ibmcloud.com/api/v0002";
let uri = "";
if(this.staging) {
uri = format("https://%s.staging.internetofthings.ibmcloud.com/api/v0002", this.org);
} else {
uri = format("https://%s.%s/api/v0002", this.org, this.domainName);
}
let uri = format("https://%s.%s/api/v0002", this.org, this.domainName);

if(Array.isArray(paths)){
for(var i = 0, l = paths.length; i < l; i++){
Expand Down Expand Up @@ -628,12 +623,8 @@ export default class ApplicationClient extends BaseClient {
this.log.debug("Publishing event of Type: "+ eventType + " with payload : "+payload);
return new Promise((resolve, reject) => {

let uri = "";
if(this.staging) {
uri = format("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", this.org, deviceType, deviceId, eventType);
} else {
uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, deviceType, deviceId, eventType);
}
let uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, deviceType, deviceId, eventType);


let xhrConfig = {
url: uri,
Expand Down
12 changes: 5 additions & 7 deletions src/clients/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export default class BaseClient extends events.EventEmitter {
super();
this.log = log;
this.log.setDefaultLevel("warn");
this.staging = false;
//removed as now we have support of domain name in config.
/* this.staging = false;
if(process.env.STAGING === '1') {
this.staging = true;
}
}*/
if(!config){
throw new Error('Client instantiated with missing properties');
}
Expand Down Expand Up @@ -66,12 +67,9 @@ export default class BaseClient extends events.EventEmitter {
else if(!isString(config['auth-token'])){
throw new Error('auth-token must be a string');
}

this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";

if(this.staging){
this.host = "wss://" + config.org + ".messaging.staging.internetofthings.ibmcloud.com:8883";
} else {
this.host = "wss://" + config.org + ".messaging." + this.domainName + ":8883";
}

this.isQuickstart = false;
this.mqttConfig = {
Expand Down
8 changes: 2 additions & 6 deletions src/clients/DeviceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,8 @@ export default class DeviceClient extends BaseClient {
publishHTTPS(eventType, eventFormat, payload){
this.log.debug("Publishing event of Type: "+ eventType + " with payload : "+payload);
return new Promise((resolve, reject) => {
let uri = "";
if(this.staging) {
uri = format("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.typeId, this.deviceId, eventType);
} else {
uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, this.typeId, this.deviceId, eventType);
}
let uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, this.typeId, this.deviceId, eventType);

let xhrConfig = {
url: uri,
method: 'POST',
Expand Down
8 changes: 2 additions & 6 deletions src/clients/GatewayClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ export default class GatewayClient extends BaseClient {
publishHTTPS(eventType, eventFormat, payload){
this.log.debug("Publishing event of Type: "+ eventType + " with payload : "+payload);
return new Promise((resolve, reject) => {
let uri;
if(this.staging) {
uri = format("https://%s.staging.internetofthings.ibmcloud.com/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.type, this.id, eventType);
} else {
uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, this.type, this.id, eventType);
}
let uri = format("https://%s.%s/api/v0002/device/types/%s/devices/%s/events/%s", this.org, this.domainName, this.type, this.id, eventType);

let xhrConfig = {
url: uri,
method: 'POST',
Expand Down

0 comments on commit 9f5791a

Please sign in to comment.