Skip to content

Commit f007e98

Browse files
author
Daniel Tolbert
authored
Merge pull request #8 from Bandwidth/DX_1004-fix_list_subscriptions
Fixed Subscription List functionality
2 parents 80e39c9 + 2d8cc48 commit f007e98

File tree

6 files changed

+72
-26
lines changed

6 files changed

+72
-26
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ This SDK stable for node versions 7 and above
1515
| > 7 | | Supported |
1616

1717
## Release Notes
18-
| Version | Notes |
19-
|:--------|:---------------------------------------------------------------------|
20-
| 1.1.0 | Added import tn functionality, added promise based `Async` functions |
21-
| 1.2.0 | Added CSR lookup functionality |
18+
| Version | Notes |
19+
|:--------|:------------------------------------------------------------------------------------------------------------------------------------------|
20+
| 1.1.0 | Added import tn functionality, added promise based `Async` functions |
21+
| 1.2.0 | Added CSR lookup functionality |
22+
| 1.2.1 | Fixed Subscription List functionality. Example code at: [examples/subscription_list_and_delete](examples/subscription_list_and_delete.js) |
2223

2324

2425
## Install
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const numbers = require("@bandwidth/numbers");
2+
3+
//Using client directly
4+
const client = new numbers.Client(process.env.BANDWIDTH_ACCOUNT_ID,
5+
process.env.BANDWIDTH_API_USER,
6+
process.env.BANDWIDTH_API_PASSWORD);
7+
8+
9+
const findAndDeleteSubscriptionById = async (id) => {
10+
try {
11+
const subscriptions = await numbers.Subscription.listAsync(client, {});
12+
for (const s of subscriptions) {
13+
console.log(s.id);
14+
// 6be53e36-...-668ee3603d71
15+
// b57094d3-...-25085d224b48
16+
if (s.id === id) {
17+
const deletedS = await s.deleteAsync();
18+
console.log(deletedS);
19+
// {}
20+
}
21+
}
22+
const moreSubscriptions = await numbers.Subscription.listAsync(client, {});
23+
console.log(moreSubscriptions)
24+
// [
25+
// Subscription {
26+
// subscriptionId: '6be53e36-...-668ee3603d71',
27+
// orderType: 'portins',
28+
// emailSubscription: { email: '...@bandwidth.com', digestRequested: 'NONE' },
29+
// client: Client {
30+
// prepareRequest: [Function],
31+
// concatAccountPath: [Function],
32+
// prepareUrl: [Function],
33+
// xml2jsParserOptions: [Object]
34+
// },
35+
// id: '6be53e36-...-668ee3603d71'
36+
// }
37+
// ]
38+
}
39+
catch (e) {
40+
console.log('Error');
41+
console.log(e);
42+
}
43+
}
44+
45+
findAndDeleteSubscriptionById('b57094d3-...-25085d224b48');

lib/importTnOrder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var fs = require("fs");
22
var Client = require("./client");
3-
var IMPORT_TN_ORDER_PATH = "importTnOrders";
3+
var IMPORT_TN_ORDER_PATH = "importtnorders";
44
var LOAS_PATH = "loas";
55
var st = require("stream");
66
var streamifier = require("streamifier");

lib/subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Subscription.list = function(client, query, callback){
3636
if(err){
3737
return callback(err);
3838
}
39-
var items = res.subscriptions || [];
39+
var items = res.subscriptions.subscription || [];
4040
if(!Array.isArray(items)){
4141
items = [items];
4242
}
4343
var result = items.map(function(item){
44-
var i = item.subscription;
44+
var i = item;
4545
i.client = client;
4646
i.__proto__ = Subscription.prototype;
4747
i.id = i.subscriptionId;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bandwidth/numbers",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "NodeJs Client library for Bandwidth Numbers API",
55
"main": "index.js",
66
"scripts": {

test/importTnOrder.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("ImportTnOrders", function(){
3636
};
3737
var numbers = ["9198675309", "8288675309"];
3838
data.telephoneNumbers = [numbers.map(number => {return {telephoneNumber: number}})];
39-
helper.nock().post("/accounts/FakeAccountId/importTnOrders", helper.buildXml({importTnOrder: data})).reply(200, helper.xml.importTnOrder);
39+
helper.nock().post("/accounts/FakeAccountId/importtnorders", helper.buildXml({importTnOrder: data})).reply(200, helper.xml.importTnOrder);
4040
ImportTnOrder.create(helper.createClient(), data, numbers, function(err, item){
4141
if(err){
4242
return done(err);
@@ -65,7 +65,7 @@ describe("ImportTnOrders", function(){
6565
};
6666
var numbers = ["9198675309", "8288675309"];
6767
data.telephoneNumbers = [numbers.map(number => {return {telephoneNumber: number}})];
68-
helper.nock().post("/accounts/FakeAccountId/importTnOrders", helper.buildXml({importTnOrder: data})).reply(200, helper.xml.importTnOrder);
68+
helper.nock().post("/accounts/FakeAccountId/importtnorders", helper.buildXml({importTnOrder: data})).reply(200, helper.xml.importTnOrder);
6969
ImportTnOrder.create(helper.createClient(), data, numbers, function(err, item){
7070
if(err){
7171
return done(err);
@@ -93,7 +93,7 @@ describe("ImportTnOrders", function(){
9393
}
9494
};
9595
var numbers = ["9198675309", "8288675309"];
96-
helper.nock().post("/accounts/FakeAccountId/importTnOrders").reply(400, "");
96+
helper.nock().post("/accounts/FakeAccountId/importtnorders").reply(400, "");
9797
ImportTnOrder.create(helper.createClient(), data, numbers, function(err, item){
9898
if(err){
9999
return done();
@@ -104,7 +104,7 @@ describe("ImportTnOrders", function(){
104104
});
105105
describe("#getImportTnOrder", function(){
106106
it("should return a importTnOrder", function(done){
107-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/021a94f5-5c55-401f-9cdc-8dca059ad7c1").reply(200, helper.xml.importTnOrderResponse, {"Content-Type": "application/xml"});
107+
helper.nock().get("/accounts/FakeAccountId/importtnorders/021a94f5-5c55-401f-9cdc-8dca059ad7c1").reply(200, helper.xml.importTnOrderResponse, {"Content-Type": "application/xml"});
108108
ImportTnOrder.get("021a94f5-5c55-401f-9cdc-8dca059ad7c1", (err, item) => {
109109
if(err){
110110
return done(err);
@@ -117,7 +117,7 @@ describe("ImportTnOrders", function(){
117117
});
118118
describe("#getImportTnOrders", function(){
119119
it("should return a list of ImportTnOrderSummary(s)", function(done){
120-
helper.nock().get("/accounts/FakeAccountId/importTnOrders").reply(200, helper.xml.importTnOrderList, {"Content-Type": "application/xml"});
120+
helper.nock().get("/accounts/FakeAccountId/importtnorders").reply(200, helper.xml.importTnOrderList, {"Content-Type": "application/xml"});
121121
ImportTnOrder.list({}, (err, items) => {
122122
if(err){
123123
return done(err);
@@ -130,7 +130,7 @@ describe("ImportTnOrders", function(){
130130
});
131131
describe("#getHistory", function(){
132132
it("should return histoy", function(done){
133-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/history").reply(200, helper.xml.importTnOrderHistory, {"Content-Type": "application/xml"});
133+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/history").reply(200, helper.xml.importTnOrderHistory, {"Content-Type": "application/xml"});
134134
var order = new ImportTnOrder();
135135
order.id = 1;
136136
order.client = helper.createClient();
@@ -145,7 +145,7 @@ describe("ImportTnOrders", function(){
145145
});
146146
describe("#getFiles", function(){
147147
it("should return list of files", function(done){
148-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/loas?metadata=true").reply(200, helper.xml.files, {"Content-Type": "application/xml"});
148+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/loas?metadata=true").reply(200, helper.xml.files, {"Content-Type": "application/xml"});
149149
var order = new ImportTnOrder();
150150
order.id = 1;
151151
order.client = helper.createClient();
@@ -160,7 +160,7 @@ describe("ImportTnOrders", function(){
160160
});
161161
});
162162
it("should return list of files (without metadata)", function(done){
163-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/loas?metadata=false").reply(200, helper.xml.files, {"Content-Type": "application/xml"});
163+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/loas?metadata=false").reply(200, helper.xml.files, {"Content-Type": "application/xml"});
164164
var order = new ImportTnOrder();
165165
order.id = 1;
166166
order.client = helper.createClient();
@@ -174,7 +174,7 @@ describe("ImportTnOrders", function(){
174174
});
175175
});
176176
it("should fail for error status code", function(done){
177-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/loas?metadata=false").reply(400);
177+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/loas?metadata=false").reply(400);
178178
var order = new ImportTnOrder();
179179
order.id = 1;
180180
order.client = helper.createClient();
@@ -187,7 +187,7 @@ describe("ImportTnOrders", function(){
187187
});
188188
describe("#getFileMetadata", function(){
189189
it("should return file's metadata", function(done){
190-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/loas/file.txt/metadata").reply(200, helper.xml.fileMetadata, {"Content-Type": "application/xml"});
190+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/loas/file.txt/metadata").reply(200, helper.xml.fileMetadata, {"Content-Type": "application/xml"});
191191
var order = new ImportTnOrder();
192192
order.id = 1;
193193
order.client = helper.createClient();
@@ -203,7 +203,7 @@ describe("ImportTnOrders", function(){
203203
describe("#updateFileMetadata", function(){
204204
it("should update file's metadata", function(done){
205205
var metadata = { documentName: "doc", documentType: "type"};
206-
helper.nock().put("/accounts/FakeAccountId/importTnOrders/1/loas/file.txt/metadata", helper.buildXml({ fileMetaData: metadata})).reply(200);
206+
helper.nock().put("/accounts/FakeAccountId/importtnorders/1/loas/file.txt/metadata", helper.buildXml({ fileMetaData: metadata})).reply(200);
207207
var order = new ImportTnOrder();
208208
order.id = 1;
209209
order.client = helper.createClient();
@@ -213,7 +213,7 @@ describe("ImportTnOrders", function(){
213213
describe("#getFile", function(){
214214
var tmpFile = path.join(os.tmpdir(), "dest.txt");
215215
beforeEach(function(){
216-
helper.nock().get("/accounts/FakeAccountId/importTnOrders/1/loas/file.txt").reply(200, "12345", {"Content-Type": "text/plain"});
216+
helper.nock().get("/accounts/FakeAccountId/importtnorders/1/loas/file.txt").reply(200, "12345", {"Content-Type": "text/plain"});
217217
});
218218
afterEach(function(done){
219219
nock.cleanAll();
@@ -268,7 +268,7 @@ describe("ImportTnOrders", function(){
268268
describe("#createFile", function(){
269269
var order, tmpFile = path.join(os.tmpdir(), "dest.txt");
270270
beforeEach(function(done){
271-
helper.nock().post("/accounts/FakeAccountId/importTnOrders/1/loas", "12345", {"Content-Type": "text/plain"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
271+
helper.nock().post("/accounts/FakeAccountId/importtnorders/1/loas", "12345", {"Content-Type": "text/plain"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
272272
order = new ImportTnOrder();
273273
order.id = 1;
274274
order.client = helper.createClient();
@@ -307,7 +307,7 @@ describe("ImportTnOrders", function(){
307307
});
308308
it("should fail on error status code", function(done){
309309
nock.cleanAll();
310-
helper.nock().post("/accounts/FakeAccountId/importTnOrders/1/loas", "11111", {"Content-Type": "text/plain"}).reply(400);
310+
helper.nock().post("/accounts/FakeAccountId/importtnorders/1/loas", "11111", {"Content-Type": "text/plain"}).reply(400);
311311
order.createFile(new Buffer.from("11111", "utf8"), "text/plain", function(err, fileName){
312312
if(err){
313313
return done();
@@ -317,7 +317,7 @@ describe("ImportTnOrders", function(){
317317
});
318318
it("should upload file to the server (default media type)", function(done){
319319
nock.cleanAll();
320-
helper.nock().post("/accounts/FakeAccountId/importTnOrders/1/loas", "12345", {"Content-Type": "application/octet-stream"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
320+
helper.nock().post("/accounts/FakeAccountId/importtnorders/1/loas", "12345", {"Content-Type": "application/octet-stream"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
321321
order.createFile(new Buffer.from("12345", "utf8"), function(err, fileName){
322322
if(err){
323323
return done(err);
@@ -330,7 +330,7 @@ describe("ImportTnOrders", function(){
330330
describe("#updateFile", function(){
331331
var order, tmpFile = path.join(os.tmpdir(), "dest.txt");
332332
beforeEach(function(done){
333-
helper.nock().put("/accounts/FakeAccountId/importTnOrders/1/loas/test.txt", "12345", {"Content-Type": "text/plain"}).reply(200);
333+
helper.nock().put("/accounts/FakeAccountId/importtnorders/1/loas/test.txt", "12345", {"Content-Type": "text/plain"}).reply(200);
334334
order = new ImportTnOrder();
335335
order.id = 1;
336336
order.client = helper.createClient();
@@ -351,7 +351,7 @@ describe("ImportTnOrders", function(){
351351
});
352352
it("should fail on error status code", function(done){
353353
nock.cleanAll();
354-
helper.nock().put("/accounts/FakeAccountId/importTnOrders/1/loas/test.txt", "11111", {"Content-Type": "text/plain"}).reply(400);
354+
helper.nock().put("/accounts/FakeAccountId/importtnorders/1/loas/test.txt", "11111", {"Content-Type": "text/plain"}).reply(400);
355355
order.updateFile("test.txt", new Buffer.from("11111", "utf8"), "text/plain", function(err){
356356
if(err){
357357
return done();
@@ -361,7 +361,7 @@ describe("ImportTnOrders", function(){
361361
});
362362
it("should upload file to the server (default media type)", function(done){
363363
nock.cleanAll();
364-
helper.nock().put("/accounts/FakeAccountId/importTnOrders/1/loas/test.txt", "12345", {"Content-Type": "application/octet-stream"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
364+
helper.nock().put("/accounts/FakeAccountId/importtnorders/1/loas/test.txt", "12345", {"Content-Type": "application/octet-stream"}).reply(200, helper.xml.fileCreated, {"Content-Type": "application/xml"});
365365
order.updateFile("test.txt", new Buffer.from("12345", "utf8"), done);
366366
});
367367
});

0 commit comments

Comments
 (0)