Skip to content

Commit

Permalink
Added full implementation of ngrok API (#60)
Browse files Browse the repository at this point in the history
* Added fully implementation of ngrok client API

* progress with the API

* [skip ci] set next development version

* [skip ci] set next development version

* progress with api

* more of ngrok API implementation

* [v0.4.0] Ngrok API implementation

* Merge branch 'main' of https://github.com/kilmajster/ngrok-spring-boot-starter into full_ngrok_api

# Conflicts:
#	pom.xml
#	src/main/java/ngrok/NgrokRunner.java

* bumped dependencies versions
  • Loading branch information
kilmajster committed Sep 18, 2021
1 parent 2848c1d commit 0cd4901
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>

<commons-io.version>2.8.0</commons-io.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<vavr.version>0.10.4</vavr.version>

<spring-cloud-contract-wiremock.version>3.0.2</spring-cloud-contract-wiremock.version>
<spring-cloud-contract-wiremock.version>3.0.3</spring-cloud-contract-wiremock.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -107,7 +108,7 @@
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.10.3</version>
<version>${vavr.version}</version>
</dependency>

<dependency>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ngrok/api/NgrokApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,28 @@ public boolean stopTunnel(final String tunnelName) {
* Returns a list of all HTTP requests captured for inspection. This will only return requests
* that are still in memory (ngrok evicts captured requests when their memory usage exceeds inspect_db_size)
*/
public List<NgrokCapturedRequest> listCapturedRequests(final int limit, final String tunnelName) {
public List<NgrokCapturedRequest> listCapturedRequests(final Integer limit, final String tunnelName) {
return Try.of(() -> restTemplate
.getForObject(UriComponentsBuilder.fromUriString(
apiUrlOf(URI_NGROK_API_CAPTURED_REQUESTS))
.queryParamIfPresent("limit", limit > 0 ? Optional.of(limit) : Optional.empty())
.queryParamIfPresent("limit", Optional.ofNullable(limit))
.queryParamIfPresent("tunnel_name", Optional.ofNullable(tunnelName))
.toUriString(),
NgrokCapturedRequestsList.class
).getRequests()
).getOrElse(Collections.emptyList());
}

public List<NgrokCapturedRequest> listCapturedRequests(final int limit) {
public List<NgrokCapturedRequest> listCapturedRequests(final Integer limit) {
return listCapturedRequests(limit, null);
}

public List<NgrokCapturedRequest> listCapturedRequests(final String tunnelName) {
return listCapturedRequests(-1, tunnelName);
return listCapturedRequests(null, tunnelName);
}

public List<NgrokCapturedRequest> listCapturedRequests() {
return listCapturedRequests(-1, null);
return listCapturedRequests(null, null);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/ngrok/api/NgrokApiClientIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ngrok.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import ngrok.api.model.NgrokCapturedRequest;
import ngrok.api.model.NgrokTunnel;
import ngrok.api.rquest.NgrokStartTunnel;
import ngrok.configuration.NgrokConfiguration;
Expand All @@ -26,6 +27,8 @@
import static ngrok.api.NgrokApiClient.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@ActiveProfiles(TEST_NGROK_PROFILE)
@AutoConfigureWireMock(port = 4040)
Expand Down Expand Up @@ -122,7 +125,7 @@ public void startTunnel_shouldStartNgrokTunnel() throws IOException {
.willReturn(
aResponse()
.withStatus(HttpStatus.CREATED.value())
.withHeader("Content-Type", "application/json")
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(tunnelAsJson)));

// when
Expand Down Expand Up @@ -162,7 +165,7 @@ public void tunnelDetail_shouldReturnTunnelDetailsWhenTunnelExistsForGivenName()
.willReturn(
aResponse()
.withStatus(HttpStatus.OK.value())
.withHeader("Content-Type", "application/json")
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(tunnelAsJson)));

// when
Expand All @@ -182,7 +185,7 @@ public void tunnelDetail_shouldThrowExceptionWhenTunnelNotExistsForGivenName() {
.willReturn(
aResponse()
.withStatus(HttpStatus.NOT_FOUND.value())
.withHeader("Content-Type", "application/json")));
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)));

// when & then
assertThatThrownBy(() -> ngrokApiClient.tunnelDetail(TEST_INVALID_TUNNEL_NAME))
Expand Down Expand Up @@ -221,6 +224,4 @@ public void stopTunnel_shouldReturnFalseWhenTunnelForGivenNameWasNotStopped() {
// then
assertThat(tunnelStopped).isFalse();
}


}

0 comments on commit 0cd4901

Please sign in to comment.