pushwoosh-client
Advanced tools
Comparing version 1.3.1 to 1.4.0
49
index.js
@@ -171,2 +171,51 @@ var request = require('request'), | ||
PushwooshClient.prototype.setTags = function(options, callback) { | ||
var client = this; | ||
if (typeof options.hwid !== 'string') { | ||
return callback(new Error('Device hwid must be provided (string)')); | ||
} | ||
if (typeof options.tags !== 'object') { | ||
return callback(new Error('Tags must be provided (object)')); | ||
} | ||
var body = { | ||
request: { | ||
application: client.appCode, | ||
hwid: options.hwid, | ||
tags: options.tags | ||
} | ||
}; | ||
client.sendRequest('setTags', body, function(error, response, body){ | ||
if (error) { | ||
return callback(error); | ||
} | ||
client.parseResponse(response, body, callback); | ||
}); | ||
}; | ||
PushwooshClient.prototype.getTags = function(options, callback) { | ||
var client = this; | ||
if (typeof options.hwid !== 'string') { | ||
return callback(new Error('Device hwid must be provided (string)')); | ||
} | ||
var body = { | ||
request: { | ||
application: client.appCode, | ||
hwid: options.hwid | ||
} | ||
}; | ||
client.sendRequest('getTags', body, function(error, response, body){ | ||
if (error) { | ||
return callback(error); | ||
} | ||
client.parseResponse(response, body, callback); | ||
}); | ||
}; | ||
PushwooshClient.prototype.sendRequest = function (method, data, callback) { | ||
@@ -173,0 +222,0 @@ request({ |
{ | ||
"name": "pushwoosh-client", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A node js client to consume the Pushwoosh API to send push notifications to mobile devices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -135,2 +135,38 @@ # pushwoosh-node-client | ||
#### Set tags for device | ||
To set tags for a device in Pushwoosh: | ||
```javascript | ||
var Pushwoosh = require('pushwoosh-client'); | ||
var client= new Pushwoosh('AppCode', 'AuthToken'); | ||
var setTagsOptions = { | ||
hwid: 'hwid', | ||
tags: { | ||
price: "1.99", | ||
language: "pl" | ||
} | ||
}; | ||
// this will set the device tags for the client's 'AppCode' application | ||
client.setTags(setTagsOptions , function(error, response) { | ||
... | ||
}); | ||
``` | ||
#### Get tags for device | ||
To get tags for a device from Pushwoosh: | ||
```javascript | ||
var Pushwoosh = require('pushwoosh-client'); | ||
var client= new Pushwoosh('AppCode', 'AuthToken'); | ||
var getTagsOptions = { | ||
hwid: 'hwid' | ||
}; | ||
// this will get the device tags for the client's 'AppCode' application | ||
client.getTags(getTagsOptions , function(error, response) { | ||
... | ||
}); | ||
``` | ||
### Tests | ||
@@ -137,0 +173,0 @@ |
@@ -1362,1 +1362,413 @@ var test = require('tape'), | ||
}); | ||
test('Pushwoosh get tags success case', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 200, | ||
response: { | ||
result: { | ||
language: "fr" | ||
} | ||
} | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}, | ||
expectedResponse = { | ||
result: { | ||
language: "fr" | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.getTags(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, expectedResponse, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh get tags error case with no hwid', function (t) { | ||
t.plan(2); | ||
var mockOptions = {}; | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.getTags(mockOptions, function (err, response) { | ||
t.deepEqual(err, new Error('Device hwid must be provided'), 'Error as expected'); | ||
t.notOk(response, 'No response as expected'); | ||
}); | ||
}); | ||
test('Pushwoosh get tags success case with response code 200 but status code 210', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 210, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}, | ||
expectedResult = {description: 'Argument error', detail: mockBodyResponse.status_message, code: 210}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.getTags(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, expectedResult, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh get tags error case with response code 400', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 400 | ||
}, | ||
mockBodyResponse = { | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.getTags(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Malformed(), 'Got Malformed Error!'); | ||
}); | ||
}); | ||
test('Pushwoosh get tags error case with response code 500', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 500 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 500, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.getTags(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Internal(), 'Got Internal Error!'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags success case with many tags', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 200, | ||
response: {} | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, {}, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags error case with no hwid', function (t) { | ||
t.plan(2); | ||
var mockOptions = {}; | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.deepEqual(err, new Error('Device hwid must be provided'), 'Error as expected'); | ||
t.notOk(response, 'No response as expected'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags error case with no tags', function (t) { | ||
t.plan(2); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}; | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.deepEqual(err, new Error('Tags must be provided'), 'Error as expected'); | ||
t.notOk(response, 'No response as expected'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags success case with response code 200 but status code 210', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 210, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
} | ||
}, | ||
expectedResult = {description: 'Argument error', detail: mockBodyResponse.status_message, code: 210}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, expectedResult, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags error case with response code 400', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
}, | ||
mockResponse = { | ||
statusCode: 400 | ||
}, | ||
mockBodyResponse = { | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Malformed(), 'Got Malformed Error!'); | ||
}); | ||
}); | ||
test('Pushwoosh set tags error case with response code 500', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
}, | ||
mockResponse = { | ||
statusCode: 500 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 500, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid, | ||
tags: { | ||
stringTag: "string value", | ||
integerTag: 42, | ||
listTag: ["string1","string2"], | ||
dateTag: "2015-10-02 22:11", | ||
booleanTag: true | ||
} | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.setTags(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Internal(), 'Got Internal Error!'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70405
1721
176