-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created NearKitWalletService to account for changed recent activity e…
…ndpoint
- Loading branch information
Showing
7 changed files
with
118 additions
and
29 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
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
53 changes: 53 additions & 0 deletions
53
...va-api-helper/src/main/java/com/syntifi/near/api/helper/service/NearKitWalletService.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,53 @@ | ||
package com.syntifi.near.api.helper.service; | ||
|
||
import com.syntifi.near.api.common.service.NearObjectMapper; | ||
import com.syntifi.near.api.helper.model.RecentActivity; | ||
import okhttp3.Headers; | ||
import okhttp3.OkHttpClient; | ||
import retrofit2.Call; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.jackson.JacksonConverterFactory; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Path; | ||
|
||
/** | ||
* Near KitWallet Helper service uses the http helper API to retrieve useful data | ||
* | ||
* @author Alexandre Carvalho | ||
* @author Andre Bertolace | ||
* @since 0.2.0 | ||
*/ | ||
public interface NearKitWalletService { | ||
|
||
/** | ||
* NearHelperService builder | ||
* | ||
* @param url the helper url to connect to | ||
* @return the helper service instance | ||
*/ | ||
static NearKitWalletService usingPeer(String url) { | ||
Headers customHeaders = new Headers.Builder() | ||
.add("Content-Type", "application/json") | ||
.add("Cache-Control", "no-cache") | ||
.build(); | ||
|
||
Retrofit retrofit = new Retrofit.Builder() | ||
.client(new OkHttpClient.Builder() | ||
.addInterceptor( | ||
chain -> chain.proceed(chain.request().newBuilder().headers(customHeaders).build())).build()) | ||
.baseUrl("https://" + url) | ||
.addConverterFactory(JacksonConverterFactory.create(NearObjectMapper.INSTANCE)) | ||
.build(); | ||
|
||
return retrofit.create(NearKitWalletService.class); | ||
} | ||
|
||
/** | ||
* Fetches a list of recent activities for one account | ||
* | ||
* @param accountId the account to fetch activity | ||
* @return list of recent activity for the account | ||
*/ | ||
@GET("account/{accountId}/activity") | ||
Call<RecentActivity> getNearRecentActivity(@Path("accountId") String accountId); | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...-helper/src/test/java/com/syntifi/near/api/helper/service/NearKitWalletServiceHelper.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.syntifi.near.api.helper.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class NearKitWalletServiceHelper { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceHelper.class); | ||
|
||
public static NearKitWalletService nearKitWalletService; | ||
|
||
static { | ||
String peerAddress = "testnet-api.kitwallet.app"; | ||
|
||
LOGGER.debug("======== Running tests with helper {} ========", peerAddress); | ||
nearKitWalletService = NearKitWalletService.usingPeer(peerAddress); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...pi-helper/src/test/java/com/syntifi/near/api/helper/service/NearKitWalletServiceTest.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,40 @@ | ||
package com.syntifi.near.api.helper.service; | ||
|
||
import com.syntifi.near.api.helper.model.RecentActivity; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import retrofit2.Response; | ||
|
||
import java.io.IOException; | ||
|
||
import static com.syntifi.near.api.helper.service.NearKitWalletServiceHelper.nearKitWalletService; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Basic Service call testing | ||
* | ||
* @author Alexandre Carvalho | ||
* @author Andre Bertolace | ||
* @since 0.0.1 | ||
*/ | ||
public class NearKitWalletServiceTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceTest.class); | ||
|
||
@Test | ||
void getNearRecentActivity_valid() throws IOException { | ||
Response<RecentActivity> value = nearKitWalletService.getNearRecentActivity("wallet-test.testnet").execute(); | ||
|
||
assertTrue(value.isSuccessful()); | ||
|
||
RecentActivity nearValue = value.body(); | ||
|
||
assertNotNull(nearValue); | ||
|
||
LOGGER.debug("Response {}", nearValue.size()); | ||
|
||
assertNotNull(nearValue); | ||
} | ||
} |