Skip to content

Commit

Permalink
- v3.0.0010
Browse files Browse the repository at this point in the history
- upgraded the whole project to be more testable.  Coded to many interfaces which could allow for dependency injection in the future.
  • Loading branch information
cmunden committed Jun 12, 2023
1 parent f2312d5 commit a5bc656
Show file tree
Hide file tree
Showing 105 changed files with 1,966 additions and 1,616 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ out of the gate. There's nothing to change, unless you need a specific feature
implementations (ex. a different Http transport).

### Installation
Version 3.0.0009 of JEtsy is available from the Maven Central Repository [here](https://search.maven.org/search?q=g:com.notronix%20a:JEtsy)
Version 3.0.0010 of JEtsy is available from the Maven Central Repository [here](https://search.maven.org/search?q=g:com.notronix%20a:JEtsy)

<dependency>
<groupId>com.notronix</groupId>
<artifactId>JEtsy</artifactId>
<version>3.0.0009</version>
<version>3.0.0010</version>
</dependency>

### Usage (TODO: update to V3 implementation with OAuth2.0)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.notronix'
version '3.0.0009'
version '3.0.0010'

sourceCompatibility = 1.8

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/com/notronix/etsy/api/API.java
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;
}
10 changes: 10 additions & 0 deletions src/main/java/com/notronix/etsy/api/AppKey.java
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;
}
}
34 changes: 23 additions & 11 deletions src/main/java/com/notronix/etsy/api/EtsyException.java
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");
}
}
14 changes: 0 additions & 14 deletions src/main/java/com/notronix/etsy/api/Method.java

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/java/com/notronix/etsy/api/MethodExecutor.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.notronix.etsy.impl;
package com.notronix.etsy.api;

import java.util.Collection;
import java.util.List;
Expand All @@ -16,7 +16,7 @@
import static org.apache.commons.lang3.StringUtils.join;

@SuppressWarnings("WeakerAccess")
public abstract class EtsyMethodUtils
public abstract class MethodUtils
{
protected static final Function<List<Enum<?>>, String> INCLUDES_CONVERTER = list -> {
Set<String> includes = list.stream().map(Enum::name).collect(toSet());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/notronix/etsy/api/Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.notronix.etsy.api;

public interface Resource
{
}
17 changes: 17 additions & 0 deletions src/main/java/com/notronix/etsy/api/Response.java
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();
}

This file was deleted.

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);
}
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);
}
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
}
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>
{
}
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);
}
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);
}
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;
}
}
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();
}

This file was deleted.

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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public interface TokenResponse
{
String getAccessToken();
AccessToken getAccessToken();
String getTokenType();
Long getExpiresIn();
String getRefreshToken();
RefreshToken getRefreshToken();
}
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 src/main/java/com/notronix/etsy/api/common/method/Method.java
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);
}
Loading

0 comments on commit a5bc656

Please sign in to comment.