forked from AdaGold/slack-cli
-
Notifications
You must be signed in to change notification settings - Fork 31
slack_project - Stacy & Mona #19
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
Open
MonaRahmani
wants to merge
57
commits into
Ada-C14:master
Choose a base branch
from
MonaRahmani:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
42cf5d3
initial setup done
MonaRahmani cb3067a
tested the token - request sent and got the data back
MonaRahmani a81cd6e
all files added
MonaRahmani caf8e12
Add coverage directory to .gitignore file
MonaRahmani d24fd7e
still working on wave 1
MonaRahmani 54fa953
slack.rb edited
MonaRahmani 1256221
commit before starting Floobits
MonaRahmani 5d37f27
updated some of the methods
MonaRahmani 25d5ba4
channel & user tests added - not done yet
MonaRahmani 4ae2649
workspace methods added
MonaRahmani 614ded9
ss
MonaRahmani 10e2c11
some tests added
MonaRahmani a176b03
edited user test
MonaRahmani a3e6328
edited channel test
MonaRahmani 5326903
def details added for user and channel
MonaRahmani ff0817a
def send_message added
MonaRahmani 1f3f1c2
test passes
MonaRahmani b25fd29
last push
MonaRahmani 056e7ac
commit so I can pull
StacyLundquist ad9f987
Merge branch 'master' of https://github.com/MonaRahmani/slack-cli int…
StacyLundquist f183941
test error for channel fixed
MonaRahmani 405efc9
asedf
StacyLundquist 57413c2
latest version
MonaRahmani 75d4510
Revert "asedf"
StacyLundquist 1130c34
revert asedf
StacyLundquist 883a744
reset channel
StacyLundquist 919b362
reset recipient
StacyLundquist f822985
reset slack
StacyLundquist b94443d
reset user
StacyLundquist 7a12649
reset workspace
StacyLundquist f0293fa
workspace reset
StacyLundquist a290ed9
user_test reset
StacyLundquist 1df996c
recipient_test reset
StacyLundquist c9eeb86
channel_test reset
StacyLundquist a15ccac
still working
MonaRahmani 949a8cf
Merge branch 'master' of https://github.com/MonaRahmani/slack-cli int…
MonaRahmani ca8bbaf
workspace & recipient tets added - working on passing the test
MonaRahmani de5cc4e
all tests passed
MonaRahmani 6456bad
Adding terminal table
StacyLundquist e38cf05
Adding use of table print
StacyLundquist a1f200f
added option to select with number
StacyLundquist 548dfc8
7
StacyLundquist eae11aa
added token to lib
StacyLundquist cbbb447
upating
StacyLundquist 93e8000
fixed slack-line-23. Removed bug.
StacyLundquist 4b2dfc1
slack.rb line 41 bug fix
StacyLundquist 387c217
recipient.rb formatting fix
StacyLundquist e94d74e
final typo changes. Final push.
StacyLundquist fad5ba7
final push
MonaRahmani e258fcb
activated API again
MonaRahmani 1cdf44d
small correction
MonaRahmani a4a33a4
token changed
MonaRahmani 774b4bb
.env added
MonaRahmani 4971df7
.env added to .git ignore
MonaRahmani 71c2d89
new api
MonaRahmani 512c078
had to remove api, I couldnt hide it
MonaRahmani 136ceed
header added to the post request
MonaRahmani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SLACK_TOKEN= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,11 @@ | |
| .DS_Store | ||
|
|
||
| # Ignore environemnt variables | ||
| .env | ||
| lib/.env | ||
|
|
||
|
|
||
|
|
||
| coverage | ||
|
|
||
| .rvmrc | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| require_relative 'recipient' | ||
|
|
||
| class Channel < Recipient | ||
|
|
||
| attr_reader :topic, :member_count | ||
|
|
||
| def initialize(name:, slack_id:, topic:, member_count:) | ||
| super(slack_id: slack_id, name: name) | ||
| @topic = topic | ||
| @member_count = member_count | ||
| end | ||
|
|
||
| def details | ||
| #prints info for currently selected channel, if not, should let user know and return to main command prompt | ||
| detailed_info = "Slack_id: #{slack_id}, Name: #{@name}, Member Count: #{@member_count}" | ||
| return detailed_info | ||
| end | ||
|
|
||
| def self.list_all | ||
| response = get(CHANNEL_LIST, {token: ENV['SLACK_TOKEN']}) | ||
| channels = [] | ||
| response["channels"].each do |channel| | ||
| new_channel = new( | ||
| name: channel["name"], | ||
| slack_id: channel["id"], | ||
| topic: channel["topic"]["value"], | ||
| member_count: channel["num_members"] | ||
| ) | ||
| channels << new_channel | ||
| end | ||
| return channels | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require 'httparty' | ||
|
|
||
| class SlackAPIError < StandardError; end | ||
|
|
||
| class Recipient | ||
| CHANNEL_LIST = 'https://slack.com/api/conversations.list' | ||
| USER_LIST = 'https://slack.com/api/users.list' | ||
| MESSAGE_LIST = 'https://slack.com/api/chat.postMessage' | ||
|
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.
|
||
|
|
||
| attr_reader :slack_id, :name | ||
|
|
||
| def initialize(slack_id:, name:) | ||
| @slack_id = slack_id | ||
| @name = name | ||
| end | ||
|
|
||
| def send_message(message) | ||
| response = HTTParty.post( | ||
| MESSAGE_LIST, | ||
| headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, | ||
| body: { | ||
| token: ENV['SLACK_TOKEN'], | ||
| text: message, | ||
| channel: @slack_id | ||
| }) | ||
| unless response['ok'] == true | ||
| raise SlackAPIError, "API call failed with reason #{response['error']}" | ||
| end | ||
| return true | ||
| end | ||
|
|
||
|
|
||
| def self.get(url, params) | ||
| response = HTTParty.get(url, query: params) | ||
|
|
||
| if !response["ok"] | ||
| raise SlackAPIError, "API call failed with reason #{response['error']}" | ||
| end | ||
| return response | ||
| end | ||
|
|
||
| def details | ||
| raise NotImplementedError, 'Implement me in a child class!' | ||
| end | ||
|
|
||
| def self.list_all | ||
| raise NotImplementedError, 'Implement me in a child class!' | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,63 @@ | ||
| #!/usr/bin/env ruby | ||
| require_relative 'workspace' | ||
| require 'dotenv' | ||
| require 'table_print' | ||
| require 'terminal-table' | ||
|
|
||
| def main | ||
|
|
||
| Dotenv.load | ||
| puts "Welcome to the Ada Slack CLI!" | ||
| workspace = Workspace.new | ||
|
|
||
| # TODO project | ||
| user_input = request_input | ||
| until user_input == "quit" | ||
|
|
||
| case user_input | ||
| when "list users", '1' | ||
| tp workspace.users, :name, :slack_id, :real_name | ||
| when "list channels", '2' | ||
| tp workspace.channels, :name, :topic, :member_count, :slack_id | ||
| when "select user", '3' | ||
| puts "What is the slack Id" | ||
| id = gets.chomp | ||
| unless workspace.select_user(id).nil? | ||
| puts "enter details to see information about #{id}" | ||
| puts "enter send message to send a message to #{id}" | ||
| end | ||
| when "select channel", '4' | ||
| puts "Please type the channel name: " | ||
| id = gets.chomp | ||
| if workspace.select_channel(id).nil? | ||
| puts "#{id} is not a channel, try again?" | ||
| else | ||
| puts "enter details to see information about #{id}" | ||
| puts "enter 'send message' to send a message to #{id}" | ||
| end | ||
| when "details", '5' | ||
| puts workspace.show_details | ||
| when "send message", '6' | ||
| puts "Please type your message: " | ||
| message = gets.chomp | ||
| unless workspace.send_message(message).nil? | ||
| puts "Your message was sent!" | ||
| end | ||
| when "quit", '7' | ||
| break | ||
| end | ||
| puts "=======================================" | ||
| puts "Would you like to select another option?" | ||
| user_input = request_input | ||
| end | ||
| puts "Thank you for using the Ada Slack CLI" | ||
| end | ||
| def request_input | ||
| options_table = [[1, 'List Users'], [2, 'List Channels'], [3, 'Select User'], | ||
| [4, 'Select Channel'], [5, 'Details'], [6, 'Send Message'], [7, 'QUIT']] | ||
|
|
||
| options = Terminal::Table.new :title => 'What would you like to do?', :rows => options_table | ||
| puts options | ||
|
|
||
| main if __FILE__ == $PROGRAM_NAME | ||
| return gets.chomp.downcase | ||
| end | ||
| main if __FILE__ == $PROGRAM_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| require_relative 'recipient' | ||
|
|
||
| class User < Recipient | ||
|
|
||
| attr_reader :real_name, :status_text, :status_emoji | ||
|
|
||
| def initialize(name:, slack_id:, real_name:, status_text:, status_emoji:) | ||
| super(name: name, slack_id: slack_id) | ||
| @real_name = real_name | ||
| @status_text = status_text | ||
| @status_emoji = status_emoji | ||
| end | ||
|
|
||
| def details | ||
| #prints info for currently selected user, if not, should let user know and return to main command prompt | ||
| detailed_info = "Slack_id: #{@slack_id}, Name: #{@name}" | ||
| return detailed_info | ||
| end | ||
|
|
||
| def self.list_all | ||
| users = [] | ||
| # get method defined in recipient.rb | ||
| response = get(USER_LIST, {token: ENV['SLACK_TOKEN']}) | ||
| response["members"].each do |user| | ||
| new_user = new( | ||
| name: user["name"], | ||
| slack_id: user["id"], | ||
| real_name: user["profile"]["real_name"], | ||
| status_text: user["profile"]["status_text"], | ||
| status_emoji: user["profile"]["status_emoji"] | ||
| ) | ||
| users << new_user | ||
| end | ||
| return users | ||
| end | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| require_relative 'channel' | ||
| require_relative 'user' | ||
|
|
||
|
|
||
| class Workspace | ||
|
|
||
| attr_reader :users, :channels | ||
| attr_accessor :selected | ||
|
|
||
| def initialize | ||
| @users = User.list_all | ||
| @channels = Channel.list_all | ||
| @selected = nil | ||
| end | ||
|
|
||
| def select_channel(id) | ||
| requested_channel = @channels.find do |channel| | ||
| channel.slack_id == id || channel.name == id | ||
| end | ||
| @selected = requested_channel | ||
| return @selected | ||
| end | ||
|
|
||
|
|
||
| def select_user(id) | ||
| user = @users.find do |user| | ||
| user.slack_id == id || user.name == id | ||
| end | ||
| @selected = user | ||
| puts "#{id} not exist" if @selected.nil? | ||
| return @selected | ||
| end | ||
|
|
||
|
|
||
| def show_details | ||
| if @selected.nil? | ||
| puts "Nothing selected, pick a user or channel first." | ||
| else | ||
| return @selected.details | ||
| end | ||
| end | ||
|
|
||
| def send_message(message) | ||
| if @selected.nil? | ||
| puts "No recipient selected" | ||
| else | ||
| begin | ||
| return @selected.send_message(message) | ||
| rescue SlackAPIError => exception | ||
| puts "error: #{exception}" | ||
| end | ||
|
|
||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
uh oh!
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.
When something like this happens, it's good to make sure it also gets deleted from the workspace. :)