Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git update #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ public static void main(String[] args) {
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");


//Message with attachment

myBot.sendMessageWithAttachments("Hello, world!", myBot.message.getAttachments() );
}
}
135 changes: 134 additions & 1 deletion src/nyc/c4q/ramonaharrison/model/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,160 @@

public class Attachment {



// TODO: implement private fields for each of the following attachment JSON keys:
private String fallback;
// "fallback"

private String color;
// "color"

private String pretext;
// "pretext"

private String authorName;
// "author_name"

private String authorLink;
// "author_link"

private String authorIcon;
// "author_icon"

private String title;
// "title"

private String titleLink;
// "title_link"

private String text;
// "text"

private String fields;
// "fields"

private String imageUrl;
// "image_url"

private String thumbUrl;
// "thumb_url"

private String footer;
// "footer"

private String footerIcon;
// "footer_icon"

private String ts;
// "ts"

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

if (json.get("fallback") != null) {
this.fallback = (String) json.get("fallback");
}
if (json.get("color") != null) {
color = (String) json.get("color");
}
if (json.get("pretext") != null) {
pretext = (String) json.get("pretext");
}
if (json.get("author_icon") != null) {
authorIcon = (String) json.get("author_icon");
}
if (json.get("author_link") != null) {
authorLink = (String) json.get("author_link");
}
if (json.get("author_name") != null) {
authorName = (String) json.get("author_name");
}
if (json.get("title") != null) {
title = (String) json.get("title");
}
if (json.get("title_link") != null) {
titleLink = (String) json.get("title_link");
}
if (json.get("text") != null) {
text = (String) json.get("text");
}
if (json.get("fields") != null) {
fields = (String) json.get("fields");
}
if (json.get("image_url") != null) {
imageUrl = (String) json.get("image_url");
}
if (json.get("thumb_url") != null) {
thumbUrl = (String) json.get("thumb_url");
}
if (json.get("footer") != null) {
footer = (String) json.get("footer");
}
if (json.get("footer_icon") != null) {
footerIcon = (String) json.get("footer_icon");
}
if (json.get("ts") != null) {
ts = (String) json.get("ts");
}
}

// TODO add getters to access private fields
public String getFallback() {
return fallback;
}
public String getColor(){
return color;
}
public String getPretext(){
return pretext;
}

public String getAuthorIcon() {
return authorIcon;
}

}
public String getAuthorLink() {
return authorLink;
}

public String getAuthorName() {
return authorName;
}

public String getTitle(){
return title;
}

public String getTitleLink() {
return titleLink;
}

public String getFields() {
return fields;
}

public String getFooter() {
return footer;
}

public String getFooterIcon() {
return footerIcon;
}

public String getImageUrl() {
return imageUrl;
}

public String getText() {
return text;
}

public String getThumbUrl() {
return thumbUrl;
}

public String getTs() {
return ts;
}
}
121 changes: 120 additions & 1 deletion src/nyc/c4q/ramonaharrison/model/User.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nyc.c4q.ramonaharrison.model;

import com.sun.tools.javac.jvm.Profile;
import org.json.simple.JSONObject;

/**
Expand All @@ -14,23 +15,141 @@
public class User {

// TODO: implement private fields for each of the following user JSON keys:

// "id"
private String id;

// "name"
private String name;

// "deleted"
private boolean deleted;

// "color"
private String color;

// "profile"
private Profile profile;

// "is_admin"
private boolean isAdmin;

// "is_owner"
private boolean isOwner;

// "is_primary_owner"
private boolean isPrimaryOwner;

// "is_restricted"
private boolean isRestricted;

// "is_ultra_restricted"
private boolean isUltraRestricted;

// "has_2fa"
private boolean has2fa;

// "two_factor_type"
private boolean twoFactorType;

// "has_files"
private boolean hasFiles;

public User(JSONObject json) {
// TODO: parse a user from the incoming json
if (json.get("id") != null) {
this.id = (String) json.get("id");
}
if (json.get("name") != null) {
this.name = (String) json.get("name");
}
if (json.get("deleted") != null) {
this.deleted = (boolean) json.get("deleted");
}
if (json.get("color") != null) {
this.color = (String) json.get("color");
}
if (json.get("profile") != null) {
this.profile = (Profile) json.get("profile");
}
if (json.get("is_admin") != null) {
this.isAdmin = (boolean) json.get("is_admin");
}
if (json.get("is_owner") != null) {
this.isOwner = (boolean) json.get("is_owner");
}
if (json.get("is_primary_owner") != null) {
this.isPrimaryOwner = (boolean) json.get("is_primary_owner");
}
if (json.get("is_restricted") != null) {
this.isRestricted = (boolean) json.get("is_restricted");
}
if (json.get("is_ultra_restricted") != null) {
this.isUltraRestricted = (boolean) json.get("is_ultra_restricted");
}
if (json.get("has_2fa") != null) {
this.has2fa = (boolean) json.get("has_2fa");
}
if (json.get("two_factor_type") != null) {
this.twoFactorType = (boolean) json.get("two_factor_type");
}
if (json.get("has_files") != null) {
this.hasFiles = (boolean) json.get("has_files");
}
}

// TODO add getters to access private fields
}


public String getName() {
return name;
}

public Profile getProfile() {
return profile;
}

public String getColor() {
return color;
}

public String getId() {
return id;
}

public boolean isAdmin() {
return isAdmin;
}

public boolean isDeleted() {
return deleted;
}

public boolean isHas2fa() {
return has2fa;
}

public boolean isHasFiles() {
return hasFiles;
}

public boolean isOwner() {
return isOwner;
}

public boolean isPrimaryOwner() {
return isPrimaryOwner;
}

public boolean isRestricted() {
return isRestricted;
}

public boolean isTwoFactorType() {
return twoFactorType;
}

public boolean isUltraRestricted() {
return isUltraRestricted;
}
}
20 changes: 18 additions & 2 deletions src/nyc/c4q/ramonaharrison/network/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class Slack {

private static final String API_KEY = Token.findApiToken();
private static final String BASE_URL = "https://slack.com/api/";
private static final String BASE_URL = "https://c4q-accesscode-4-4.slack.com/services/B7JFZS2E7";
private static final String ENDPOINT_TEST = "api.test";
private static final String ENDPOINT_LIST_CHANNELS = "channels.list";
private static final String ENDPOINT_LIST_MESSAGES = "channels.history";
Expand Down Expand Up @@ -97,7 +97,23 @@ public static SendMessageResponse sendMessage(String messageText) {
public static SendMessageResponse sendMessageWithAttachments(String messageText, List<Attachment> attachments) {

// TODO (optional): implement this method! See https://api.slack.com/docs/message-attachments
throw new RuntimeException("Method not implemented!");

attachments.add(messageTex

message(attachments);

try {
messageText = URLEncoder.encode(messageText, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText);

return new SendMessageResponse(HTTPS.get(sendMessageUrl));



}

/**
Expand Down