Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/nyc/c4q/ramonaharrison/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ public void deleteMessageInBotsChannel(String messageTs) {
System.err.print("Error sending message: " + deleteMessageResponse.getError());
}
}

public void getAnEvent (){
sendMessageToBotsChannel(TodayInHistory.getTodayInHistory().getRandomEvent().toString());
}
}
10 changes: 8 additions & 2 deletions src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package nyc.c4q.ramonaharrison;

import nyc.c4q.ramonaharrison.model.Event;
import nyc.c4q.ramonaharrison.network.HTTP;
import nyc.c4q.ramonaharrison.network.Slack;
import nyc.c4q.ramonaharrison.network.TodayInHistory;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

public class Main {

Expand All @@ -10,15 +15,16 @@ public static void main(String[] args) {

myBot.testApi();

myBot.listChannels();
// myBot.listChannels();

myBot.listMessages(Slack.BOTS_CHANNEL_ID);
// myBot.listMessages(Slack.BOTS_CHANNEL_ID);

// Post "Hello, world!" to the #bots channel
//myBot.sendMessage("Hello, world!");

// Post a pineapple photo to the #bots channel
//myBot.sendMessage("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg");

myBot.getAnEvent();
}
}
166 changes: 145 additions & 21 deletions src/nyc/c4q/ramonaharrison/model/Attachment.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,163 @@
package nyc.c4q.ramonaharrison.model;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Ramona Harrison
* on 8/26/16
*
* A class representing a message attachment.
* See https://api.slack.com/docs/message-attachments
*
*/

public class Attachment {

// TODO: implement private fields for each of the following attachment JSON keys:
// "fallback"
// "color"
// "pretext"
// "author_name"
// "author_link"
// "author_icon"
// "title"
// "title_link"
// "text"
// "fields"
// "image_url"
// "thumb_url"
// "footer"
// "footer_icon"
// "ts"
private String fallback;
private String color;
private String pretext;
private String authorName;
private String authorLink;
private String authorIcon;
private String title;
private String titleLink;
private String text;
private List<Field> fields;
private String imageUrl;
private String thumbUrl;
private String footer;
private String footerIcon;
private long ts;


public Attachment(JSONObject json) {
// TODO: parse an attachment from the incoming json

if (json.containsKey("fallback")) {
this.fallback = (String) json.get("fallback");
}

if (json.containsKey("color")) {
this.color = (String) json.get("color");
}

if (json.containsKey("pretext")) {
this.pretext = (String) json.get("pretext");
}

if (json.containsKey("author_name")) {
this.authorName = (String) json.get("author_name");
}

if (json.containsKey("author_link")) {
this.authorLink = (String) json.get("author_link");
}

if (json.containsKey("author_icon")) {
this.authorIcon = (String) json.get("author_icon");
}

if (json.containsKey("title")) {
this.title = (String) json.get("title");
}

if (json.containsKey("title_link")) {
this.titleLink = (String) json.get("title_link");
}

if (json.containsKey("text")) {
this.text = (String) json.get("text");
}

if (json.containsKey("fields")) {
JSONArray jsonFields = (JSONArray) json.get("fields");
this.fields = new ArrayList<Field>();
for (int i = 0; i < jsonFields.size(); i++) {
Field field = new Field((JSONObject) jsonFields.get(i));
}
}

if (json.containsKey("image_url")) {
this.imageUrl = (String) json.get("image_url");
}

if (json.containsKey("thumb_rl")) {
this.thumbUrl = (String) json.get("thumb_url");
}

if (json.containsKey("footer")) {
this.footer = (String) json.get("footer");
}

if (json.containsKey("footer_icon")) {
this.footerIcon = (String) json.get("footer_icon");
}

// ts = timestamp
if (json.containsKey("ts")) {
this.ts = (long) json.get("ts");
}

}

public String getFallback() {
return fallback;
}

public String getColor() {
return color;
}

public String getPretext() {
return pretext;
}

public String getAuthorName() {
return authorName;
}

public String getAuthorLink() {
return authorLink;
}

public String getAuthorIcon() {
return authorIcon;
}

public String getTitle() {
return title;
}

// TODO add getters to access private fields
public String getTitleLink() {
return titleLink;
}

public String getText() {
return text;
}

}
public List<Field> getFields() {
return fields;
}

public String getImageUrl() {
return imageUrl;
}

public String getThumbUrl() {
return thumbUrl;
}

public String getFooter() {
return footer;
}

public String getFooterIcon() {
return footerIcon;
}

public long getTs() {
return ts;
}
}
41 changes: 41 additions & 0 deletions src/nyc/c4q/ramonaharrison/model/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package nyc.c4q.ramonaharrison.model;

import org.json.simple.JSONObject;

/**
* Created by Rafael on 9/14/16.
*/
public class Event {

private String year;
private String text;


public Event(JSONObject json) {

if (json.containsKey("year")) {
this.year = (String) json.get("year");
}
if (json.containsKey("text")) {
this.text = (String) json.get("text");
}
}

public String getYear() {
return year;
}

public String getText() {
return text;
}

@Override
public String toString() {

String year = getYear();
String text = getText();
String complete = "On this day in " + year + ": \n" + text + "\n";

return complete;
}
}
43 changes: 43 additions & 0 deletions src/nyc/c4q/ramonaharrison/model/Field.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package nyc.c4q.ramonaharrison.model;

import org.json.simple.JSONObject;

/**
* Created by Rafael on 9/15/16.
*/

public class Field {

private String title;
private String value;
private boolean isShort;


public Field(JSONObject json) {

if (json.containsKey("title")) {
this.title = (String) json.get("title");
}

if (json.containsKey("value")) {
this.value = (String) json.get("value");
}

if (json.containsKey("short")) {
this.isShort = (boolean) json.get("short");
}

}

public String getTitle() {
return title;
}

public String getValue() {
return value;
}

public boolean isShort() {
return isShort;
}
}
Loading