Skip to content

Commit 0a21675

Browse files
Merge pull request #98 from smarty/max/custom-parameters
Max/custom parameters
2 parents b79c9a1 + 6c72d49 commit 0a21675

File tree

19 files changed

+77
-4
lines changed

19 files changed

+77
-4
lines changed

examples/international_address_autocomplete.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const client = clientBuilder.buildInternationalAddressAutocompleteClient();
2424
const country = "CAN";
2525

2626
const summaryLookup = new Lookup({search: "123 Anson", country});
27+
// uncomment the following line to add a custom parameter
28+
// summaryLookup.addCustomParameter("max_results", 1);
29+
2730
await handleRequest(summaryLookup, "Response of summary results");
2831

2932
const detailedLookup = new Lookup({addressId: summaryLookup.result[0].addressId, country});

examples/international_street.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ let client = clientBuilder.buildInternationalStreetClient();
2323
// https://www.smarty.com/docs/cloud/international-street-api#http-input-fields
2424

2525
let lookup1 = new Lookup("CA", "262 Browndale Cr, Richmond Hill, ON");
26+
// uncomment the following line to add a custom parameter
27+
// lookup1.addCustomParameter("input_id", 1234);
2628

2729
let lookup2 = new Lookup();
2830
lookup2.inputId = "ID-8675309";

examples/us_autocomplete_pro.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let client = clientBuilder.buildUsAutocompleteProClient();
2424

2525
// *** Simple Lookup ***
2626
let lookup = new Lookup("4770 Lincoln");
27+
// uncomment the following line to add a custom parameter
28+
// lookup.addCustomParameter("max_results", 3);
2729

2830
await handleRequest(lookup, "Simple Lookup");
2931

@@ -60,4 +62,4 @@ async function handleRequest(lookup, lookupType) {
6062
} catch(err) {
6163
console.log(err)
6264
}
63-
}
65+
}

examples/us_enrichment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ let client = clientBuilder.buildUsEnrichmentClient();
2323
// https://www.smarty.com/docs/us-street-api#input-fields
2424

2525
let lookup = new Lookup("334968275");
26+
// uncomment the following line to add a custom parameter
27+
// lookup.addCustomParameter("include", "group_financial");
2628

2729
handleResponse(lookup).then();
2830

examples/us_extract.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ lookup.aggressive = true;
2424
lookup.addressesHaveLineBreaks = false;
2525
lookup.addressesPerLine = 1;
2626

27+
// uncomment the following line to add a custom parameter
28+
// lookup.addCustomParameter("addr_line_breaks", false);
29+
2730
await handleRequest(lookup);
2831

2932
function logResult(response) {

examples/us_reverse_geo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-
1818
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
1919
let client = clientBuilder.buildUsReverseGeoClient();
2020

21-
let lookup1 = new Lookup(40.27644, -111.65747, "all");
21+
let lookup1 = new Lookup(40.27644, -111.65747);
22+
// uncomment the following line to add a custom parameter
23+
// lookup1.addCustomParameter("source", "all");
2224

2325
await handleResponse(lookup1);
2426

examples/us_street.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ lookup2.maxCandidates = 5;
4545
let lookup3 = new Lookup();
4646
lookup3.inputId = "8675309";
4747
lookup3.street = "1600 Amphitheatre Parkway Mountain View, CA 94043";
48-
lookup3.maxCandidates = 1;
48+
49+
// uncomment the following line to add a custom parameter
50+
// lookup3.addCustomParameter("max_candidates", 1);
4951

5052
// NOTE: batches are not supported when using SharedCredentials.
5153
let batch = new SmartyCore.Batch();

examples/us_zipcode.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ let lookup3 = new Lookup();
3333
lookup3.city = "Phoenix";
3434
lookup3.state = "AZ";
3535

36+
// uncomment the following line to add a custom parameter
37+
// lookup3.addCustomParameter("input_id", 1234);
38+
3639
let batch = new SmartyCore.Batch();
3740
batch.add(lookup1);
3841
batch.add(lookup2);

src/InputData.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class InputData {
88
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]);
99
}
1010

11+
addCustomParameter(key, value) {
12+
this.data[key] = value;
13+
}
14+
1115
formatData(field) {
1216
if (Array.isArray(field)) return field.join(";");
1317
else return field;

src/international_address_autocomplete/Lookup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class Lookup {
88
this.maxResults = maxResults;
99
this.includeOnlyLocality = includeOnlyLocality;
1010
this.includeOnlyPostalCode = includeOnlyPostalCode;
11+
this.customParameters = {};
12+
}
13+
14+
addCustomParameter(key, value) {
15+
this.customParameters[key] = value;
1116
}
1217
}
1318

0 commit comments

Comments
 (0)