Skip to content

Commit 9262217

Browse files
committed
Merge pull request cloudbees-oss#67 from matthewtckr/newevents
Implement additional Event types
2 parents 08e4801 + a46a5b2 commit 9262217

File tree

5 files changed

+208
-1
lines changed

5 files changed

+208
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.zendesk.client.v2.model.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* An attachment was redacted, or permanently deleted, from a ticket comment
7+
*
8+
* @author matthewtckr
9+
* @see <a href="https://developer.zendesk.com/rest_api/docs/core/ticket_audits#attachment-redaction-event">Zendesk API Documentation</a>
10+
*
11+
*/
12+
public class AttachmentRedactionEvent extends Event {
13+
14+
private Long attachmentId;
15+
private Long commentId;
16+
17+
@JsonProperty("attachment_id")
18+
public Long getAttachmentId() {
19+
return attachmentId;
20+
}
21+
22+
public void setAttachmentId( Long attachmentId ) {
23+
this.attachmentId = attachmentId;
24+
}
25+
26+
@JsonProperty("comment_id")
27+
public Long getCommentId() {
28+
return commentId;
29+
}
30+
31+
public void setCommentId( Long commentId ) {
32+
this.commentId = commentId;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
final StringBuilder sb = new StringBuilder();
38+
sb.append("AttachmentRedactionEvent");
39+
sb.append("{attachmentId=").append(attachmentId);
40+
sb.append(", commentId=").append(commentId);
41+
sb.append('}');
42+
return sb.toString();
43+
}
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.zendesk.client.v2.model.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* A word or string was redacted from a ticket comment
7+
*
8+
* @author matthewtckr
9+
* @see <a href="https://developer.zendesk.com/rest_api/docs/core/ticket_audits#comment-redaction-event">Zendesk API Documentation</a>
10+
*
11+
*/
12+
public class CommentRedactionEvent extends Event {
13+
14+
private Long commentId;
15+
16+
@JsonProperty("comment_id")
17+
public Long getCommentId() {
18+
return commentId;
19+
}
20+
21+
public void setCommentId( Long commentId ) {
22+
this.commentId = commentId;
23+
}
24+
25+
@Override
26+
public String toString() {
27+
final StringBuilder sb = new StringBuilder();
28+
sb.append("CommentRedactionEvent");
29+
sb.append("{commentId=").append(commentId);
30+
sb.append('}');
31+
return sb.toString();
32+
}
33+
}

src/main/java/org/zendesk/client/v2/model/events/Event.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
@JsonSubTypes.Type(value = PushEvent.class, name = "Push"),
2424
@JsonSubTypes.Type(value = TweetEvent.class, name = "Tweet"),
2525
@JsonSubTypes.Type(value = SMSEvent.class, name = "SMS"),
26-
@JsonSubTypes.Type(value = TicketSharingEvent.class, name = "TicketSharingEvent")
26+
@JsonSubTypes.Type(value = TicketSharingEvent.class, name = "TicketSharingEvent"),
27+
@JsonSubTypes.Type(value = AttachmentRedactionEvent.class, name = "AttachmentRedactionEvent" ),
28+
@JsonSubTypes.Type(value = CommentRedactionEvent.class, name = "CommentRedactionEvent" ),
29+
@JsonSubTypes.Type(value = OrganizationActivityEvent.class, name = "OrganizationActivity" )
2730
})
2831

2932
public abstract class Event {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.zendesk.client.v2.model.events;
2+
3+
import java.util.List;
4+
5+
import org.zendesk.client.v2.model.Via;
6+
7+
/**
8+
* A notification was sent to the organization subscribers
9+
*
10+
* @author matthewtckr
11+
* @see <a href="https://developer.zendesk.com/rest_api/docs/core/ticket_audits#organization-subscription-notification-event">Zendesk API Documentation</a>
12+
*
13+
*/
14+
public class OrganizationActivityEvent extends Event {
15+
16+
private String subject;
17+
private String body;
18+
private List<Long> recipients;
19+
private Via via;
20+
21+
public String getSubject() {
22+
return subject;
23+
}
24+
25+
public void setSubject( String subject ) {
26+
this.subject = subject;
27+
}
28+
29+
public String getBody() {
30+
return body;
31+
}
32+
33+
public void setBody( String body ) {
34+
this.body = body;
35+
}
36+
37+
public List<Long> getRecipients() {
38+
return recipients;
39+
}
40+
41+
public void setRecipients( List<Long> recipients ) {
42+
this.recipients = recipients;
43+
}
44+
45+
public Via getVia() {
46+
return via;
47+
}
48+
49+
public void setVia( Via via ) {
50+
this.via = via;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
final StringBuilder sb = new StringBuilder();
56+
sb.append("OrganizationActivityEvent");
57+
sb.append("{subject=").append(subject);
58+
sb.append(", body=").append(body);
59+
sb.append(", recipients=").append(recipients);
60+
sb.append(", via=").append(via);
61+
sb.append('}');
62+
return sb.toString();
63+
}
64+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
6+
import org.junit.Test;
7+
import org.zendesk.client.v2.model.events.AttachmentRedactionEvent;
8+
import org.zendesk.client.v2.model.events.CommentRedactionEvent;
9+
import org.zendesk.client.v2.model.events.Event;
10+
import org.zendesk.client.v2.model.events.OrganizationActivityEvent;
11+
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
14+
public class EventTest {
15+
16+
private Event parseJson( byte[] json ) {
17+
ObjectMapper mapper = new ObjectMapper();
18+
try {
19+
return mapper.readValue( json, Event.class );
20+
} catch ( Exception e ) {
21+
System.out.println( e );
22+
return null;
23+
}
24+
}
25+
26+
@Test
27+
public void testOrganizationActivityEvent() {
28+
String json = "{ \"id\": 21337631753, \"type\": \"OrganizationActivity\", \"subject\": \"Custom Subject\", \"body\": \"This is sample data\", \"recipients\": [568628833] }";
29+
Event ev = parseJson( json.getBytes() );
30+
assertNotNull( ev );
31+
assertEquals( OrganizationActivityEvent.class, ev.getClass() );
32+
assertEquals( new Long(21337631753L), ev.getId() );
33+
assertEquals( "Custom Subject", ((OrganizationActivityEvent) ev).getSubject() );
34+
assertEquals( "This is sample data", ((OrganizationActivityEvent) ev).getBody() );
35+
assertNotNull( ((OrganizationActivityEvent) ev).getRecipients() );
36+
assertEquals( 1, ((OrganizationActivityEvent) ev).getRecipients().size() );
37+
assertEquals( new Long(568628833L), ((OrganizationActivityEvent) ev).getRecipients().get(0) );
38+
assertEquals( "OrganizationActivityEvent{subject=Custom Subject, body=This is sample data, recipients=[568628833], via=null}", ev.toString() );
39+
}
40+
41+
@Test
42+
public void testAttachmentRedactionEvent() {
43+
String json = "{ \"id\": 10593649089, \"type\": \"AttachmentRedactionEvent\", \"attachment_id\": 315988189, \"comment_id\": 10591294149 }";
44+
Event ev = parseJson( json.getBytes() );
45+
assertNotNull( ev );
46+
assertEquals( AttachmentRedactionEvent.class, ev.getClass() );
47+
assertEquals( new Long(10593649089L), ev.getId() );
48+
assertEquals( new Long(315988189L), ((AttachmentRedactionEvent) ev).getAttachmentId() );
49+
assertEquals( new Long(10591294149L), ((AttachmentRedactionEvent) ev).getCommentId() );
50+
assertEquals( "AttachmentRedactionEvent{attachmentId=315988189, commentId=10591294149}", ev.toString() );
51+
}
52+
53+
@Test
54+
public void testCommentRedactionEvent() {
55+
String json = "{ \"id\": 18231937759, \"type\": \"CommentRedactionEvent\", \"comment_id\": \"18974155255\" }";
56+
Event ev = parseJson( json.getBytes() );
57+
assertNotNull( ev );
58+
assertEquals( CommentRedactionEvent.class, ev.getClass() );
59+
assertEquals( new Long(18231937759L), ev.getId() );
60+
assertEquals( new Long(18974155255L), ((CommentRedactionEvent) ev).getCommentId() );
61+
assertEquals( "CommentRedactionEvent{commentId=18974155255}", ev.toString() );
62+
}
63+
}

0 commit comments

Comments
 (0)