44import com .westerhoud .osrs .taskman .domain .AccountCredentials ;
55import com .westerhoud .osrs .taskman .domain .AccountProgress ;
66import com .westerhoud .osrs .taskman .domain .ErrorResponse ;
7- import com .westerhoud .osrs .taskman .domain .SheetRequestBody ;
87import com .westerhoud .osrs .taskman .domain .Task ;
98import java .io .IOException ;
109import lombok .extern .slf4j .Slf4j ;
1716@ Slf4j
1817public class TaskService implements com .westerhoud .osrs .taskman .api .TaskService {
1918
20- private static final String BASE_URL = "https://osrs-taskman.herokuapp.com/sheet" ;
19+ public static final String TASKMAN_IDENTIFIER_HEADER = "x-taskman-identifier" ;
20+ public static final String TASKMAN_PASSWORD_HEADER = "x-taskman-password" ;
21+ public static final String TASKMAN_SOURCE_HEADER = "x-taskman-source" ;
22+ private static final String BASE_URL = "https://osrs-taskman.herokuapp.com/task" ;
2123 private final OkHttpClient client ;
2224 private final Gson gson ;
2325 private final String currentUrl ;
@@ -35,14 +37,20 @@ public TaskService(final OkHttpClient okHttpClient) {
3537 }
3638
3739 @ Override
38- public Task getCurrentTask (final String key ) throws IOException {
39- if (key == null || key . isEmpty ()) {
40+ public Task getCurrentTask (final AccountCredentials credentials ) throws IOException {
41+ if (! credentials . isValid ()) {
4042 throw new IllegalArgumentException (
41- "Please set your username / spreadsheet key in the plugin configurations" );
43+ "Please configure your credentials in the plugin configurations" );
4244 }
4345
4446 final Request request =
45- new Request .Builder ().url (String .format ("%s?key=%s" , currentUrl , key )).get ().build ();
47+ new Request .Builder ()
48+ .url (currentUrl )
49+ .addHeader (TASKMAN_IDENTIFIER_HEADER , credentials .getIdentifier ())
50+ .addHeader (TASKMAN_PASSWORD_HEADER , credentials .getPassword ())
51+ .addHeader (TASKMAN_SOURCE_HEADER , credentials .getSource ().name ())
52+ .get ()
53+ .build ();
4654
4755 return executeRequest (request );
4856 }
@@ -53,7 +61,8 @@ public Task generateTask(final AccountCredentials credentials) throws IOExceptio
5361 new Request .Builder ()
5462 .url (generateUrl )
5563 .header ("Content-Type" , "application/json" )
56- .post (getRequestBody (credentials .getIdentifier (), credentials .getPassword ()))
64+ .addHeader (TASKMAN_SOURCE_HEADER , credentials .getSource ().name ())
65+ .post (getRequestBody (credentials ))
5766 .build ();
5867 return executeRequest (request );
5968 }
@@ -64,20 +73,28 @@ public Task completeTask(final AccountCredentials credentials) throws IOExceptio
6473 new Request .Builder ()
6574 .url (completeUrl )
6675 .header ("Content-Type" , "application/json" )
67- .post (getRequestBody (credentials .getIdentifier (), credentials .getPassword ()))
76+ .addHeader (TASKMAN_SOURCE_HEADER , credentials .getSource ().name ())
77+ .post (getRequestBody (credentials ))
6878 .build ();
6979 return executeRequest (request );
7080 }
7181
7282 @ Override
73- public AccountProgress getAccountProgress (final String key ) throws IOException {
74- if (key == null || key .isEmpty ()) {
83+ public AccountProgress getAccountProgress (final AccountCredentials credentials )
84+ throws IOException {
85+ if (!credentials .isValid ()) {
7586 throw new IllegalArgumentException (
7687 "Please set your username / spreadsheet key in the plugin configurations" );
7788 }
7889
7990 final Request request =
80- new Request .Builder ().url (String .format ("%s?key=%s" , progressUrl , key )).get ().build ();
91+ new Request .Builder ()
92+ .url (progressUrl )
93+ .addHeader (TASKMAN_IDENTIFIER_HEADER , credentials .getIdentifier ())
94+ .addHeader (TASKMAN_PASSWORD_HEADER , credentials .getPassword ())
95+ .addHeader (TASKMAN_SOURCE_HEADER , credentials .getSource ().name ())
96+ .get ()
97+ .build ();
8198
8299 final Response response = client .newCall (request ).execute ();
83100
@@ -89,9 +106,8 @@ public AccountProgress getAccountProgress(final String key) throws IOException {
89106 throw new IllegalArgumentException (error .getMessage ());
90107 }
91108
92- private RequestBody getRequestBody (final String key , final String passphrase ) {
93- final SheetRequestBody body = new SheetRequestBody (key , passphrase );
94- return RequestBody .create (MediaType .parse ("application/json" ), gson .toJson (body ));
109+ private RequestBody getRequestBody (final AccountCredentials credentials ) {
110+ return RequestBody .create (MediaType .parse ("application/json" ), gson .toJson (credentials ));
95111 }
96112
97113 private Task executeRequest (final Request request ) throws IOException {
0 commit comments