Skip to content

Commit 22f5c38

Browse files
committed
service builder more generic
1 parent 1393131 commit 22f5c38

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.scribejava.core.builder;
22

3+
import com.github.scribejava.core.builder.api.BaseApi;
34
import com.github.scribejava.core.builder.api.DefaultApi10a;
45
import com.github.scribejava.core.builder.api.DefaultApi20;
56
import com.github.scribejava.core.model.OAuthConfig;
@@ -8,6 +9,7 @@
89
import com.github.scribejava.core.model.SignatureType;
910
import com.github.scribejava.core.oauth.OAuth10aService;
1011
import com.github.scribejava.core.oauth.OAuth20Service;
12+
import com.github.scribejava.core.oauth.OAuthService;
1113
import com.github.scribejava.core.utils.Preconditions;
1214

1315
abstract class AbstractServiceBuilder<T extends AbstractServiceBuilder<T>> {
@@ -176,22 +178,12 @@ public String getResponseType() {
176178
protected abstract OAuthConfig createConfig();
177179

178180
/**
179-
* Returns the fully configured {@link OAuth10aService}
181+
* Returns the fully configured {@link S}
180182
*
181183
* @param api will build Service for this API
182-
* @return fully configured {@link OAuth10aService}
184+
* @return fully configured {@link S}
183185
*/
184-
public OAuth10aService build(DefaultApi10a api) {
185-
return api.createService(createConfig());
186-
}
187-
188-
/**
189-
* Returns the fully configured {@link OAuth20Service}
190-
*
191-
* @param api will build Service for this API
192-
* @return fully configured {@link OAuth20Service}
193-
*/
194-
public OAuth20Service build(DefaultApi20 api) {
186+
public <S extends OAuthService> S build(BaseApi<S> api) {
195187
return api.createService(createConfig());
196188
}
197189
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.scribejava.core.builder.api;
2+
3+
import com.github.scribejava.core.model.OAuthConfig;
4+
import com.github.scribejava.core.oauth.OAuthService;
5+
6+
7+
public interface BaseApi<T extends OAuthService> {
8+
T createService(OAuthConfig config);
9+
}

scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do.
3131
*
3232
*/
33-
public abstract class DefaultApi10a {
33+
public abstract class DefaultApi10a implements BaseApi<OAuth10aService> {
3434

3535
/**
3636
* Returns the access token extractor.
@@ -126,6 +126,7 @@ public Verb getRequestTokenVerb() {
126126
*/
127127
public abstract String getAuthorizationUrl(OAuth1RequestToken requestToken);
128128

129+
@Override
129130
public OAuth10aService createService(OAuthConfig config) {
130131
return new OAuth10aService(this, config);
131132
}

scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do.
2323
*
2424
*/
25-
public abstract class DefaultApi20 {
25+
public abstract class DefaultApi20 implements BaseApi<OAuth20Service> {
2626

2727
/**
2828
* Returns the access token extractor.
@@ -88,6 +88,7 @@ public String getAuthorizationUrl(OAuthConfig config, Map<String, String> additi
8888
return authUrl;
8989
}
9090

91+
@Override
9192
public OAuth20Service createService(OAuthConfig config) {
9293
return new OAuth20Service(this, config);
9394
}

0 commit comments

Comments
 (0)