Skip to content

Commit 8b647b8

Browse files
committed
Some rename of classes and more javadoc
1 parent f3ba3d1 commit 8b647b8

17 files changed

Lines changed: 97 additions & 85 deletions

lib/src/main/java/com/auth0/Auth0.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
package com.auth0;
2626

2727
import com.auth0.authentication.AuthenticationAPIClient;
28-
import com.auth0.util.BaseMetrics;
29-
import com.auth0.util.Metrics;
28+
import com.auth0.util.BaseTelemetry;
29+
import com.auth0.util.Telemetry;
3030
import com.squareup.okhttp.HttpUrl;
3131

3232
/**
@@ -53,7 +53,7 @@ public class Auth0 {
5353
private final String clientId;
5454
private final String domainUrl;
5555
private final String configurationUrl;
56-
private Metrics metrics;
56+
private Telemetry telemetry;
5757

5858
/**
5959
* Creates a new object using clientId & domain
@@ -76,8 +76,8 @@ public Auth0(String clientId, String domain, String configurationDomain) {
7676
this.clientId = clientId;
7777
this.domainUrl = ensureUrlString(domain);
7878
this.configurationUrl = resolveConfiguration(configurationDomain, this.domainUrl);
79-
this.metrics = new BaseMetrics();
80-
this.metrics.usingLibrary(Auth0.NAME, Auth0.VERSION);
79+
this.telemetry = new BaseTelemetry();
80+
this.telemetry.usingLibrary(Auth0.NAME, Auth0.VERSION);
8181
}
8282

8383
/**
@@ -119,22 +119,17 @@ public String getAuthorizeUrl() {
119119
}
120120

121121
/**
122-
* @return Auth0 metrics sent in every requests
122+
* @return Auth0 telemetry info sent in every request
123123
*/
124-
public Metrics getMetrics() {
125-
return metrics;
124+
public Telemetry getTelemetry() {
125+
return telemetry;
126126
}
127127

128128
/**
129-
* Define what metrics are sent to Auth0 on every request.
130-
* @param metrics to send or nil to send nothing
129+
* Avoid sending telemetry in every request to Auth0
131130
*/
132-
public void setMetrics(Metrics metrics) {
133-
if (metrics == null) {
134-
this.metrics = new BaseMetrics();
135-
} else {
136-
this.metrics = metrics;
137-
}
131+
public void doNotSendTelemetry() {
132+
this.telemetry = null;
138133
}
139134

140135
private String resolveConfiguration(String configurationDomain, String domainUrl) {

lib/src/main/java/com/auth0/authentication/AuthenticationAPIClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
import com.auth0.authentication.result.DatabaseUser;
3030
import com.auth0.authentication.result.Delegation;
3131
import com.auth0.authentication.result.UserProfile;
32-
import com.auth0.internal.RequestFactory;
32+
import com.auth0.request.internal.RequestFactory;
3333
import com.auth0.request.AuthenticationRequest;
3434
import com.auth0.request.ParameterizableRequest;
3535
import com.auth0.request.Request;
36-
import com.auth0.util.Metrics;
36+
import com.auth0.util.Telemetry;
3737
import com.fasterxml.jackson.databind.ObjectMapper;
3838
import com.squareup.okhttp.HttpUrl;
3939
import com.squareup.okhttp.OkHttpClient;
@@ -103,9 +103,9 @@ private AuthenticationAPIClient(Auth0 auth0, OkHttpClient client, ObjectMapper m
103103
this.client = client;
104104
this.mapper = mapper;
105105
this.factory = new RequestFactory();
106-
final Metrics metrics = auth0.getMetrics();
107-
if (metrics != null) {
108-
factory.setClientInfo(metrics.getValue());
106+
final Telemetry telemetry = auth0.getTelemetry();
107+
if (telemetry != null) {
108+
factory.setClientInfo(telemetry.getValue());
109109
}
110110
}
111111

lib/src/main/java/com/auth0/authentication/ParameterBuilder.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@
3131
import java.util.Map;
3232

3333
/**
34-
* Builder class for Auth API parameters.
34+
* Builder for Auth0 Authentication API parameters
35+
*
36+
* You can build your parameters like this
37+
* <pre><code>
38+
* Map<String, Object> parameters = ParameterBuilder.newBuilder()
39+
* .setClientId("{CLIENT_ID}")
40+
* .setConnection("{CONNECTION}")
41+
* .set("{PARAMETER_NAME}", "{PARAMETER_VALUE}")
42+
* .asDictionary();
43+
* </code></pre>
44+
*
45+
* @see ParameterBuilder#newBuilder()
46+
* @see ParameterBuilder#newAuthenticationBuilder()
3547
*/
3648
public class ParameterBuilder {
3749

3850
public static final String GRANT_TYPE_PASSWORD = "password";
3951
public static final String GRANT_TYPE_JWT = "urn:ietf:params:oauth:grant-type:jwt-bearer";
52+
4053
public static final String SCOPE_OPENID = "openid";
4154
public static final String SCOPE_OFFLINE_ACCESS = "openid offline_access";
55+
4256
public static final String ID_TOKEN_KEY = "id_token";
4357
public static final String SCOPE_KEY = "scope";
4458
public static final String REFRESH_TOKEN_KEY = "refresh_token";
@@ -51,11 +65,6 @@ public class ParameterBuilder {
5165

5266
private Map<String, Object> parameters;
5367

54-
/**
55-
* Creates a new builder with default parameters
56-
*
57-
* @param parameters default parameters
58-
*/
5968
private ParameterBuilder(Map<String, Object> parameters) {
6069
CheckHelper.checkArgument(parameters != null, "Must provide non-null parameters");
6170
this.parameters = new HashMap<>(parameters);
@@ -128,17 +137,7 @@ public ParameterBuilder setAccessToken(String accessToken) {
128137
* @return itself
129138
*/
130139
public ParameterBuilder setSend(PasswordlessType passwordlessType) {
131-
switch (passwordlessType) {
132-
default:
133-
case CODE:
134-
return set(SEND_KEY, "code");
135-
case LINK:
136-
return set(SEND_KEY, "link");
137-
case LINK_ANDROID:
138-
return set(SEND_KEY, "link_android");
139-
case LINK_IOS:
140-
return set(SEND_KEY, "link_ios");
141-
}
140+
return set(SEND_KEY, passwordlessType.getValue());
142141
}
143142

144143
/**
@@ -179,14 +178,14 @@ public ParameterBuilder clearAll() {
179178
/**
180179
* Create a {@link Map} with all the parameters
181180
*
182-
* @return an unmodifiable map with the parameters
181+
* @return all parameters added previously as a {@link Map}
183182
*/
184183
public Map<String, Object> asDictionary() {
185184
return Collections.unmodifiableMap(new HashMap<>(this.parameters));
186185
}
187186

188187
/**
189-
* Creates a new instance of the builder with default values
188+
* Creates a new instance of the builder using default values for login request, e.g. 'openid' for scope.
190189
*
191190
* @return a new builder
192191
*/
@@ -196,7 +195,8 @@ public static ParameterBuilder newAuthenticationBuilder() {
196195
}
197196

198197
/**
199-
* Creates a new instance of the builder without any default values
198+
* Creates a new instance of the builder.
199+
* This builder wont have any default values
200200
*
201201
* @return a new builder
202202
*/
@@ -205,9 +205,9 @@ public static ParameterBuilder newBuilder() {
205205
}
206206

207207
/**
208-
* Creates a new instance of the builder with parameters.
208+
* Creates a new instance of the builder from some initial parameters.
209209
*
210-
* @param parameters default parameters
210+
* @param parameters initial parameters
211211
* @return a new builder
212212
*/
213213
public static ParameterBuilder newBuilder(Map<String, Object> parameters) {

lib/src/main/java/com/auth0/authentication/PasswordlessType.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,28 @@
2525
package com.auth0.authentication;
2626

2727
/**
28-
* An enum with all passwordless login types available in Auth0
28+
* Valid types of passwordless flows in Auth0
2929
*/
3030
public enum PasswordlessType {
31-
LINK,
31+
/**
32+
* Sends a link used to login
33+
*/
34+
LINK_WEB,
3235
LINK_ANDROID,
3336
LINK_IOS,
34-
CODE
37+
CODE;
38+
39+
public String getValue() {
40+
switch (this) {
41+
default:
42+
case CODE:
43+
return "code";
44+
case LINK_WEB:
45+
return "link";
46+
case LINK_ANDROID:
47+
return "link_android";
48+
case LINK_IOS:
49+
return "link_ios";
50+
}
51+
}
3552
}

lib/src/main/java/com/auth0/authentication/SignUpRequest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
import com.auth0.authentication.result.DatabaseUser;
3030
import com.auth0.callback.BaseCallback;
3131
import com.auth0.request.AuthenticationRequest;
32-
import com.auth0.request.ParameterizableRequest;
3332
import com.auth0.request.Request;
3433

3534
import java.util.Map;
3635

3736
/**
38-
* Represent a request to create a user + log in
37+
* Represent a request that creates a user in a Auth0 Database connection and then logs in.
3938
*/
4039
public class SignUpRequest implements Request<Credentials> {
4140

@@ -48,8 +47,8 @@ public class SignUpRequest implements Request<Credentials> {
4847
}
4948

5049
/**
51-
* Add additional parameters for create user request
52-
* @param parameters as a non-null dictionary
50+
* Add additional parameters sent when creating a using.
51+
* @param parameters sent with the request and must be non-null
5352
* @return itself
5453
*/
5554
public SignUpRequest addSignUpParameters(Map<String, Object> parameters) {
@@ -58,17 +57,18 @@ public SignUpRequest addSignUpParameters(Map<String, Object> parameters) {
5857
}
5958

6059
/**
61-
* Add additional parameters for login request
62-
* @param parameters as a non-null dictionary
60+
* Add additional parameters sent when logging the user in
61+
* @param parameters sent with the request and must be non-null
6362
* @return itself
63+
* @see ParameterBuilder
6464
*/
6565
public SignUpRequest addAuthenticationParameters(Map<String, Object> parameters) {
6666
authenticationRequest.addAuthenticationParameters(parameters);
6767
return this;
6868
}
6969

7070
/**
71-
* Set the scope used to authenticate the user
71+
* Set the scope used to login the user
7272
* @param scope value
7373
* @return itself
7474
*/
@@ -97,8 +97,7 @@ public void start(final BaseCallback<Credentials> callback) {
9797
signUpRequest.start(new BaseCallback<DatabaseUser>() {
9898
@Override
9999
public void onSuccess(final DatabaseUser user) {
100-
authenticationRequest
101-
.start(callback);
100+
authenticationRequest.start(callback);
102101
}
103102

104103
@Override

lib/src/main/java/com/auth0/internal/BaseAuthenticationRequest.java renamed to lib/src/main/java/com/auth0/request/internal/BaseAuthenticationRequest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.internal;
1+
package com.auth0.request.internal;
22

33
import com.auth0.authentication.result.Credentials;
44
import com.auth0.request.AuthenticationRequest;
@@ -14,19 +14,12 @@
1414
import static com.auth0.authentication.ParameterBuilder.GRANT_TYPE_KEY;
1515
import static com.auth0.authentication.ParameterBuilder.SCOPE_KEY;
1616

17-
/**
18-
* Created by hernan on 3/16/16.
19-
*/
20-
public class BaseAuthenticationRequest extends SimpleRequest<Credentials> implements AuthenticationRequest {
17+
class BaseAuthenticationRequest extends SimpleRequest<Credentials> implements AuthenticationRequest {
2118

2219
public BaseAuthenticationRequest(HttpUrl url, OkHttpClient client, ObjectMapper mapper, String httpMethod, Class clazz) {
2320
super(url, client, mapper, httpMethod, clazz);
2421
}
2522

26-
public BaseAuthenticationRequest(HttpUrl url, OkHttpClient client, ObjectMapper mapper, String httpMethod) {
27-
super(url, client, mapper, httpMethod);
28-
}
29-
3023
/**
3124
* Sets the 'grant_type' parameter
3225
*

lib/src/main/java/com/auth0/internal/BaseRequest.java renamed to lib/src/main/java/com/auth0/request/internal/BaseRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.auth0.internal;
25+
package com.auth0.request.internal;
2626

2727
import com.auth0.APIException;
2828
import com.auth0.Auth0Exception;

lib/src/main/java/com/auth0/internal/JsonRequestBodyBuilder.java renamed to lib/src/main/java/com/auth0/request/internal/JsonRequestBodyBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.auth0.internal;
25+
package com.auth0.request.internal;
2626

2727
import com.auth0.RequestBodyBuildException;
2828
import com.fasterxml.jackson.core.JsonProcessingException;

lib/src/main/java/com/auth0/internal/RequestFactory.java renamed to lib/src/main/java/com/auth0/request/internal/RequestFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.auth0.internal;
25+
package com.auth0.request.internal;
2626

2727
import com.auth0.authentication.result.Credentials;
2828
import com.auth0.request.AuthenticationRequest;
2929
import com.auth0.request.AuthorizableRequest;
3030
import com.auth0.request.ParameterizableRequest;
31-
import com.auth0.util.Metrics;
31+
import com.auth0.util.Telemetry;
3232
import com.fasterxml.jackson.databind.ObjectMapper;
3333
import com.squareup.okhttp.HttpUrl;
3434
import com.squareup.okhttp.OkHttpClient;
@@ -105,7 +105,7 @@ public <T> ParameterizableRequest<T> DELETE(HttpUrl url, OkHttpClient client, Ob
105105

106106
private <T> void addMetrics(ParameterizableRequest<T> request) {
107107
if (this.clientInfo != null) {
108-
request.addHeader(Metrics.HEADER_NAME, this.clientInfo);
108+
request.addHeader(Telemetry.HEADER_NAME, this.clientInfo);
109109
}
110110
if (this.userAgent!= null) {
111111
request.addHeader("User-Agent", this.userAgent);

lib/src/main/java/com/auth0/internal/SimpleRequest.java renamed to lib/src/main/java/com/auth0/request/internal/SimpleRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.auth0.internal;
25+
package com.auth0.request.internal;
2626

2727
import com.auth0.Auth0Exception;
2828
import com.auth0.APIException;

0 commit comments

Comments
 (0)