-
Notifications
You must be signed in to change notification settings - Fork 26
Branches - Erika and Dora #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
f7204f2
05da021
a800226
4b4c5da
845b0d0
9302604
1ef14ce
78010de
58d9be5
d9723f7
60f56e0
6482413
418a91b
6e24945
5faccdc
ae5d805
9d4971c
d8b0488
7afda0c
2fbef17
83b27ff
e6377b0
a831192
7c6b4e7
820b1e5
d9ce1ae
b37ceb4
7c47ea2
c4686c5
d925feb
48852c2
94b85f2
2ce8ed2
eb2304e
3ce2510
06de147
0519a35
3af96bd
de1a4f7
507deab
2be8793
c0999ae
4b15006
751c504
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| require_relative 'recipient' | ||
|
|
||
|
|
||
| class Channel < Recipient | ||
| attr_reader :topic, :member_count, :detail | ||
|
|
||
| def initialize(slack_id:, name:, topic:, member_count:, detail:) | ||
| super(slack_id: slack_id, name: name) | ||
| @topic = topic | ||
| @member_count = member_count | ||
| @detail = detail | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # Source Citation: lines 20-23 & 27 with Paige and Angele | ||
| def self.list | ||
| channels = self.get("https://slack.com/api/conversations.list")["channels"] | ||
|
|
||
| channels.map do |channel| | ||
| name = channel["name"] | ||
| topic = channel["topic"]["value"] | ||
| member_count = channel["num_members"] | ||
| slack_id = channel["id"] | ||
| detail = channel["purpose"]["value"] | ||
|
|
||
| Channel.new(slack_id: slack_id, name: name, topic: topic, member_count: member_count, detail: detail) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
|
|
||
| class SlackApiError < Exception | ||
| # attr_reader | ||
|
|
||
| def initialize | ||
|
|
||
| end | ||
|
|
||
|
|
||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| require 'httparty' | ||
| require 'dotenv' | ||
|
|
||
| Dotenv.load | ||
|
|
||
|
|
||
| class Recipient | ||
| attr_reader :slack_id, :name | ||
|
|
||
| KEY = ENV['SLACK_TOKEN'] | ||
|
|
||
| def initialize(slack_id:, name:) | ||
| @slack_id = slack_id | ||
| @name = name | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def self.get(url) | ||
| HTTParty.get(url, query: {token: KEY}) | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def self.list | ||
| raise NotImplementedError 'Children implement this' | ||
| end | ||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,78 @@ | ||
| #!/usr/bin/env ruby | ||
| require_relative 'workspace' | ||
|
|
||
| def main | ||
| workspace = Workspace.new | ||
|
|
||
| puts "Welcome to the Ada Slack CLI!" | ||
|
|
||
| # TODO project | ||
|
|
||
| puts "Select one of the following options: \'list users\', \'list channels\', \'select user\', \'select channel\', \'details\', \'send message'\ or \'quit\': " | ||
| user_input = gets.chomp.downcase | ||
| until user_input == "quit" | ||
| case user_input | ||
| when "list users", "list user", "user", "users" | ||
| workspace.users.each do |user| | ||
| puts """ | ||
| Slack ID: #{user.slack_id} | ||
| Real name: #{user.real_name} | ||
| Username: #{user.user_name} | ||
| """ | ||
| end | ||
|
|
||
| when "list channels", "list channel", "channels", "channel" | ||
| workspace.channels.each do |channel| | ||
| puts """ | ||
| Slack ID: #{channel.slack_id} | ||
| Name: #{channel.name} | ||
| Topic: #{channel.topic} | ||
| Member count: #{channel.member_count} | ||
| """ | ||
| end | ||
|
|
||
| when "select user", "user" | ||
| puts "Enter username or ID" | ||
| selection = gets.chomp.downcase | ||
| if workspace.select_user(selection) == nil | ||
| puts "Invalid input - username or ID does not exist" | ||
| end | ||
|
|
||
| when "select channel", "channel" | ||
| puts "Enter channel name or ID" | ||
| selection = gets.chomp.downcase | ||
| if workspace.select_channel(selection) == nil | ||
| puts "Invalid input. Channel name or ID does not exist" | ||
| end | ||
|
|
||
| when "send message", "message" | ||
| if workspace.selected == nil | ||
| puts "A recipient has not been selected." | ||
| else | ||
| puts "Enter the message you would like to send:" | ||
| message = gets.chomp | ||
| workspace.send_message(message, workspace.selected.slack_id) | ||
| puts "You sent the following message:" | ||
| puts message | ||
| end | ||
|
|
||
| when "details", "detail" | ||
| if workspace.show_details == nil | ||
| puts "No recipient (user/channel) has been selected" | ||
| end | ||
| puts """ | ||
| #{workspace.show_details.slack_id} | ||
| #{workspace.show_details.detail} | ||
| """ | ||
|
|
||
| end | ||
|
|
||
| puts "Select one of the following options: \'list users\', \'list channels\', \'select user\', \'select channel\', \'send message'\ \'details\' or \'quit\': " | ||
| user_input = gets.chomp.downcase | ||
| end | ||
|
|
||
|
|
||
| puts "Thank you for using the Ada Slack CLI" | ||
|
|
||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
| main if __FILE__ == $PROGRAM_NAME |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| require_relative 'recipient' | ||
| require 'pry' | ||
|
|
||
|
|
||
| class User < Recipient | ||
|
|
||
| attr_reader :slack_id, :user_name, :real_name, :detail | ||
|
|
||
| def initialize(slack_id:, user_name:, real_name:, detail:) | ||
| @user_name = user_name | ||
| @real_name = real_name | ||
| @slack_id = slack_id | ||
| @detail = detail | ||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
| def self.list | ||
|
|
||
| response = self.get("https://slack.com/api/users.list")["members"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be error handling here, reading the response code and returning an instance of SlackApiError. |
||
|
|
||
| users = [] | ||
| response.each do |member| | ||
| user = self.new(slack_id: member["id"], real_name: member["real_name"], user_name: member["name"], detail: member["profile"]["status_text"]) | ||
| users << user | ||
| end | ||
| return users | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| require_relative 'channel' | ||
| require_relative 'user' | ||
| require 'dotenv' | ||
|
|
||
| Dotenv.load | ||
|
|
||
| class Workspace | ||
| attr_reader :users, :channels, :selected | ||
| KEY = ENV['SLACK_TOKEN'] | ||
|
|
||
| def initialize | ||
| @users = User.list | ||
| @channels = Channel.list | ||
| @selected = nil | ||
| end | ||
|
|
||
|
|
||
| def select_channel(selection) | ||
| @selected = @channels.find do |channel| | ||
| channel.name == selection || channel.slack_id == selection.upcase | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def select_user(selection) | ||
| @selected = @users.find do |user| | ||
| user.user_name == selection || user.slack_id == selection.upcase | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def show_details | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to talk with y'all to understand why y'all chose to put this and |
||
| if @selected != nil | ||
| if @selected.class == Channel | ||
| return @selected | ||
| elsif @selected.class == User | ||
| return @selected | ||
| end | ||
| else | ||
| return nil | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def send_message(message, channel) | ||
| response = HTTParty.post("https://slack.com/api/chat.postMessage", | ||
| body: { | ||
| token: ENV["SLACK_TOKEN"], | ||
| channel: channel, | ||
| text: message | ||
| }, | ||
| headers: { 'Content-type' => 'application/x-www-form-urlencoded' } | ||
| ) | ||
| end | ||
|
|
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be error handling here, reading the response code and returning an instance of SlackApiError.