Skip to content

Commit de66978

Browse files
committed
Javadoc'd everything public. Fixed bug where Token was not publicly visible
1 parent 35bbd05 commit de66978

8 files changed

Lines changed: 206 additions & 76 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
package io.github.robertograham.nadir;
22

3+
/**
4+
* The {@code Account} class represents an EA account
5+
*
6+
* @since 1.0.0
7+
*/
38
public interface Account {
49

10+
/**
11+
* @return The UID (user ID) of this {@code Account}
12+
* @since 1.0.0
13+
*/
514
long userId();
615

16+
/**
17+
* @return The EAID (EA username) of this {@code Account}
18+
* @since 1.0.0
19+
*/
720
String username();
821
}

src/main/java/io/github/robertograham/nadir/AccountResource.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@
44
import java.util.List;
55
import java.util.Optional;
66

7+
/**
8+
* An object from which actions related to EA accounts can be performed
9+
*
10+
* @since 1.0.0
11+
*/
712
public interface AccountResource {
813

14+
/**
15+
* @return An {@link Optional} of {@link Account} that's non-empty if the HTTP response contained an account
16+
* @throws StryderErrorException If there's an HTTP error response
17+
* @throws IOException If an {@link java.io.InputStream} cannot be created from the HTTP response
18+
* @since 1.0.0
19+
*/
920
Optional<Account> findOneBySessionToken() throws IOException;
1021

11-
Optional<List<Account>> findAllBySearchTerms(final String... names) throws IOException;
22+
/**
23+
* @param searchTerms The terms that will be used to search for EA accounts
24+
* @return An {@link Optional} of {@link List} of {@link Account} that's non-empty if the HTTP response contained any accounts
25+
* @throws StryderErrorException If there's an HTTP error response
26+
* @throws IOException If an {@link java.io.InputStream} cannot be created from the HTTP response
27+
* @since 1.0.0
28+
*/
29+
Optional<List<Account>> findAllBySearchTerms(final String... searchTerms) throws IOException;
1230
}

src/main/java/io/github/robertograham/nadir/AuthenticationResource.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.net.URISyntaxException;
1616
import java.nio.charset.StandardCharsets;
1717
import java.util.*;
18+
import java.util.function.Function;
1819
import java.util.regex.Pattern;
1920

2021
final class AuthenticationResource {
@@ -113,8 +114,9 @@ private Optional<Token> fetchToken() throws IOException {
113114
.addParameter("prompt", "none")
114115
.addParameter("release_type", "prod")
115116
.build(),
116-
optionalResultResponseHandlerProvider.forClass(Token.class)
117-
);
117+
optionalResultResponseHandlerProvider.forClass(TokenImpl.class)
118+
)
119+
.map(Function.identity());
118120
}
119121

120122
Optional<Token> userCredentialsGrantedToken(final String emailAddress,

src/main/java/io/github/robertograham/nadir/JsonOptionalResultResponseHandlerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
enum JsonOptionalResultResponseHandlerProvider implements OptionalResultResponseHandlerProvider {
1818

1919
INSTANCE(
20-
Token.Adapter.INSTANCE,
20+
TokenImpl.Adapter.INSTANCE,
2121
AccountImpl.Adapter.INSTANCE,
2222
XSearchResult.Adapter.INSTANCE
2323
);

src/main/java/io/github/robertograham/nadir/Nadir.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,86 @@
22

33
import java.io.IOException;
44

5+
/**
6+
* Entry-point for the {@code nadir} library
7+
* <p>
8+
* Can be instantiated via {@link Nadir#newNadir(String, String)}
9+
* which will use the default {@link Nadir.Builder} options
10+
* <p>
11+
* Can be created via {@link Nadir#newBuilder(String, String)} which returns an instance of {@link Nadir.Builder}
12+
* that lets you customise the object returned by {@link Builder#build()}
13+
*
14+
* @since 1.0.0
15+
*/
516
public interface Nadir extends AutoCloseable {
617

18+
/**
19+
* @param emailAddress EA account email address
20+
* @param password EA account password
21+
* @return An instance of {@link Nadir.Builder} that can be used to build an instance of {@code Nadir}
22+
* @throws NullPointerException If {@code emailAddress is null}
23+
* @throws NullPointerException If {@code password is null}
24+
* @since 1.0.0
25+
*/
726
static Builder newBuilder(final String emailAddress,
827
final String password) {
928
return new NadirBuilderImpl(emailAddress, password);
1029
}
1130

31+
/**
32+
* @param emailAddress EA account email address
33+
* @param password EA account password
34+
* @return An authenticated instance of {@code Nadir} configured with the default {@link Nadir.Builder} options
35+
* @see Nadir#newBuilder(String, String)
36+
* @see Builder#build()
37+
* @since 1.0.0
38+
*/
1239
static Nadir newNadir(final String emailAddress,
1340
final String password) throws IOException {
1441
return Nadir.newBuilder(emailAddress, password)
1542
.build();
1643
}
1744

45+
/**
46+
* @return The EA account email address this instance was configured to use
47+
* @since 1.0.0
48+
*/
1849
String emailAddress();
1950

51+
/**
52+
* @return The EA account password this instance was configured to use
53+
* @since 1.0.0
54+
*/
2055
String password();
2156

57+
/**
58+
* @return A non-expired instance of {@link Token} with at least 5 minutes of use left
59+
* @since 1.0.0
60+
*/
2261
Token session();
2362

63+
/**
64+
* @return an instance of {@link AccountResource} from which EA account related actions can be performed
65+
* @since 1.0.0
66+
*/
2467
AccountResource accounts();
2568

2669
@Override
2770
void close();
2871

72+
/**
73+
* Used to build instances of {@link Nadir}
74+
*
75+
* @since 1.0.0
76+
*/
2977
interface Builder {
3078

79+
/**
80+
* @return An authenticated instance of {@link Nadir}
81+
* @throws StryderErrorException If any erroneous HTTP responses are encountered during authentication
82+
* @throws IOException If any number of problems occur during authentication
83+
* @since 1.0.0
84+
*/
3185
Nadir build() throws IOException;
3286
}
3387
}

src/main/java/io/github/robertograham/nadir/StryderErrorException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import javax.json.JsonObject;
88
import java.util.Optional;
99

10+
/**
11+
* An exception thrown due to erroneous HTTP responses
12+
*
13+
* @since 1.0.0
14+
*/
1015
public final class StryderErrorException extends HttpResponseException {
1116

1217
private final JsonObject jsonObject;
@@ -21,6 +26,11 @@ public final class StryderErrorException extends HttpResponseException {
2126
jsonObject = null;
2227
}
2328

29+
/**
30+
* @return an {@link Optional} of {@link JsonObject} that's non-empty if a JSON object
31+
* was included in the erroneous HTTP response
32+
* @since 1.0.0
33+
*/
2434
public Optional<JsonObject> jsonObject() {
2535
return Optional.ofNullable(jsonObject);
2636
}
Lines changed: 25 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,30 @@
11
package io.github.robertograham.nadir;
22

3-
import javax.json.JsonObject;
4-
import javax.json.bind.adapter.JsonbAdapter;
53
import java.time.LocalDateTime;
6-
import java.util.Objects;
74

8-
final class Token {
9-
10-
private final String accessToken;
11-
private final String tokenType;
12-
private final LocalDateTime accessTokenExpiresAt;
13-
14-
private Token(String accessToken, String tokenType, LocalDateTime accessTokenExpiresAt) {
15-
this.accessToken = accessToken;
16-
this.tokenType = tokenType;
17-
this.accessTokenExpiresAt = accessTokenExpiresAt;
18-
}
19-
20-
public String accessToken() {
21-
return accessToken;
22-
}
23-
24-
public String tokenType() {
25-
return tokenType;
26-
}
27-
28-
public LocalDateTime accessTokenExpiresAt() {
29-
return accessTokenExpiresAt;
30-
}
31-
32-
@Override
33-
public String toString() {
34-
return "Token{" +
35-
"accessToken='" + accessToken + '\'' +
36-
", tokenType='" + tokenType + '\'' +
37-
", accessTokenExpiresAt=" + accessTokenExpiresAt +
38-
'}';
39-
}
40-
41-
@Override
42-
public boolean equals(final Object object) {
43-
if (this == object)
44-
return true;
45-
if (!(object instanceof Token))
46-
return false;
47-
final var token = (Token) object;
48-
return accessToken.equals(token.accessToken) &&
49-
tokenType.equals(token.tokenType) &&
50-
accessTokenExpiresAt.equals(token.accessTokenExpiresAt);
51-
}
52-
53-
@Override
54-
public int hashCode() {
55-
return Objects.hash(accessToken, tokenType, accessTokenExpiresAt);
56-
}
57-
58-
enum Adapter implements JsonbAdapter<Token, JsonObject> {
59-
60-
INSTANCE;
61-
62-
@Override
63-
public JsonObject adaptToJson(final Token token) {
64-
throw new UnsupportedOperationException();
65-
}
66-
67-
@Override
68-
public Token adaptFromJson(final JsonObject jsonObject) {
69-
return new Token(
70-
jsonObject.getString("access_token"),
71-
jsonObject.getString("token_type"),
72-
LocalDateTime.now()
73-
.plusSeconds(Long.parseLong(jsonObject.getString("expires_in")))
74-
);
75-
}
76-
}
5+
/**
6+
* Representation of a user's authentication session
7+
*
8+
* @since 1.0.0
9+
*/
10+
public interface Token {
11+
12+
/**
13+
* @return An access token that can be used to authenticate against API endpoints
14+
* @since 1.0.0
15+
*/
16+
String accessToken();
17+
18+
/**
19+
* @return The type of token this, I have only seen {@code Bearer} so far
20+
* @since 1.0.0
21+
*/
22+
String tokenType();
23+
24+
/**
25+
* @return The time when this session will be invalid. A valid {@code Token} can be obtained using
26+
* {@link Nadir#session()}
27+
* @since 1.0.0
28+
*/
29+
LocalDateTime accessTokenExpiresAt();
7730
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.github.robertograham.nadir;
2+
3+
import javax.json.JsonObject;
4+
import javax.json.bind.adapter.JsonbAdapter;
5+
import java.time.LocalDateTime;
6+
import java.util.Objects;
7+
8+
final class TokenImpl implements Token {
9+
10+
private final String accessToken;
11+
private final String tokenType;
12+
private final LocalDateTime accessTokenExpiresAt;
13+
14+
private TokenImpl(String accessToken, String tokenType, LocalDateTime accessTokenExpiresAt) {
15+
this.accessToken = accessToken;
16+
this.tokenType = tokenType;
17+
this.accessTokenExpiresAt = accessTokenExpiresAt;
18+
}
19+
20+
@Override
21+
public String accessToken() {
22+
return accessToken;
23+
}
24+
25+
@Override
26+
public String tokenType() {
27+
return tokenType;
28+
}
29+
30+
@Override
31+
public LocalDateTime accessTokenExpiresAt() {
32+
return accessTokenExpiresAt;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
return "Token{" +
38+
"accessToken='" + accessToken + '\'' +
39+
", tokenType='" + tokenType + '\'' +
40+
", accessTokenExpiresAt=" + accessTokenExpiresAt +
41+
'}';
42+
}
43+
44+
@Override
45+
public boolean equals(final Object object) {
46+
if (this == object)
47+
return true;
48+
if (!(object instanceof TokenImpl))
49+
return false;
50+
final var token = (TokenImpl) object;
51+
return accessToken.equals(token.accessToken) &&
52+
tokenType.equals(token.tokenType) &&
53+
accessTokenExpiresAt.equals(token.accessTokenExpiresAt);
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return Objects.hash(accessToken, tokenType, accessTokenExpiresAt);
59+
}
60+
61+
enum Adapter implements JsonbAdapter<TokenImpl, JsonObject> {
62+
63+
INSTANCE;
64+
65+
@Override
66+
public JsonObject adaptToJson(final TokenImpl token) {
67+
throw new UnsupportedOperationException();
68+
}
69+
70+
@Override
71+
public TokenImpl adaptFromJson(final JsonObject jsonObject) {
72+
return new TokenImpl(
73+
jsonObject.getString("access_token"),
74+
jsonObject.getString("token_type"),
75+
LocalDateTime.now()
76+
.plusSeconds(Long.parseLong(jsonObject.getString("expires_in")))
77+
);
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)