Skip to content

Commit 36aa400

Browse files
committed
added support to get Attachement by ID
1 parent 460208c commit 36aa400

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add this dependency and repository to your POM.xml
1616
<dependency>
1717
<groupId>com.xero</groupId>
1818
<artifactId>xero-java-sdk</artifactId>
19-
<version>1.0.7</version>
19+
<version>1.0.8</version>
2020
</dependency>
2121

2222
<repositories>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.xero</groupId>
55
<artifactId>xero-java-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0.7</version>
7+
<version>1.0.8</version>
88
<name>Xero-Java SDK</name>
99
<url>http://maven.apache.org</url>
1010
<dependencies>

src/main/java/com/xero/api/JsonConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public String getAccessTokenUrl() {
114114

115115
@Override
116116
public String getUserAgent() {
117-
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-1.0.7]";
117+
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-1.0.8]";
118118
}
119119

120120
@Override

src/main/java/com/xero/api/XeroClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,6 @@ protected String normalizeFileNameForURI(final String fileName) {
19011901
.replaceAll("[^\\p{Alnum}\\-_.~]", "");
19021902
}
19031903

1904-
19051904
public String getAttachmentContent(String endpoint, String guid, String filename, String accept, String dirPath)
19061905
throws IOException {
19071906
String encodedFileName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
@@ -1913,4 +1912,9 @@ public ByteArrayInputStream getAttachmentContent(String endpoint, String guid, S
19131912
String encodedFileName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
19141913
return getInputStream(endpoint + "/" + guid + "/Attachments/" + encodedFileName, null, null, accept);
19151914
}
1915+
1916+
public ByteArrayInputStream getAttachmentContentById(String endpoint, String guid, String attachmentid, String accept)
1917+
throws IOException {
1918+
return getInputStream(endpoint + "/" + guid + "/Attachments/" + attachmentid, null, null, accept);
1919+
}
19161920
}

src/main/java/com/xero/example/RequestResourceServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.io.InputStream;
88
import java.io.OutputStream;
99
import java.io.PrintWriter;
10-
10+
import java.net.URLEncoder;
1111
import java.util.Date;
1212
import java.util.HashMap;
1313
import java.util.ArrayList;
@@ -36,8 +36,8 @@ public class RequestResourceServlet extends HttpServlet
3636
{
3737
private static final long serialVersionUID = 1L;
3838
private Config config = JsonConfig.getInstance();
39-
final static Logger logger = LogManager.getLogger(OAuthRequestResource.class);
40-
39+
final static Logger logger = LogManager.getLogger(OAuthRequestResource.class);
40+
4141
private String htmlString = "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\" integrity=\"sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7\" crossorigin=\"anonymous\">"
4242
+ "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css\" integrity=\"sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r\" crossorigin=\"anonymous\">"
4343
+ "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\" integrity=\"sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS\" crossorigin=\"anonymous\"></script>"
@@ -208,11 +208,11 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
208208
System.out.println(getInvoiceAttachment.get(0).getFileName() + " --- " +getInvoiceAttachment.get(0).getMimeType());
209209

210210
File f = new File("./");
211-
String fileName1 = "filename.jpg";
211+
String fileName1 = getInvoiceAttachment.get(0).getFileName();
212212
String dirPath = f.getCanonicalPath();
213213
String saveFilePath = dirPath + File.separator + fileName1;
214-
215-
InputStream in = client.getAttachmentContent("Invoices", newInvoice.get(0).getInvoiceID(),getInvoiceAttachment.get(0).getFileName(),getInvoiceAttachment.get(0).getMimeType());
214+
215+
InputStream in = client.getAttachmentContentById("Invoices",newInvoice.get(0).getInvoiceID(),getInvoiceAttachment.get(0).getAttachmentID(),getInvoiceAttachment.get(0).getMimeType());
216216

217217
OutputStream out = new FileOutputStream(saveFilePath);
218218

0 commit comments

Comments
 (0)