Skip to content

Commit

Permalink
🔨 Refact: Refactor the platform data classes and add the Access base …
Browse files Browse the repository at this point in the history
…class interface.
  • Loading branch information
hanbings committed Jan 8, 2023
1 parent 2cd3e4c commit bf78aec
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 30 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ dependencies {

// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation 'com.google.code.gson:gson:2.10'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
implementation("com.fasterxml.jackson.core:jackson-annotations:2.14.1")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@RequiredArgsConstructor
@SuppressWarnings("unused")
@Accessors(fluent = true, chain = true)
public class OAuth<D, W> implements Authable<D, W> {
public class OAuth<D extends Access, W extends Access.Wrong> implements Accessible<D, W> {
final String authorization;
final String access;
String client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("SpellCheckingInspection")
public interface Authable<D, W> {
public interface Accessible<D extends Access, W extends Access.Wrong> {
String authorize();

String authorize(List<String> scopes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.hanbings.fluocean.common.interfaces;

@SuppressWarnings("SpellCheckingInspection")
public interface Profilable<D, W> {
public interface Profilable<D extends Profile, W extends Profile.Wrong> {
Callback<D, W> profile();

Callback<D, W> profile(String token);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.hanbings.fluocean.common.interfaces;

public interface Profile {
String openid();
interface Wrong {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.hanbings.fluocean.common.interfaces;

public interface Refresh {
String accessToken();

interface Wrong {
String error();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package io.hanbings.fluocean.common.interfaces;

public interface Refreshable<D, W> {
public interface Refreshable<D extends Refresh, W extends Refresh.Wrong> {
Callback<D, W> refresh(String token);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.hanbings.fluocean.common.interfaces;

@SuppressWarnings("SpellCheckingInspection")
public interface Revokable<D, W> {
public interface Revokable<D extends Revoke, W extends Revoke.Wrong> {
Callback<D, W> revoke(String token);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.hanbings.fluocean.common.interfaces;

public interface Revoke {
interface Wrong {

}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package io.hanbings.fluocean.discord;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;
import io.hanbings.fluocean.common.interfaces.Refresh;

public record DiscordAccess(
@JsonProperty("access_token")
@SerializedName("access_token")
String accessToken,
@JsonProperty("token_type")
@SerializedName("token_type")
String tokenType,
@JsonProperty("expires_in")
@SerializedName("expires_in")
long expiresIn,
@JsonProperty("refresh_token")
@SerializedName("refresh_token")
String refreshToken,
@JsonProperty("scope")
@SerializedName("scope")
String scope
) {
) implements Access, Refresh {
record Wrong(
@JsonProperty("error")
@SerializedName("error")
String error
) {
) implements Access.Wrong, Refresh.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.hanbings.fluocean.discord;

public record DiscordRevoke() {
record Wrong() {
import io.hanbings.fluocean.common.interfaces.Revoke;

public record DiscordRevoke() implements Revoke {
record Wrong() implements Revoke.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
package io.hanbings.fluocean.dropbox;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;

public record DropboxAccess(
@JsonProperty("access_token")
@SerializedName("access_token")
String accessToken,
@JsonProperty("expires_in")
@SerializedName("expires_in")
String expiresIn,
@JsonProperty("token_type")
@SerializedName("token_type")
String tokenType,
@JsonProperty("scope")
@SerializedName("scope")
String scope,
@JsonProperty("account_id")
@SerializedName("account_id")
String accountId,
@JsonProperty("team_id")
@SerializedName("team_id")
String teamId,
@JsonProperty("refresh_token")
@SerializedName("refresh_token")
String refreshToken,
@JsonProperty("id_token")
@SerializedName("id_token")
String idToken,
@JsonProperty("uid")
@SerializedName("uid")
String uid
) {
record Wrong(@SerializedName("error")
String error,
@SerializedName("error_description")
String errorDescription,
@SerializedName("state")
String state) {
) implements Access {
record Wrong(
@JsonProperty("error")
@SerializedName("error")
String error,
@JsonProperty("error_description")
@SerializedName("error_description")
String errorDescription,
@JsonProperty("state")
@SerializedName("state")
String state
) implements Access.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package io.hanbings.fluocean.dropbox;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Refresh;

public record DropboxRefresh(
@JsonProperty("access_token")
@SerializedName("access_token")
String accessToken,
@JsonProperty("expires_in")
@SerializedName("expires_in")
String expiresIn,
@JsonProperty("token_type")
@SerializedName("token_type")
String tokenType
) {
) implements Refresh {
record Wrong(
@JsonProperty("error")
@SerializedName("error")
String error,
@JsonProperty("error_description")
@SerializedName("error_description")
String errorDescription,
@JsonProperty("state")
@SerializedName("state")
String state
) {
) implements Refresh.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.hanbings.fluocean.dropbox;

public record DropboxRevoke() {
record Wrong() {
import io.hanbings.fluocean.common.interfaces.Revoke;

public record DropboxRevoke() implements Revoke {
record Wrong() implements Revoke.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.hanbings.fluocean.facebook;

public record FacebookAccess(
import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;

) {
record Wrong() {
public record FacebookAccess(
@SerializedName("access_token")
String accessToken
) implements Access {
record Wrong(
@SerializedName("error")
String error
) implements Access.Wrong {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;

public record GithubAccess(
@SerializedName("access_token")
Expand All @@ -10,14 +11,14 @@ public record GithubAccess(
String tokenType,
@SerializedName("scope")
String scope
) {
) implements Access {
record Wrong(
@SerializedName("error_uri")
String errorUri,
@SerializedName("error")
String error,
@SerializedName("error_description")
String errorDescription
) {
) implements Access.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.hanbings.fluocean.google;

import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;

public record GoogleAccess(
@SerializedName("access_token")
Expand All @@ -13,12 +14,12 @@ public record GoogleAccess(
String scope,
@SerializedName("token_type")
String tokenType
) {
) implements Access {
record Wrong(
@SerializedName("error")
String error,
@SerializedName("error_description")
String errorDescription
) {
) implements Access.Wrong {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.hanbings.fluocean.microsoft;

import com.google.gson.annotations.SerializedName;
import io.hanbings.fluocean.common.interfaces.Access;
import io.hanbings.fluocean.common.interfaces.Refresh;

import java.util.List;

Expand All @@ -17,7 +19,7 @@ public record MicrosoftAccess(
String refreshToken,
@SerializedName("id_token")
String idToken
) {
) implements Access, Refresh {
record Wrong(
@SerializedName("error")
String error,
Expand All @@ -31,6 +33,6 @@ record Wrong(
String traceId,
@SerializedName("correlation_id")
String correlationId
) {
) implements Access.Wrong, Refresh.Wrong {
}
}

0 comments on commit bf78aec

Please sign in to comment.