-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- upgraded the whole project to be more testable. Coded to many interfaces which could allow for dependency injection in the future.
- Loading branch information
Showing
105 changed files
with
1,966 additions
and
1,616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ plugins { | |
} | ||
|
||
group 'com.notronix' | ||
version '3.0.0009' | ||
version '3.0.0010' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
package com.notronix.etsy.api; | ||
|
||
import com.notronix.etsy.api.authentication.AuthResource; | ||
import com.notronix.etsy.api.listings.ListingResource; | ||
import com.notronix.etsy.api.shops.ShopResource; | ||
import com.notronix.etsy.api.taxonomy.TaxonomyResource; | ||
import com.notronix.etsy.api.users.UserResource; | ||
import com.notronix.etsy.api.authentication.method.AuthResource; | ||
import com.notronix.etsy.api.common.method.Method; | ||
import com.notronix.etsy.api.listings.method.ListingResource; | ||
import com.notronix.etsy.api.shops.method.ShopResource; | ||
import com.notronix.etsy.api.taxonomy.method.TaxonomyResource; | ||
import com.notronix.etsy.api.users.method.UserResource; | ||
|
||
public interface API | ||
public interface API<C> | ||
{ | ||
AuthResource getAuthResource(); | ||
void setMarshaller(Marshaller marshaller); | ||
|
||
ListingResource getListingResource(); | ||
void setUnmarshaller(Unmarshaller unmarshaller); | ||
|
||
ShopResource getShopResource(); | ||
AuthResource<C> getAuthResource(); | ||
|
||
TaxonomyResource getTaxonomyResource(); | ||
UserResource<C> getUserResource(); | ||
|
||
UserResource getUserResource(); | ||
ListingResource<C> getListingResource(); | ||
|
||
ShopResource<C> getShopResource(); | ||
|
||
TaxonomyResource<C> getTaxonomyResource(); | ||
|
||
<T> Response<T> execute(AppKey appKey, Method<T, C> method) throws EtsyException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.notronix.etsy.api; | ||
|
||
import com.notronix.etsy.api.authentication.model.Credential; | ||
|
||
public interface AppKey extends Credential | ||
{ | ||
static AppKey forKeyString(final String keyString) { | ||
return () -> keyString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
package com.notronix.etsy.api; | ||
|
||
import static java.lang.Boolean.TRUE; | ||
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; | ||
import static org.apache.commons.lang3.StringUtils.trim; | ||
|
||
public class EtsyException extends Exception | ||
{ | ||
private Boolean dueToExpiredToken; | ||
private String error; | ||
private String errorDescription; | ||
|
||
public EtsyException(String message) | ||
{ | ||
public EtsyException(String message) { | ||
super(message); | ||
} | ||
|
||
public EtsyException(Throwable cause) | ||
{ | ||
public EtsyException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public EtsyException(String message, Throwable cause) | ||
{ | ||
public EtsyException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public EtsyException dueToExpiredToken(boolean dueToExpiredToken) { | ||
this.dueToExpiredToken = dueToExpiredToken; | ||
public String getError() { | ||
return error; | ||
} | ||
|
||
public EtsyException withError(String error) { | ||
this.error = error; | ||
return this; | ||
} | ||
|
||
public String getErrorDescription() { | ||
return errorDescription; | ||
} | ||
|
||
public EtsyException withErrorDescription(String errorDescription) { | ||
this.errorDescription = errorDescription; | ||
return this; | ||
} | ||
|
||
public boolean isDueToExpiredToken() { | ||
return TRUE.equals(dueToExpiredToken); | ||
return equalsIgnoreCase(trim(errorDescription), "access token is expired"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.notronix.etsy.api; | ||
|
||
public interface Resource | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.notronix.etsy.api; | ||
|
||
public interface Response<T> | ||
{ | ||
String REQUEST_UUID = "X-Etsy-Request-Uuid"; | ||
String LIMIT_PER_SECOND = "X-Limit-Per-Second"; | ||
String REMAINING_THIS_SECOND = "X-Remaining-This-Second"; | ||
String LIMIT_PER_DAY = "X-Limit-Per-Day"; | ||
String REMAINING_THIS_DAY = "X-Remaining-Today"; | ||
|
||
String getRequestUUID(); | ||
Integer getLimitPerSecond(); | ||
Integer getLimitPerDay(); | ||
Integer getCallsRemainingThisDay(); | ||
Integer getCallsRemainingThisSecond(); | ||
T getContent(); | ||
} |
19 changes: 0 additions & 19 deletions
19
src/main/java/com/notronix/etsy/api/authentication/AuthResource.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/notronix/etsy/api/authentication/method/AuthResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
import com.notronix.etsy.api.AppKey; | ||
import com.notronix.etsy.api.Resource; | ||
import com.notronix.etsy.api.authentication.model.AccessToken; | ||
import com.notronix.etsy.api.authentication.model.LegacyToken; | ||
import com.notronix.etsy.api.authentication.model.RefreshToken; | ||
|
||
public interface AuthResource<C> extends Resource | ||
{ | ||
PingMethod<C> createPingMethod(); | ||
|
||
RefreshTokenMethod<C> createRefreshTokenMethod(AppKey appKey, RefreshToken refreshToken); | ||
|
||
ExchangeTokenMethod<C> createExchangeTokenMethod(AppKey appKey, LegacyToken legacyToken); | ||
|
||
TokenScopesMethod<C> createTokenScopesMethod(AccessToken accessToken); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/notronix/etsy/api/authentication/method/ExchangeTokenMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
import com.notronix.etsy.api.AppKey; | ||
import com.notronix.etsy.api.authentication.model.LegacyToken; | ||
import com.notronix.etsy.api.authentication.model.TokenResponse; | ||
import com.notronix.etsy.api.common.method.Method; | ||
|
||
public interface ExchangeTokenMethod<C> extends Method<TokenResponse, C> | ||
{ | ||
void setAppKey(AppKey appKey); | ||
void setLegacyToken(LegacyToken refreshToken); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/notronix/etsy/api/authentication/method/GrantType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
public enum GrantType | ||
{ | ||
refresh_token, | ||
token_exchange | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/notronix/etsy/api/authentication/method/PingMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
import com.notronix.etsy.api.common.method.Method; | ||
|
||
public interface PingMethod<C> extends Method<Long, C> | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/notronix/etsy/api/authentication/method/RefreshTokenMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
import com.notronix.etsy.api.AppKey; | ||
import com.notronix.etsy.api.common.method.Method; | ||
import com.notronix.etsy.api.authentication.model.RefreshToken; | ||
import com.notronix.etsy.api.authentication.model.TokenResponse; | ||
|
||
public interface RefreshTokenMethod<Content> extends Method<TokenResponse, Content> | ||
{ | ||
void setAppKey(AppKey appKey); | ||
void setRefreshToken(RefreshToken refreshToken); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/notronix/etsy/api/authentication/method/TokenScopesMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.notronix.etsy.api.authentication.method; | ||
|
||
import com.notronix.etsy.api.authentication.model.AccessToken; | ||
import com.notronix.etsy.api.authentication.model.EtsyScope; | ||
import com.notronix.etsy.api.common.method.Method; | ||
|
||
import java.util.List; | ||
|
||
public interface TokenScopesMethod<C> extends Method<List<EtsyScope>, C> | ||
{ | ||
void setToken(AccessToken accessToken); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/notronix/etsy/api/authentication/model/AccessToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.notronix.etsy.api.authentication.model; | ||
|
||
public interface AccessToken extends Credential | ||
{ | ||
static AccessToken forToken(final String token) { | ||
return () -> token; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/notronix/etsy/api/authentication/model/Credential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.notronix.etsy.api.authentication.model; | ||
|
||
public interface Credential | ||
{ | ||
String getValue(); | ||
} |
34 changes: 0 additions & 34 deletions
34
src/main/java/com/notronix/etsy/api/authentication/model/Credentials.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/java/com/notronix/etsy/api/authentication/model/LegacyToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.notronix.etsy.api.authentication.model; | ||
|
||
public interface LegacyToken extends Credential | ||
{ | ||
static LegacyToken forToken(final String token) { | ||
return () -> token; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/notronix/etsy/api/authentication/model/RefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.notronix.etsy.api.authentication.model; | ||
|
||
public interface RefreshToken extends Credential | ||
{ | ||
static RefreshToken forToken(final String token) { | ||
return () -> token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/notronix/etsy/api/common/method/EtsyParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.notronix.etsy.api.common.method; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
public @interface EtsyParameter | ||
{ | ||
ParameterPosition position() default ParameterPosition.BODY; | ||
|
||
boolean nullable() default true; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/notronix/etsy/api/common/method/Method.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.notronix.etsy.api.common.method; | ||
|
||
import com.notronix.etsy.api.Marshaller; | ||
import com.notronix.etsy.api.Unmarshaller; | ||
|
||
public interface Method<B, C> | ||
{ | ||
String getURL(); | ||
B buildResponseBody(Unmarshaller unmarshaller, String payload); | ||
String getRequestMethod(); | ||
C buildRequestContent(Marshaller marshaller); | ||
} |
Oops, something went wrong.