diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java
index 933e92b..9ef8f62 100644
--- a/src/nyc/c4q/ramonaharrison/Main.java
+++ b/src/nyc/c4q/ramonaharrison/Main.java
@@ -15,10 +15,10 @@ public static void main(String[] args) {
myBot.listMessages(Slack.BOTS_CHANNEL_ID);
// Post "Hello, world!" to the #bots channel
- //myBot.sendMessage("Hello, world!");
+ myBot.sendMessageToBotsChannel("Hello, world!");
// Post a pineapple photo to the #bots channel
- //myBot.sendMessage("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg");
+ myBot.sendMessageToBotsChannel("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg");
}
}
\ No newline at end of file
diff --git a/src/nyc/c4q/ramonaharrison/model/Attachment.java b/src/nyc/c4q/ramonaharrison/model/Attachment.java
index 8b9d1ef..bec3804 100644
--- a/src/nyc/c4q/ramonaharrison/model/Attachment.java
+++ b/src/nyc/c4q/ramonaharrison/model/Attachment.java
@@ -1,39 +1,170 @@
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 fields;
+ private String imageUrl;
+ private String thumbUrl;
+ private String footer;
+ private String footerIcon;
+ private long ts; // timestamp
+
public Attachment(JSONObject json) {
// TODO: parse an attachment from the incoming json
+ // check for null before assuming item is in json object
+
+ 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();
+ 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");
+ }
+
}
// TODO add getters to access private fields
+ // command + N to generate Getter methods
+
+ 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;
+ }
+
+ public String getTitleLink() {
+ return titleLink;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public List 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;
+ }
}
diff --git a/src/nyc/c4q/ramonaharrison/model/Field.java b/src/nyc/c4q/ramonaharrison/model/Field.java
new file mode 100644
index 0000000..0c1e6f4
--- /dev/null
+++ b/src/nyc/c4q/ramonaharrison/model/Field.java
@@ -0,0 +1,43 @@
+package nyc.c4q.ramonaharrison.model;
+
+import org.json.simple.JSONObject;
+
+/**
+ * Created by akashaarcher on 9/11/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;
+ }
+}