-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
138 lines (128 loc) · 3.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var requestify = require('requestify');
var baseURL = "http://services.postcodeanywhere.co.uk";
var KEY = "";
exports.initialize = function(key) {
KEY = key;
};
exports.CapturePlusInteractiveFind = function(data, next) {
requestify.request(baseURL + "/CapturePlus/Interactive/Find/v2.10/json3.ws", {
method: "POST",
params: {
Key: KEY,
SearchTerm: data.searchTerm,
LastId : data.lastId,
SearchFor : data.searchFor,
Country : data.country,
LanguagePreference : data.languagePreference,
MaxSuggestions : data.maxSuggestions,
MaxResults : data.maxResults
},
dataType: "json"
}
)
.then(function(response) {
var body = JSON.parse(response.body);
// Test for an error
if (body.Items.length == 1 && typeof(body.Items[0].Error) != "undefined") {
// Show the error message
next( {
description: body.Items[0].Description
}, null);
}
else {
// Check if there were any items found
if (body.Items.length == 0)
next(null, []);
else {
next(null, body.Items);
}
}
});
};
exports.CapturePlusInteractiveRetrieve = function(data, next) {
requestify.request(baseURL + "/CapturePlus/Interactive/Retrieve/v2.10/json3.ws", {
method: "POST",
params: {
Key: KEY,
Id: data.id
},
dataType: "json"
}
)
.then(function(response) {
var body = JSON.parse(response.body);
// Test for an error
if (body.Items.length == 1 && typeof(body.Items[0].Error) != "undefined") {
// Show the error message
next( {
description: body.Items[0].Description
}, null);
}
else {
// Check if there were any items found
if (body.Items.length == 0)
next(null, []);
else {
next(null, body.Items);
}
}
});
};
exports.RetrieveByAddress= function(data, next) {
requestify.request(baseURL + "/PostcodeAnywhere/Interactive/RetrieveByAddress/v1.20/json3.ws", {
method: "POST",
params: {
Key: KEY,
Address: data.address,
Company: data.company
},
dataType: "json"
})
.then(function(response) {
var body = JSON.parse(response.body);
// Test for an error
if (body.Items.length == 1 && typeof(body.Items[0].Error) != "undefined") {
// Show the error message
next( {
description: body.Items[0].Description
}, null);
}
else {
// Check if there were any items found
if (body.Items.length == 0)
next(null, []);
else {
next(null, body.Items);
}
}
});
};
exports.BankAccountValidation= function(data, next) {
requestify.request(baseURL + "/BankAccountValidation/Interactive/Validate/v2.00/json3.ws", {
method: "POST",
params: {
Key: KEY,
AccountNumber: data.accountNumber,
SortCode: data.sortCode
},
dataType: "json"
})
.then(function(response) {
var body = JSON.parse(response.body);
// Test for an error
if (body.Items.length == 1 && typeof(body.Items[0].Error) != "undefined") {
// Show the error message
next( {
description: body.Items[0].Description
}, null);
}
else {
// Check if there were any items found
if (body.Items.length == 0)
next(null, []);
else {
next(null, body.Items);
}
}
});
};