11nameapi-client-java
22===================
33
4- Java Client for the NameAPI Web Service at https://www.nameapi.org
4+ Java Client for the NameAPI Web Services at https://www.nameapi.org
55
6- There are functional tests (in test/functional) that demonstrate how to use this library.
6+ There are functional tests that demonstrate how to use this library.
77
8- All you need to send requests is your own api key, get it from nameapi.org.
8+ All you need to send requests is your own api key which you can get from nameapi.org.
99
1010This library requires at least Java 8.
1111
@@ -27,8 +27,13 @@ Or you can download the jar, or check out the source code from this GitHub proje
2727
2828## Setup code
2929
30- At first you need one single include, the one to the nameapi service factory :
30+ At first you need some includes, to the context information :
3131
32+ ``` java
33+ import org.nameapi.ontology5.input.context.Context ;
34+ import org.nameapi.ontology5.input.context.ContextBuilder ;
35+ import org.nameapi.ontology5.input.context.Priority ;
36+ ```
3237
3338You need a Context that explains a bit your working environment, something like:
3439
@@ -41,13 +46,21 @@ Context context = new ContextBuilder()
4146Then you need an executor and a mode:
4247
4348``` java
49+ import com.optimaize.anythingworks.common.host.Host ;
50+ import com.optimaize.anythingworks.common.host.Protocol ;
51+ import com.optimaize.command4j.CommandExecutor ;
52+ import com.optimaize.command4j.Mode ;
53+ import org.nameapi.client.lib.NameApiModeFactory ;
54+ import org.nameapi.client.lib.NameApiPortUrlFactory ;
55+ import org.nameapi.client.lib.NameApiRemoteExecutors ;
56+
4457CommandExecutor executor = NameApiRemoteExecutors . get();
45- Mode mode = NameApiModeFactory . withContext(
58+ Mode mode = NameApiModeFactory . withContext(
4659 " your-api-key" ,
4760 context,
4861 // the default and live server is "api.nameapi.org"
49- new Host (" api.nameapi.org" , Protocol . HTTPS ), NameApiPortUrlFactory . version5_3())
50- );
62+ new Host (" api.nameapi.org" , Protocol . HTTPS ), NameApiPortUrlFactory . version5_3()
63+ );
5164```
5265
5366Now you're ready to execute commands.
@@ -60,12 +73,12 @@ Now you're ready to execute commands.
6073This code sends a simple ping to nameapi to test the connection:
6174
6275``` java
76+ import org.nameapi.client.services.system.ping.PingCommand ;
77+
6378PingCommand command = new PingCommand ();
6479 executor. execute(command, mode, null ). get(); // returns "pong"
6580```
6681
67-
68-
6982## Input / Output
7083
7184All input objects come with builders or nicely documented setters.
@@ -88,12 +101,16 @@ and is very convenient in accepting the data however you have it at hands.
88101Creating a simple person looks something like this:
89102
90103``` java
104+ import org.nameapi.ontology5.input.entities.person.InputPerson ;
105+ import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder ;
106+ import org.nameapi.ontology5.input.entities.person.name.InputPersonName ;
107+ import org.nameapi.ontology5.input.entities.person.name.builder.NameBuilders ;
108+
91109InputPersonName name = NameBuilders . western(). fullname(" John F. Kennedy" ). build();
92110 InputPerson inputPerson = new NaturalInputPersonBuilder (). name(name). build();
93111```
94112
95113
96-
97114## Commands
98115
99116The web service methods are implemented as commands. This brings the advantage that the
@@ -111,6 +128,9 @@ Name parsing is the process of splitting a full name into its components.
111128Using the objects created earlier:
112129
113130``` java
131+ import org.nameapi.client.services.parser.personnameparser.PersonNameParserCommand ;
132+ import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult ;
133+
114134PersonNameParserCommand command = new PersonNameParserCommand ();
115135 PersonNameParserResult result = executor. execute(command, mode, inputPerson). get();
116136```
@@ -123,6 +143,9 @@ Name genderizing is the process of identifying the gender based on a person's na
123143Using the objects created earlier:
124144
125145``` java
146+ import org.nameapi.client.services.genderizer.persongenderizer.PersonGenderizerCommand ;
147+ import org.nameapi.ontology5.services.genderizer.GenderizerResult ;
148+
126149PersonGenderizerCommand command = new PersonGenderizerCommand ();
127150 GenderizerResult result = executor. execute(command, mode, inputPerson). get();
128151```
@@ -135,6 +158,12 @@ The Name Matcher compares names and name pairs to discover whether the people co
135158This service takes 2 people as input:
136159
137160``` java
161+ import org.nameapi.client.services.matcher.personmatcher.PersonMatcherArgument ;
162+ import org.nameapi.client.services.matcher.personmatcher.PersonMatcherCommand ;
163+ import org.nameapi.ontology5.input.entities.person.NaturalInputPerson ;
164+ import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder ;
165+ import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult ;
166+
138167PersonMatcherCommand command = new PersonMatcherCommand ();
139168 NaturalInputPerson person1 = new NaturalInputPersonBuilder (). name( NameBuilders . western(). fullname(" John F. Kennedy" ). build() ). build();
140169 NaturalInputPerson person2 = new NaturalInputPersonBuilder (). name( NameBuilders . western(). fullname(" Jack Kennedy" ). build() ). build();
@@ -148,6 +177,13 @@ PersonMatcherCommand command = new PersonMatcherCommand();
148177The Name Formatter displays personal names in the desired form. This includes the order as well as upper and lower case writing.
149178
150179``` java
180+ import org.nameapi.client.services.formatter.personnameformatter.PersonNameFormatterArgument ;
181+ import org.nameapi.client.services.formatter.personnameformatter.PersonNameFormatterCommand ;
182+ import org.nameapi.ontology5.input.entities.person.NaturalInputPerson ;
183+ import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder ;
184+ import org.nameapi.ontology5.services.formatter.FormatterProperties ;
185+ import org.nameapi.ontology5.services.formatter.FormatterResult ;
186+
151187PersonNameFormatterCommand command = new PersonNameFormatterCommand ();
152188 NaturalInputPerson person = new NaturalInputPersonBuilder (). name( NameBuilders . western(). fullname(" john f. kennedy" ). build() ). build();
153189 FormatterProperties properties = new FormatterProperties (true );
@@ -161,6 +197,9 @@ PersonNameFormatterCommand command = new PersonNameFormatterCommand();
161197The Email Name Parser extracts names out of email addresses.
162198
163199``` java
200+ import org.nameapi.client.services.email.emailnameparser.EmailNameParserCommand ;
201+ import org.nameapi.ontology5.services.email.emailnameparser.EmailNameParserResult ;
202+
164203EmailNameParserCommand command = new EmailNameParserCommand ();
165204 EmailNameParserResult result
= executor
. execute(command, mode,
" [email protected] " )
. get();
166205```
@@ -171,6 +210,9 @@ EmailNameParserCommand command = new EmailNameParserCommand();
171210The DEA-Detector checks email addresses against a list of known "trash domains" such as mailinator.com.
172211
173212``` java
213+ import org.nameapi.client.services.email.disposableemailaddressdetector.DisposableEmailAddressDetectorCommand ;
214+ import org.nameapi.ontology5.services.email.disposableemailaddressdetector.DisposableEmailAddressDetectorResult ;
215+
174216DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand ();
175217 DisposableEmailAddressDetectorResult result
= executor
. execute(command, mode,
" [email protected] " )
. get();
176218```
0 commit comments