diff options
author | Vitaly Takmazov | 2017-10-15 05:37:18 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-15 19:50:15 +0300 |
commit | 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc (patch) | |
tree | 38b7a4ba01d1fc47841d3ba2787209b2b2a2de9e /juick-core | |
parent | aeda9e3733e685f5069b5cfbb16272cd32073fa0 (diff) |
api: ImagesService
Diffstat (limited to 'juick-core')
5 files changed, 70 insertions, 67 deletions
diff --git a/juick-core/src/main/java/com/juick/Attachment.java b/juick-core/src/main/java/com/juick/Attachment.java new file mode 100644 index 00000000..76f2995a --- /dev/null +++ b/juick-core/src/main/java/com/juick/Attachment.java @@ -0,0 +1,58 @@ +package com.juick; + +public class Attachment { + private String url; + private Integer height; + private Integer width; + private Attachment small; + private Attachment medium; + private Attachment thumbnail; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public Attachment getSmall() { + return small; + } + + public void setSmall(Attachment small) { + this.small = small; + } + + public Attachment getMedium() { + return medium; + } + + public void setMedium(Attachment medium) { + this.medium = medium; + } + + public Attachment getThumbnail() { + return thumbnail; + } + + public void setThumbnail(Attachment thumbnail) { + this.thumbnail = thumbnail; + } +} diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 25463c46..8f903e1f 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -27,16 +27,13 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; /** * @author Ugnich Anton */ @XmlRootElement(name = "juick", namespace = "http://juick.com/message") -@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) +@XmlAccessorType() public class Message implements Comparable { private int mid = 0; private int rid = 0; @@ -67,6 +64,8 @@ public class Message implements Comparable { private String attachmentType; @XmlTransient private Photo photo; + @XmlTransient + private Attachment attachment; public String Video = null; public Place Place = null; private int likes; @@ -159,25 +158,6 @@ public class Message implements Comparable { } @JsonIgnore - public String getAttachmentURL() { - if (attachmentType != null) { - StringBuilder builder = new StringBuilder(); - - builder.append("http://i.juick.com/"); - builder.append(attachmentType.equals("mp4") ? "video" : "photos-1024"); - builder.append("/").append(getMid()); - - if (getRid() > 0) - builder.append("-").append(getRid()); - - builder.append(".").append(attachmentType); - - return builder.toString(); - } - return null; - } - - @JsonIgnore public String getTagsString() { StringBuilder builder = new StringBuilder(); if (!tags.isEmpty()) { @@ -352,22 +332,10 @@ public class Message implements Comparable { this.repliesBy = repliesBy; } - @JsonProperty("photo") - @XmlTransient - public Photo getPhotoURLs() { - if (StringUtils.isNotBlank(attachmentType)) { - Photo photo = new Photo(); - if (rid > 0) { - photo.setSmall(String.format("https://i.juick.com/photos-512/%d-%d.%s", mid, rid, attachmentType)); - photo.setMedium(String.format("https://i.juick.com/photos-1024/%d-%d.%s", mid, rid, attachmentType)); - photo.setThumbnail(String.format("https://i.juick.com/ps/%d-%d.%s", mid, rid, attachmentType)); - } else { - photo.setSmall(String.format("https://i.juick.com/photos-512/%d.%s", mid, attachmentType)); - photo.setMedium(String.format("https://i.juick.com/photos-1024/%d.%s", mid, attachmentType)); - photo.setThumbnail(String.format("https://i.juick.com/ps/%d.%s", mid, attachmentType)); - } - return photo; - } - return null; + public Attachment getAttachment() { + return attachment; + } + public void setAttachment(Attachment attachment) { + this.attachment = attachment; } } diff --git a/juick-core/src/main/java/com/juick/Photo.java b/juick-core/src/main/java/com/juick/Photo.java index af20fc88..06299610 100644 --- a/juick-core/src/main/java/com/juick/Photo.java +++ b/juick-core/src/main/java/com/juick/Photo.java @@ -20,6 +20,8 @@ package com.juick; /** * Created by vitalyster on 30.11.2016. */ +// used for compatibility +@Deprecated public class Photo { private String small; private String medium; diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java index c62e0134..06ae8a0a 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -39,7 +39,7 @@ public class PlainTextFormatter { sb.append(title).append(jmsg.getUser().getName()).append(":\n") .append(subtitle).append("\n").append(jmsg.getText()).append("\n"); if (jmsg.getPhoto() != null) { - sb.append(jmsg.getAttachmentURL()); + sb.append(jmsg.getAttachment().getMedium().getUrl()); } return sb.toString(); } diff --git a/juick-core/src/test/java/com/juick/MessageTest.java b/juick-core/src/test/java/com/juick/MessageTest.java index b420edfa..3bdac9be 100644 --- a/juick-core/src/test/java/com/juick/MessageTest.java +++ b/juick-core/src/test/java/com/juick/MessageTest.java @@ -128,31 +128,6 @@ public class MessageTest { } @Test - public void attachmentURLShouldBeReturnCorrectResult() throws Exception { - Message message1 = new Message(); - - assertThat(message1.getAttachmentURL(), nullValue()); - - message1.setAttachmentType("jpeg"); - - assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0.jpeg")); - - message1.setRid(1); - - assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0-1.jpeg")); - - Message message2 = new Message(); - - message2.setAttachmentType("mp4"); - - assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0.mp4")); - - message2.setRid(1); - - assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0-1.mp4")); - } - - @Test public void tagsStringShouldBeEmptyIfNoTags() throws Exception { Message message = new Message(); |