Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 9cd84c0

Browse files
Merge pull request #14 from helpscout/bug/address-dates
Change Address to use Dates in place of Calendar
2 parents f7566e0 + 10f348d commit 9cd84c0

6 files changed

Lines changed: 215 additions & 114 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 1.5.1 (October 28,2015)
2+
3+
* Address model has been updated to use java.util.Data instead of java.util.Calendar objects, de-serialization from JSON payloads will now work correctly.
4+
5+
16
### 1.5.0 (August 27, 2015)
27

38
* Identifiers are now of type `Long` (matching model objects). Old methods using `Integer` are deprecated.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Help Scout Java Wrapper
22
=======================
33
Java Wrapper for the Help Scout API. More information can be found on our [developer site](http://developer.helpscout.net).
44

5-
Version 1.5.0 Released
5+
Version 1.5.1 Released
66
---------------------
77
Please see the [Changelog](https://github.com/helpscout/helpscout-api-java/blob/master/CHANGELOG.md) for details.
88

pom.xml

Lines changed: 114 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,118 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<groupId>net.helpscout</groupId>
4-
<artifactId>helpscout-api</artifactId>
5-
<packaging>jar</packaging>
6-
<version>1.5.0</version>
7-
<name>helpscout-api</name>
8-
<url>http://maven.apache.org</url>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>net.helpscout</groupId>
5+
<artifactId>helpscout-api</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.5.1</version>
8+
<name>helpscout-api</name>
9+
<url>http://maven.apache.org</url>
910

10-
<scm>
11-
<connection>scm:git:git@github.com:helpscout/helpscout-api-java.git</connection>
12-
<developerConnection>scm:git:git@github.com:helpscout/helpscout-api-java.git</developerConnection>
13-
<tag>HEAD</tag>
14-
</scm>
11+
<scm>
12+
<connection>scm:git:git@github.com:helpscout/helpscout-api-java.git</connection>
13+
<developerConnection>scm:git:git@github.com:helpscout/helpscout-api-java.git</developerConnection>
14+
<tag>HEAD</tag>
15+
</scm>
1516

16-
<properties>
17-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
</properties>
19-
<dependencies>
20-
<!-- Gson: Java to Json conversion -->
21-
<dependency>
22-
<groupId>com.google.code.gson</groupId>
23-
<artifactId>gson</artifactId>
24-
<version>2.2.2</version>
25-
<scope>compile</scope>
26-
</dependency>
27-
<dependency>
28-
<groupId>commons-codec</groupId>
29-
<artifactId>commons-codec</artifactId>
30-
<version>1.9</version>
31-
<scope>compile</scope>
32-
</dependency>
33-
<dependency>
34-
<groupId>commons-io</groupId>
35-
<artifactId>commons-io</artifactId>
36-
<version>2.4</version>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.apache.commons</groupId>
40-
<artifactId>commons-lang3</artifactId>
41-
<version>3.4</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>javax.servlet</groupId>
45-
<artifactId>servlet-api</artifactId>
46-
<version>2.5</version>
47-
<scope>provided</scope>
48-
</dependency>
49-
<dependency>
50-
<groupId>org.slf4j</groupId>
51-
<artifactId>slf4j-api</artifactId>
52-
<version>1.6.6</version>
53-
<scope>compile</scope>
54-
</dependency>
55-
<dependency>
56-
<groupId>org.projectlombok</groupId>
57-
<artifactId>lombok</artifactId>
58-
<version>1.16.4</version>
59-
<scope>provided</scope>
60-
</dependency>
61-
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
64-
<version>4.12</version>
65-
<scope>test</scope>
66-
</dependency>
67-
<dependency>
68-
<groupId>com.github.tomakehurst</groupId>
69-
<artifactId>wiremock</artifactId>
70-
<version>1.57</version>
71-
<scope>test</scope>
72-
</dependency>
73-
</dependencies>
74-
<repositories>
75-
<repository>
76-
<id>maven2-repository.dev.java.net</id>
77-
<name>Java.net Repository for Maven</name>
78-
<url>http://download.java.net/maven/2/</url>
79-
<layout>default</layout>
80-
</repository>
81-
</repositories>
82-
<build>
83-
<plugins>
84-
<plugin>
85-
<groupId>org.apache.maven.plugins</groupId>
86-
<artifactId>maven-source-plugin</artifactId>
87-
<version>2.3</version>
88-
<executions>
89-
<execution>
90-
<id>attach-sources</id>
91-
<goals>
92-
<goal>jar</goal>
93-
</goals>
94-
</execution>
95-
</executions>
96-
</plugin>
97-
<plugin>
98-
<groupId>org.apache.maven.plugins</groupId>
99-
<artifactId>maven-javadoc-plugin</artifactId>
100-
<version>2.10</version>
101-
<configuration>
102-
<skip>true</skip>
103-
</configuration>
104-
</plugin>
105-
</plugins>
106-
</build>
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
<dependencies>
21+
<!-- Gson: Java to Json conversion -->
22+
<dependency>
23+
<groupId>com.google.code.gson</groupId>
24+
<artifactId>gson</artifactId>
25+
<version>2.2.2</version>
26+
<scope>compile</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>commons-codec</groupId>
30+
<artifactId>commons-codec</artifactId>
31+
<version>1.9</version>
32+
<scope>compile</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>commons-io</groupId>
36+
<artifactId>commons-io</artifactId>
37+
<version>2.4</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.commons</groupId>
41+
<artifactId>commons-lang3</artifactId>
42+
<version>3.4</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>javax.servlet</groupId>
46+
<artifactId>servlet-api</artifactId>
47+
<version>2.5</version>
48+
<scope>provided</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.slf4j</groupId>
52+
<artifactId>slf4j-api</artifactId>
53+
<version>1.6.6</version>
54+
<scope>compile</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.projectlombok</groupId>
58+
<artifactId>lombok</artifactId>
59+
<version>1.16.4</version>
60+
<scope>provided</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>junit</groupId>
64+
<artifactId>junit</artifactId>
65+
<version>4.12</version>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>com.github.tomakehurst</groupId>
70+
<artifactId>wiremock</artifactId>
71+
<version>1.57</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
<repositories>
76+
<repository>
77+
<id>maven2-repository.dev.java.net</id>
78+
<name>Java.net Repository for Maven</name>
79+
<url>http://download.java.net/maven/2/</url>
80+
<layout>default</layout>
81+
</repository>
82+
</repositories>
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-source-plugin</artifactId>
88+
<version>2.3</version>
89+
<executions>
90+
<execution>
91+
<id>attach-sources</id>
92+
<goals>
93+
<goal>jar</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-javadoc-plugin</artifactId>
101+
<version>2.10</version>
102+
<configuration>
103+
<skip>true</skip>
104+
</configuration>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-compiler-plugin</artifactId>
109+
<version>3.3</version>
110+
<configuration>
111+
<source>1.6</source>
112+
<target>1.6</target>
113+
</configuration>
114+
</plugin>
115+
</plugins>
116+
</build>
107117

108118
</project>

src/main/java/net/helpscout/api/model/customer/Address.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.helpscout.api.model.customer;
22

3-
import java.util.Calendar;
3+
import java.util.Date;
44
import java.util.List;
55

66
import lombok.Data;
@@ -14,6 +14,6 @@ public class Address {
1414
private String state;
1515
private String postalCode;
1616
private String country;
17-
private Calendar createdAt;
18-
private Calendar modifiedAt;
17+
private Date createdAt;
18+
private Date modifiedAt;
1919
}

src/test/java/net/helpscout/api/ApiClientTest.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package net.helpscout.api;
22

3-
import static com.github.tomakehurst.wiremock.client.WireMock.*;
4-
import static java.net.HttpURLConnection.*;
5-
import static org.hamcrest.core.Is.*;
6-
import static org.junit.Assert.*;
3+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5+
import static com.github.tomakehurst.wiremock.client.WireMock.givenThat;
6+
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
7+
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
8+
import static java.net.HttpURLConnection.HTTP_OK;
9+
import static org.hamcrest.core.Is.is;
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertNotNull;
12+
import static org.junit.Assert.assertNull;
13+
import static org.junit.Assert.assertThat;
14+
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
import java.nio.file.Paths;
18+
19+
import lombok.SneakyThrows;
720
import lombok.val;
821
import net.helpscout.api.exception.InvalidFormatException;
922
import net.helpscout.api.json.JsonFormatter;
23+
import net.helpscout.api.model.Customer;
1024

1125
import org.junit.BeforeClass;
1226
import org.junit.Rule;
@@ -54,8 +68,7 @@ public void shouldReturnDetailedErrorMessageForBadRequest() {
5468
val error = "{\"message\":\"Invalid request.\"}";
5569

5670
givenThat(get(urlEqualTo("/v1/mailboxes.json"))
57-
.willReturn(aResponse().withStatus(HTTP_BAD_REQUEST)
58-
.withBody(error)));
71+
.willReturn(aResponse().withStatus(HTTP_BAD_REQUEST).withBody(error)));
5972

6073
try {
6174
client.getMailboxes();
@@ -64,6 +77,33 @@ public void shouldReturnDetailedErrorMessageForBadRequest() {
6477
}
6578
}
6679

80+
@Test
81+
public void shouldRetrieveSpecificCustomer() throws ApiException {
82+
givenThat(get(urlEqualTo("/v1/customers/60984612.json"))
83+
.willReturn(aResponse().withStatus(HTTP_OK)
84+
.withBody(getResponse("customer"))));
85+
86+
Long customerId = 60984612L;
87+
Customer customer = client.getCustomer(customerId);
88+
assertEquals("Peter", customer.getFirstName());
89+
assertEquals(customerId, customer.getId());
90+
assertNotNull(customer.getAddress().getCreatedAt());
91+
Long addressId = 1187643L;
92+
assertEquals(addressId, customer.getAddress().getId());
93+
94+
}
95+
96+
@SneakyThrows
97+
private String getResponse(String responseFile) {
98+
if (responseFile == null) {
99+
return "";
100+
}
101+
String response = null;
102+
Path responseFilePath = Paths.get(ClassLoader.getSystemResource("responses/" + responseFile + ".json").toURI());
103+
response = new String(Files.readAllBytes(responseFilePath));
104+
return response;
105+
}
106+
67107
private String formatted(String rawJson) {
68108
return new JsonFormatter().format(rawJson);
69109
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"item": {
3+
"id": 60984612,
4+
"firstName": "Peter",
5+
"lastName": "Smith",
6+
"fullName": "Peter Smith",
7+
"photoUrl": "http://1.gravatar.com/avatar/10a4c618",
8+
"photoType": "gravatar",
9+
"gender": "unknown",
10+
"age": null,
11+
"organization": null,
12+
"jobTitle": null,
13+
"location": "NL",
14+
"createdAt": "2015-09-22T06:06:19Z",
15+
"modifiedAt": "2015-10-04T07:07:57Z",
16+
"background": null,
17+
"address": {
18+
"id": 1187643,
19+
"lines": [
20+
""
21+
],
22+
"city": null,
23+
"state": null,
24+
"postalCode": null,
25+
"country": "NL",
26+
"createdAt": "2015-09-24T14:35:19Z",
27+
"modifiedAt": "2015-09-30T20:08:13Z"
28+
},
29+
"socialProfiles": null,
30+
"emails": [
31+
{
32+
"id": 76610693,
33+
"value": "petersmith@fakeemail.com",
34+
"location": "work"
35+
},
36+
{
37+
"id": 77590346,
38+
"value": "petersmithwork@fakeemail.com",
39+
"location": "work"
40+
}
41+
],
42+
"phones": [],
43+
"chats": null,
44+
"websites": null
45+
}
46+
}

0 commit comments

Comments
 (0)