Last active
August 29, 2015 14:08
-
-
Save paulparton/d8d943a14b96dbc0aeed to your computer and use it in GitHub Desktop.
Report It App v3 address web service connectivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addressService = angular.module('reportIt.addressService', ['reportIt.config']); | |
/** | |
* Connect to the Sutherland shire council property & rating address service to build and validate street addresses | |
**/ | |
addressService.factory('AddressService',['$http', '$q', 'config', | |
function($http, $q, config){ | |
//Web service credentials | |
var credentials = config.encodedWebserviceCredentials, | |
baseServiceUrl = config.webServices.addressServiceUrl, | |
webServiceConnect, | |
baseTransformer; | |
webServiceConnect = function(urlPostfix, transformer){ | |
var deferred = $q.defer(); | |
$http.get(baseServiceUrl + '/' + urlPostfix, | |
{ | |
headers: {'Authorization': 'Basic ' + credentials}, | |
transformResponse: transformer | |
} | |
). | |
success(function(data, status, headers, config) { | |
deferred.resolve(data); | |
}). | |
error(function(data, status, headers, config) { | |
deferred.reject({'error': data}); | |
}); | |
return deferred.promise; | |
}; | |
//Convert XML response to JSON | |
var baseTransformer = function(data) { | |
// convert the data to JSON and provide | |
// it to the success function below | |
var x2js = new X2JS(), | |
json = x2js.xml_str2json( data ); | |
return json.ArrayOfString.string; | |
}; | |
return { | |
getStreets: function(){ | |
var urlPostfix = 'getStreets'; | |
return webServiceConnect(urlPostfix, baseTransformer); | |
}, | |
getSuburbsForStreet: function(street){ | |
var urlPostfix = 'getSuburbsForStreet?street='+street; | |
return webServiceConnect(urlPostfix, baseTransformer); | |
}, | |
getHouseNumbers: function(suburb, street){ | |
var urlPostfix = 'getHouseNumber?suburb=' + suburb + '&street=' + street; | |
return webServiceConnect(urlPostfix, baseTransformer); | |
}, | |
validateAddress: function(suburb, street, houseNumber){ | |
var urlPostfix = 'validateAddress?suburb=' + suburb + '&street=' + street + '&houseNumber=' + houseNumber; | |
return webServiceConnect(urlPostfix, baseTransformer); | |
} | |
} | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment