|
4 | 4 | import com.optimaize.command4j.ext.extensions.exception.exceptiontranslation.CombinedExceptionTranslator; |
5 | 5 | import com.optimaize.command4j.ext.extensions.exception.exceptiontranslation.ExceptionTranslationExtension; |
6 | 6 | import com.optimaize.soapworks.client.Keys; |
| 7 | +import com.optimaize.soapworks.client.PortUrlFactory; |
7 | 8 | import com.optimaize.soapworks.client.exensions.exceptiontranslation.DefaultClientExceptionTranslator; |
8 | 9 | import com.optimaize.soapworks.client.exensions.exceptiontranslation.SoapFaultExceptionTranslator; |
9 | 10 | import com.optimaize.soapworks.common.host.Host; |
|
18 | 19 | */ |
19 | 20 | public class NameApiModeFactory { |
20 | 21 |
|
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 | + |
26 | 25 |
|
27 | 26 | /** |
28 | 27 | * You can take this and extend for your setup if you need more. |
29 | 28 | * |
30 | 29 | * <p>Example: .with(StdoutLoggingExtension.enabled())</p> |
31 | 30 | * |
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()} |
34 | 48 | */ |
35 | 49 | @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); |
38 | 52 | } |
39 | 53 | } |
0 commit comments