1.2.0 • Published 9 years ago
angular-ziptastic v1.2.0
angular-ziptastic
Ziptastic ZIP -> City/State lookups for Angular
Installation
# use npm
$ npm install angular-ziptastic
# or bower
$ bower install angular-ziptastic
Setup
Include 'ziptastic'
in your module's dependencies:
// node module exports the string 'ziptastic' for convenience
angular.module('myApp', [
require('angular-ziptastic')
]);
// otherwise, include the code first then the module name
angular.module('myApp', [
'ziptastic'
]);
API
ziptasticProvider
base(baseUrl)
-> undefined
Sets the default base URL for requests. Defaults to 'https://zip.getziptastic.com/v2'
.
country(country)
-> undefined
Set the default country to use in requests. Defaults to 'US'
.
$http(config)
-> undefined
Set default config
for $http
. Defaults to undefined
. config
is an object that will be passed directly to $http
and can be used to set config options like timeout
and cache
ziptastic
lookup(code|options)
-> promise
Performs a Ziptastic lookup, either with a code
string or an options
object that specifies:
code
(string): The postal codecountry
(string): Overrides the default countrybase
(string): Overrides the default base$http
(object): Overrides the default$http
configuration
Returns a $q
promise for the Ziptastic response.
ziptastic.lookup('10009')
.then(function (data) {
expect(data).to.deep.equal({
city: 'New York City',
country: 'US',
county: 'New York',
state: 'New York',
state_short: 'NY',
postal_code: '10009'
});
})
.catch(function (err) {
console.err('Error in lookup', err);
});