Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit bdc9b95

Browse files
Sergi CastellsaguéSergi Castellsagué
authored andcommitted
Merge pull request #5 from StuartApp/add_match_method
Add patch method
2 parents dcc0451 + f2c63c9 commit bdc9b95

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

pom.xml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.stuartapp</groupId>
66
<artifactId>stuart-client-java</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.0.2-snapshot</version>
88

99
<name>Stuart API Java client</name>
1010
<description>Java library to interact with the Stuart API.</description>
@@ -23,19 +23,25 @@
2323
<email>maximilien.tyc@gmail.com</email>
2424
<url>https://github.com/maximilientyc/</url>
2525
</developer>
26+
<developer>
27+
<id>sergicastellsague</id>
28+
<name>Sergi Castellsague</name>
29+
<email>s.castellsague@stuart.com</email>
30+
<url>https://github.com/sergicastellsague/</url>
31+
</developer>
2632
</developers>
2733

2834
<properties>
29-
<maven.compiler.source>1.6</maven.compiler.source>
30-
<maven.compiler.target>1.6</maven.compiler.target>
35+
<maven.compiler.source>1.7</maven.compiler.source>
36+
<maven.compiler.target>1.7</maven.compiler.target>
3137
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3238
</properties>
3339

3440
<scm>
3541
<connection>scm:git:git@github.com:StuartApp/stuart-client-java.git</connection>
3642
<url>scm:git:git@github.com:StuartApp/stuart-client-java.git</url>
3743
<developerConnection>scm:git:git@github.com:StuartApp/stuart-client-java.git</developerConnection>
38-
<tag>HEAD</tag>
44+
<tag>stuart-client-java-1.0.2</tag>
3945
</scm>
4046

4147
<distributionManagement>
@@ -88,6 +94,9 @@
8894
<plugin>
8995
<groupId>org.apache.maven.plugins</groupId>
9096
<artifactId>maven-javadoc-plugin</artifactId>
97+
<configuration>
98+
<detectJavaApiLink>false</detectJavaApiLink>
99+
</configuration>
91100
<executions>
92101
<execution>
93102
<id>attach-javadocs</id>
@@ -100,13 +109,20 @@
100109
<plugin>
101110
<groupId>org.apache.maven.plugins</groupId>
102111
<artifactId>maven-gpg-plugin</artifactId>
112+
<version>1.6</version>
103113
<executions>
104114
<execution>
105115
<id>sign-artifacts</id>
106116
<phase>verify</phase>
107117
<goals>
108118
<goal>sign</goal>
109119
</goals>
120+
<configuration>
121+
<gpgArguments>
122+
<arg>--pinentry-mode</arg>
123+
<arg>loopback</arg>
124+
</gpgArguments>
125+
</configuration>
110126
</execution>
111127
</executions>
112128
</plugin>

src/main/java/com/stuart/stuartclientjava/infrastructure/HttpClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ public ApiResponse performPost(String resource, String body) throws IOException
3737
return new ApiResponse(response.code(), response.body().string());
3838
}
3939

40+
public ApiResponse performPatch(String resource, String body) throws IOException {
41+
Request request = new Request.Builder()
42+
.url(getFullUrl(resource))
43+
.headers(Headers.of(getDefaultHeaders()))
44+
.patch(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body))
45+
.build();
46+
47+
Response response = client.newCall(request).execute();
48+
return new ApiResponse(response.code(), response.body().string());
49+
}
50+
4051
private Map<String, String> getDefaultHeaders() {
4152
Map<String, String> result = new HashMap<String, String>();
4253
result.put("Authorization", String.format("Bearer %s", authenticator.getAccessToken()));

src/test/java/com/stuart/stuartclientjava.infrastructure/HttpClientTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ void shouldSendPostRequestWithCorrectParameters() throws IOException {
6969
assertThat(sink.readUtf8()).isEqualTo("{'some': 'body'}");
7070
}
7171

72+
@Test
73+
void shouldSendPatchRequestWithCorrectParameters() throws IOException {
74+
// when
75+
this.httpClient.performPatch("/sample-endpoint", "{'some': 'body'}");
76+
Request request = this.okHttpClient.getRequest();
77+
78+
// then
79+
assertThat(request.url().toString()).isEqualTo("https://sandbox-api.stuart.com/sample-endpoint");
80+
assertThat(request.method()).isEqualTo("PATCH");
81+
assertThat(request.headers()).isEqualTo(
82+
Headers.of(
83+
"Authorization", "Bearer token",
84+
"User-Agent", String.format("stuart-client-java/%s", new Version().getCurrent()),
85+
"Content-Type", "application/json"
86+
)
87+
);
88+
89+
Buffer sink = new Buffer();
90+
request.body().writeTo(sink);
91+
assertThat(sink.readUtf8()).isEqualTo("{'some': 'body'}");
92+
}
93+
7294
private class HttpClientMock extends HttpClient {
7395

7496
public HttpClientMock(Authenticator authenticator, OkHttpClient client) {

0 commit comments

Comments
 (0)