mirror of https://github.com/shred/acme4j
Registration contact is an URI now
parent
3d49f8d094
commit
06a600fec1
|
@ -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<String> contacts = new ArrayList<>();
|
||||
private List<URI> 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<String> getContacts() {
|
||||
public List<URI> 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.
|
||||
* <p>
|
||||
* 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.
|
||||
|
|
|
@ -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")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue