Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max/custom parameters #98

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/international_address_autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const client = clientBuilder.buildInternationalAddressAutocompleteClient();
const country = "CAN";

const summaryLookup = new Lookup({search: "123 Anson", country});
// uncomment the following line to add a custom parameter
// summaryLookup.addCustomParameter("max_results", 1);

await handleRequest(summaryLookup, "Response of summary results");

const detailedLookup = new Lookup({addressId: summaryLookup.result[0].addressId, country});
Expand Down
2 changes: 2 additions & 0 deletions examples/international_street.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let client = clientBuilder.buildInternationalStreetClient();
// https://www.smarty.com/docs/cloud/international-street-api#http-input-fields

let lookup1 = new Lookup("CA", "262 Browndale Cr, Richmond Hill, ON");
// uncomment the following line to add a custom parameter
// lookup1.addCustomParameter("input_id", 1234);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these supposed to be commented?


let lookup2 = new Lookup();
lookup2.inputId = "ID-8675309";
Expand Down
4 changes: 3 additions & 1 deletion examples/us_autocomplete_pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ let client = clientBuilder.buildUsAutocompleteProClient();

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

await handleRequest(lookup, "Simple Lookup");

Expand Down Expand Up @@ -60,4 +62,4 @@ async function handleRequest(lookup, lookupType) {
} catch(err) {
console.log(err)
}
}
}
2 changes: 2 additions & 0 deletions examples/us_enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let client = clientBuilder.buildUsEnrichmentClient();
// https://www.smarty.com/docs/us-street-api#input-fields

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

handleResponse(lookup).then();

Expand Down
3 changes: 3 additions & 0 deletions examples/us_extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ lookup.aggressive = true;
lookup.addressesHaveLineBreaks = false;
lookup.addressesPerLine = 1;

// uncomment the following line to add a custom parameter
// lookup.addCustomParameter("addr_line_breaks", false);

await handleRequest(lookup);

function logResult(response) {
Expand Down
4 changes: 3 additions & 1 deletion examples/us_reverse_geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
let client = clientBuilder.buildUsReverseGeoClient();

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

await handleResponse(lookup1);

Expand Down
4 changes: 3 additions & 1 deletion examples/us_street.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ lookup2.maxCandidates = 5;
let lookup3 = new Lookup();
lookup3.inputId = "8675309";
lookup3.street = "1600 Amphitheatre Parkway Mountain View, CA 94043";
lookup3.maxCandidates = 1;

// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("max_candidates", 1);

// NOTE: batches are not supported when using SharedCredentials.
let batch = new SmartyCore.Batch();
Expand Down
3 changes: 3 additions & 0 deletions examples/us_zipcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ let lookup3 = new Lookup();
lookup3.city = "Phoenix";
lookup3.state = "AZ";

// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("input_id", 1234);

let batch = new SmartyCore.Batch();
batch.add(lookup1);
batch.add(lookup2);
Expand Down
4 changes: 4 additions & 0 deletions src/InputData.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class InputData {
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]);
}

addCustomParameter(key, value) {
this.data[key] = value;
}

formatData(field) {
if (Array.isArray(field)) return field.join(";");
else return field;
Expand Down
5 changes: 5 additions & 0 deletions src/international_address_autocomplete/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class Lookup {
this.maxResults = maxResults;
this.includeOnlyLocality = includeOnlyLocality;
this.includeOnlyPostalCode = includeOnlyPostalCode;
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/international_street/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class Lookup {

this.ensureEnoughInfo = this.ensureEnoughInfo.bind(this);
this.ensureValidData = this.ensureValidData.bind(this);
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}

ensureEnoughInfo() {
Expand Down
7 changes: 6 additions & 1 deletion src/us_autocomplete_pro/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class Lookup {
this.preferZIPCodes = [];
this.preferRatio = undefined;
this.preferGeolocation = undefined;
this.source = undefined
this.source = undefined;
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/us_enrichment/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ class Lookup {
this.dataSubset = dataSubset;

this.response = {};
this.customParameters = {};
};

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

module.exports = Lookup;
5 changes: 5 additions & 0 deletions src/us_extract/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Lookup {
this.aggressive = undefined;
this.addressesHaveLineBreaks = undefined;
this.addressesPerLine = undefined;
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/us_reverse_geo/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Lookup {
this.longitude = longitude.toFixed(8);
this.source = source;
this.response = new Response();
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/us_street/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class Lookup {
this.format = format;
this.countySource = countySource;
this.result = [];
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}

}

module.exports = Lookup;
5 changes: 5 additions & 0 deletions src/us_zipcode/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class Lookup {
this.zipCode = zipCode;
this.inputId = inputId;
this.result = [];
this.customParameters = {};
}

addCustomParameter(key, value) {
this.customParameters[key] = value;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/util/buildInputData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ const InputData = require("../InputData");
module.exports = (lookup, keyTranslationFormat) => {
let inputData = new InputData(lookup);

const hasCustomParameters = Object.keys(lookup.customParameters ?? {}).length > 0;

for (let key in keyTranslationFormat) {
inputData.add(key, keyTranslationFormat[key]);
}

if (hasCustomParameters) {
for (let key in lookup.customParameters) {
inputData.addCustomParameter(key, lookup.customParameters[key]);
}
}

return inputData.data;
};
1 change: 1 addition & 0 deletions tests/international_address_autocomplete/test_Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("An International Address Autocomplete lookup", function () {
maxResults: 5,
includeOnlyLocality: undefined,
includeOnlyPostalCode: undefined,
customParameters: {},
};
let lookup = new Lookup();
expect(lookup).to.deep.equal(defaultLookup);
Expand Down
Loading