diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java index 5920e8fa..a0fbd4ff 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java @@ -14,6 +14,7 @@ package org.shredzone.acme4j; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -24,7 +25,7 @@ import java.util.List; */ public class Registration { - private List contacts = new ArrayList<>(); + private List contacts = new ArrayList<>(); private URI agreement; private URI location; @@ -57,12 +58,40 @@ public class Registration { } /** - * List of contact email addresses. + * List of contact addresses (emails, phone numbers etc). */ - public List getContacts() { + public List getContacts() { return contacts; } + /** + * Add a contact URI to the list of contacts. + * + * @param contact + * Contact URI + */ + public void addContact(URI contact) { + getContacts().add(contact); + } + + /** + * Add a contact address to the list of contacts. + *

+ * This is a convenience call for {@link #addContact(URI)}. + * + * @param contact + * Contact URI as string + * @throws IllegalArgumentException + * if there is a syntax error in the URI string + */ + public void addContact(String contact) { + try { + addContact(new URI(contact)); + } catch (URISyntaxException ex) { + throw new IllegalArgumentException("Invalid contact URI", ex); + } + } + /** * Location URI of the registration at the server. Returned from the server after * successfully creating or updating a registration. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java index 8102f4f8..4910b8bb 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java @@ -41,12 +41,15 @@ public class RegistrationTest { registration.setAgreement(new URI("http://example.com/agreement.pdf")); registration.setLocation(new URI("http://example.com/acme/12345")); - registration.getContacts().add("mailto:foo@example.com"); - registration.getContacts().add("mailto:bar@example.com"); + registration.getContacts().add(new URI("mailto:foo@example.com")); + registration.addContact(new URI("tel:+1-212-555-0101")); + registration.addContact("mailto:foo2@example.com"); assertThat(registration.getAgreement(), is(new URI("http://example.com/agreement.pdf"))); assertThat(registration.getLocation(), is(new URI("http://example.com/acme/12345"))); - assertThat(registration.getContacts(), contains("mailto:foo@example.com", "mailto:bar@example.com")); + assertThat(registration.getContacts(), contains( + new URI("mailto:foo@example.com"), new URI("tel:+1-212-555-0101"), + new URI("mailto:foo2@example.com"))); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java index ae53f0a3..795b7eba 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java @@ -69,7 +69,7 @@ public class AbstractAcmeClientTest { @Test public void testNewRegistration() throws AcmeException { Registration registration = new Registration(); - registration.getContacts().add("mailto:foo@example.com"); + registration.addContact("mailto:foo@example.com"); Connection connection = new DummyConnection() { @Override @@ -111,7 +111,7 @@ public class AbstractAcmeClientTest { public void testUpdateRegistration() throws AcmeException { Registration registration = new Registration(); registration.setAgreement(agreementUri); - registration.getContacts().add("mailto:foo2@example.com"); + registration.addContact("mailto:foo2@example.com"); registration.setLocation(locationUri); Connection connection = new DummyConnection() { diff --git a/src/site/markdown/usage/register.md b/src/site/markdown/usage/register.md index c734fc10..6c4074c5 100644 --- a/src/site/markdown/usage/register.md +++ b/src/site/markdown/usage/register.md @@ -8,7 +8,7 @@ This code fragment registers your account with the CA. Optionally you can add co ```java Registration reg = new Registration(); -reg.getContacts().add("mailto:acme@example.com"); // optional +reg.addContact("mailto:acme@example.com"); // optional client.newRegistration(account, reg);