Skip to content

Commit feb3f4f

Browse files
committed
Made it easier for the user to configure api version and host/protocol for the connection.
1 parent 3c9f236 commit feb3f4f

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

src/main/java/org/nameapi/client/lib/NameApiModeFactory.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.optimaize.command4j.ext.extensions.exception.exceptiontranslation.CombinedExceptionTranslator;
55
import com.optimaize.command4j.ext.extensions.exception.exceptiontranslation.ExceptionTranslationExtension;
66
import com.optimaize.soapworks.client.Keys;
7+
import com.optimaize.soapworks.client.PortUrlFactory;
78
import com.optimaize.soapworks.client.exensions.exceptiontranslation.DefaultClientExceptionTranslator;
89
import com.optimaize.soapworks.client.exensions.exceptiontranslation.SoapFaultExceptionTranslator;
910
import com.optimaize.soapworks.common.host.Host;
@@ -18,22 +19,35 @@
1819
*/
1920
public class NameApiModeFactory {
2021

21-
private static final Mode minimalMode = Mode.create()
22-
.with(Keys.PORT_URL_FACTORY, new NameApiPortUrlFactory())
23-
.with(ExceptionTranslationExtension.TRANSLATOR, new CombinedExceptionTranslator(new DefaultClientExceptionTranslator(), new SoapFaultExceptionTranslator()))
24-
.with(Keys.HOST, new Host("api.nameapi.org", 80))
25-
;
22+
private static final Host DEFAULT_HOST = new Host("api.nameapi.org", 80);
23+
private static final NameApiPortUrlFactory DEFAULT_PORT_FACTORY = NameApiPortUrlFactory.versionLatestStable();
24+
2625

2726
/**
2827
* You can take this and extend for your setup if you need more.
2928
*
3029
* <p>Example: .with(StdoutLoggingExtension.enabled())</p>
3130
*
32-
* <p>If the minimal default is not exactly what you need, for example because you were given a different
33-
* host name, then create your own from scratch.</p>
31+
* @param context for example {@code new ContextBuilder().apiKey("your-api-key).priority(Priority.REALTIME).build()}
32+
* @param host for example {@code new Host("api.nameapi.org", 80)}
33+
* @param portUrlFactory for example {@code NameApiPortUrlFactory.versionLatestStable()}
34+
*/
35+
@NotNull
36+
public static Mode minimal(@NotNull Context context, @NotNull Host host, @NotNull PortUrlFactory portUrlFactory) {
37+
return Mode.create()
38+
.with(Keys.PORT_URL_FACTORY, portUrlFactory)
39+
.with(ExceptionTranslationExtension.TRANSLATOR, new CombinedExceptionTranslator(new DefaultClientExceptionTranslator(), new SoapFaultExceptionTranslator()))
40+
.with(Keys.HOST, host)
41+
.with(NameApiKeys.CONTEXT, Conversions.convert(context));
42+
}
43+
44+
/**
45+
* Overloaded method that uses
46+
* for host: {@code new Host("api.nameapi.org", 80)}
47+
* for port url: {@code NameApiPortUrlFactory.versionLatestStable()}
3448
*/
3549
@NotNull
36-
public static Mode minimal(Context context) {
37-
return minimalMode.with(NameApiKeys.CONTEXT, Conversions.convert(context));
50+
public static Mode minimal(@NotNull Context context) {
51+
return minimal(context, DEFAULT_HOST, DEFAULT_PORT_FACTORY);
3852
}
3953
}

src/main/java/org/nameapi/client/lib/NameApiPortUrlFactory.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,53 @@
1010
*/
1111
public class NameApiPortUrlFactory extends AbstractPortUrlFactory {
1212

13+
private final String soapPrefix;
14+
15+
/**
16+
* This is updated whenever the "latest stable" server api version changes.
17+
*
18+
* Currently this is version 4.0.
19+
*/
20+
public static NameApiPortUrlFactory versionLatestStable() {
21+
return version4_0();
22+
}
23+
24+
/**
25+
* This is always set to the latest release candidate, that is the version right before it becomes the latest stable.
26+
* Such a version does not always exist. After successful testing, it becomes the live version.
27+
*
28+
* Currently this is version 4.1.
29+
*/
30+
public static NameApiPortUrlFactory versionLatestReleaseCandidate() {
31+
return version4_1();
32+
}
33+
1334
/**
14-
* This is updated whenever the server api version changes.
35+
* This is always set to the current main development version.
36+
* You do not necessarily have access to this.
37+
*
38+
* Currently this is version 4.2.
1539
*/
16-
private static final String soapPrefix = "/soap/v4.0";
40+
public static NameApiPortUrlFactory versionLatestDevelopment() {
41+
return version4_2();
42+
}
43+
44+
public static NameApiPortUrlFactory version4_0() {
45+
return new NameApiPortUrlFactory("4.0");
46+
}
47+
public static NameApiPortUrlFactory version4_1() {
48+
return new NameApiPortUrlFactory("4.1");
49+
}
50+
public static NameApiPortUrlFactory version4_2() {
51+
return new NameApiPortUrlFactory("4.2");
52+
}
53+
54+
/**
55+
* @param version for example "4.0".
56+
*/
57+
private NameApiPortUrlFactory(@NotNull String version) {
58+
this.soapPrefix = "/soap/v"+version;
59+
}
1760

1861
@NotNull @Override
1962
public URL createUrl(@NotNull Host host, @NotNull String servicePath) {

0 commit comments

Comments
 (0)