Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
000249e
initial commit after initial files made
CEsGutierrez Sep 10, 2019
8280120
updated .gitignore
criacuervos Sep 10, 2019
18146ee
updated
criacuervos Sep 10, 2019
d824bfd
completed set up, pseudocode for recipient tests
criacuervos Sep 10, 2019
07a6309
wrote tests to verify that instances of user are able to recognize th…
criacuervos Sep 11, 2019
5fbcf86
added tests to user_test to verify inputs used to initialize
CEsGutierrez Sep 11, 2019
71a3b7b
created user initialization method
criacuervos Sep 11, 2019
c02c7f7
created user initialization method
criacuervos Sep 11, 2019
ce67b02
started workspace functionality, able to initiate an API call to Slac…
CEsGutierrez Sep 11, 2019
1fc0072
Delete cassettes.yml
CEsGutierrez Sep 11, 2019
39a2996
changed git ignore file to exclude cassettes
CEsGutierrez Sep 12, 2019
1f83718
tests for initial channel functionality
CEsGutierrez Sep 12, 2019
b359309
Merge branch 'master' of https://github.com/CEsGutierrez/slack-cli
CEsGutierrez Sep 12, 2019
78186fd
updated test_helper to hide token from cassette
criacuervos Sep 12, 2019
789e477
started workspace functionality, able to initiate an API call to Slac…
CEsGutierrez Sep 12, 2019
3d1df63
changed git ignore file to exclude cassettes
CEsGutierrez Sep 12, 2019
cb271db
tests for initial channel functionality
CEsGutierrez Sep 12, 2019
d63d557
Delete cassettes.yml
CEsGutierrez Sep 11, 2019
405410e
updated test_helper to hide token from cassette
criacuervos Sep 12, 2019
a0f18fe
updated test helper and started channel initialization method
criacuervos Sep 12, 2019
78041d3
merge conflict fixed
criacuervos Sep 12, 2019
bf0662d
fixing channel tests
criacuervos Sep 12, 2019
d046633
finished channel initialization tests
criacuervos Sep 12, 2019
4bc80d9
working on parsing API information
CEsGutierrez Sep 12, 2019
a7a1924
used API to make instances of User. Adjusted test and code in channel…
CEsGutierrez Sep 12, 2019
802e347
added API calls, parsing and initiation of instances of User and Chan…
CEsGutierrez Sep 12, 2019
ff07dd1
changes to workspace test
criacuervos Sep 12, 2019
b391fef
changes to workspace test
criacuervos Sep 12, 2019
af96605
temporary changes to workspace_test
CEsGutierrez Sep 12, 2019
f89e828
merge conflict resolution
CEsGutierrez Sep 12, 2019
8875a10
slack ui wave 1 functionality completed
criacuervos Sep 13, 2019
4bfcf5c
pulling now
criacuervos Sep 13, 2019
5974864
pseudocode for wave2
criacuervos Sep 13, 2019
ac2300c
working on details part of wave 2
criacuervos Sep 13, 2019
a029785
finished wave 2 and error free cli
criacuervos Sep 13, 2019
bc97050
dont with wave 3 wahoo
criacuervos Sep 14, 2019
dd800da
Refactor after adding tests to cover all functionality
CEsGutierrez Sep 14, 2019
83236b4
refactor to use inheritance of Recipient class for User and Channel
CEsGutierrez Sep 14, 2019
66578af
Added cassettes to submission
CEsGutierrez Sep 15, 2019
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
Binary file added .DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/tmp/

# Used by dotenv library to load environment variables.
# .env
.env

## Specific to RubyMotion:
.dat*
Expand Down Expand Up @@ -53,4 +53,8 @@ build-iPhoneSimulator/
.env

# Ignore cassette files
/specs/cassettes/
# /specs/cassettes/
# /test/cassettes/

# Ignore my set-up test
/lib/set_up/
29 changes: 29 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative 'recipient'

class Channel < Recipient

attr_reader :topic, :member_count

def initialize(name:, slack_id:, topic:, member_count:)
super(name: name, slack_id: slack_id)

if topic.class != String
raise ArgumentError.new, "Wrong format for topic!"
end
@topic = topic

if member_count.class != Integer
raise ArgumentError.new, "Wrong format for member count!"
end
@member_count = member_count
end

def details
return "\n
Name: #{@name}
Topic: #{@topic}
Slack id: #{@slack_id}
Member count: #{@member_count}"
end

end
24 changes: 24 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Recipient

attr_reader :name, :slack_id

def initialize(name:, slack_id:)

if name.class != String
raise ArgumentError.new, "wrong format for initiating name"
end
@name = name

if slack_id.class != String
raise ArgumentError.new, "wrong format for initiating id"
end
@slack_id = slack_id

end


def details
raise NotImplementedError.new "not implemented in recipient class"
end

end
25 changes: 25 additions & 0 deletions lib/set_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# To get this to work properly, running it in ruby (ruby.set_up.rb) you must be in the general project folder NOT lib. Run it from the project folder. This is a specificity problem because the .env file doesn't live in Lib so ruby can't find it from here.

# Run this in ruby as (ruby lib/set_up.rb)

require 'httparty'
require 'pry'

require 'dotenv'
Dotenv.load

def set_up_test

url = "https://slack.com/api/conversations.list"

query_params = {
token: ENV["SLACK_TOKEN"]
}

response = HTTParty.get(url, query: query_params)

return response

end

puts set_up_test
157 changes: 155 additions & 2 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,164 @@
#!/usr/bin/env ruby
require_relative 'workspace'
require 'pry'

def main
puts "Welcome to the Ada Slack CLI!"

# Initializes a new workspace
workspace = Workspace.new

#Ternary statement to add 's' for more than 1 user
puts "There are #{workspace.users.length} user(s) in your workplace."

puts "There are #{workspace.channels.length} channel(s) in your workspace."

main_menu(workspace)

puts "Thank you for using the Ada Slack CLI"
end

# TODO project
def main_menu(workspace)

loop_options = ["1. List users", "2. List channels", "3. Quit"]
puts "\nPlease select from one of the following options by choosing its corresponding number: "
loop_options.each do |option|
puts "\t #{option}"
end

input = gets.chomp.downcase
eval = nil
until eval == "exit"
case input
when "1"
puts
puts "Here is a list of all users: "
all_users_details = []
workspace.users.each do |user|
all_users_details << user.details
end
puts all_users_details
selected_user = make_a_selection(workspace)
if selected_user == nil
eval = nil
break
else
selected_info = display_selected(workspace, selected_user)
if selected_info == nil
break
else puts selected_info
end
input = nil
end
when "2"
puts
puts "Here is a list of all channels: "
all_channel_details = []
workspace.channels.each do |channel|
all_channel_details << channel.details
end
puts all_channel_details
selected_channel = make_a_selection(workspace)
if selected_channel == nil
eval = nil
break
else
selected_info = display_selected(workspace, selected_channel)
if selected_info == nil
break
else puts selected_info
end
input = nil
end
when "3"
eval = "exit"
when "quit"
eval = "exit"
else
puts "\nPlease select from one of the following options by choosing its corresponding number: "
loop_options.each do |option|
puts "\t #{option}"
end
eval = nil
input = gets.chomp.downcase
end

end

end

puts "Thank you for using the Ada Slack CLI"
def make_a_selection(workspace)
print "\n You will be able to see details or send a message soon! Please select a user or channel by entering their corresponding name or Slack ID. If you'd like to exit, you may type \'QUIT\' to quit the program.: "
second_input = gets.chomp.downcase

if second_input == "quit"
return nil
end

selected = nil

if workspace.all_user_names.include?(second_input) || workspace.all_user_slack_ids.include?(second_input)
puts "You selected the following user: #{second_input}.\n "
workspace.users.each do |possible_user|
if possible_user.name == second_input || possible_user.slack_id == second_input
selected = possible_user
end
end
return_statement = [selected, "user"]
return return_statement

elsif workspace.all_channel_names.include?(second_input) || workspace.all_channel_slack_ids.include?(second_input)
puts "You selected the following channel: #{second_input}. \n"
workspace.channels.each do |possible_channel|
if possible_channel.name == second_input || possible_channel.slack_id == second_input
selected = possible_channel
end
end
return_statement = [selected, "channel"]
return return_statement
else
puts "You did not enter a valid user. We're going to quit."
return nil
end
end

def display_selected(workspace, selection)
puts "\n What would you like to know?
\t * Details
\t * Send message
\t * Quit"

third_input = gets.chomp.downcase
if third_input == "quit"
return nil
end

selection_text = selection[0]

if third_input == "details"
if selection[1] == "user"
return selection_text.details
elsif selection[1] == "channel"
return selection_text.details
end
elsif third_input == "send message"
success_of_messaging = sending_message(workspace, selection)
if success_of_messaging == true
puts "You successfully sent your message. Great"
else
puts "Your message did not send. Sorry."
end
end
end

def sending_message(workspace, selection)
puts "What message do you want to send to #{selection[0].name}? \n Type it here: "
message = gets.chomp

success_of_sending = workspace.api_message_send(message, selection[0])
return success_of_sending

end


main if __FILE__ == $PROGRAM_NAME
48 changes: 48 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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)

if real_name.class != String
raise ArgumentError.new, "Wrong format for real name initialization"
else
@real_name = real_name
end


if status_text.class != String
raise ArgumentError.new, "Wrong format for status initialization"
else
@status_text = status_text
end

if status_emoji.class != String
raise ArgumentError.new, "Wrong format for emoji input"
elsif status_emoji.length == 0
@status_emoji = status_emoji
elsif
status_emoji[0] != ":" || status_emoji[-1] != ":"
raise ArgumentError.new, "Wrong format for emoji input"
else
@status_emoji = status_emoji
end



end

def details
return "
Name: #{@name}
Slack id: #{@slack_id}
Status text: #{@status_text}
Status emoji: #{@status_emoji}
Real name: #{@real_name}
"
end

end
Loading