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

Add instructions for using this lib to validate address in general JAVA project #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,49 @@ input widget ready for use, but only the UI parts are tied to Android.
Non-UI code and tests can be run in Java SE, and the rest of the library could
easily be adapted to run in any Java environment.

### Address validation in general JAVA project.

If you are developing a pure JAVA project, this lib can still be very useful when you want to validate addresses. In this case, the only part we need is the common module. Please following steps below to get started.

* 1. Follow the **readme.md** inside common module to build the common project. After build succeed, you would find common.jar within folder: common/build/libs
* 2. Import this common.jar into your project. Now, you should be able to start to code.
* 3. For valiating address, the key class we need is **StandardAddressVerifier.java**
```java
// Build address data need to be verified.
final AddressData addressData =
AddressData.builder().
setCountry("US").
setAdminArea("CA").
setPostalCode("94088").
setLocality(Sunnyvale).
setAddress("Dream Ave").
build();
// address problems, which will be filled by standardAddressVerifier if some data is invalid.
AddressProblems addressProblems = new AddressProblems();

// Verify the address.
standardAddressVerifier.verify(addressData, addressProblems);

// Now, you can see the address problems reside inside addressProblems.
addressProblems.getProblems();
```
Of course, StandardAddressVerifier needs some effort to be configured.
```java
StandardAddressVerifier standardAddressVerifier = new StandardAddressVerifier(
new FieldVerifier(
new ClientData(
new CacheData(
// By default, this lib uses SimpleClientCacheManager
// You can implement your customized cache manager to cache the metadata.
new RedisClientCacheManager(redissonClient, cacheSize),
// You need to implement AsyncRequestApi to provide internet access capability for this lib.
// If the address meta is not cached in your cache manager, it would go fetch the metadata from the internet: "https://chromium-i18n.appspot.com/ssl-address"
new XXXAsyncRequestApi()
)
)
));
```

## Mailing List

Using and developing libaddressinput is discussed on this mailing list:
Expand Down