Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
07fa5f1
Copied ENV file to lib: Authenticated Token Works
Steph0088 Sep 10, 2019
50dd9ac
Created Recipient Class and test constructor
Steph0088 Sep 10, 2019
ff25ea4
added new user method list
Steph0088 Sep 10, 2019
33ee029
created list method and passed test
in-formation Sep 10, 2019
b91c159
added self.list method for User and passed nominal test
in-formation Sep 10, 2019
eb1d375
Added tests for Channel and List method
Steph0088 Sep 10, 2019
49fa7e9
Resolve merge conflict
Steph0088 Sep 10, 2019
8fa86da
Formatted tabs
in-formation Sep 10, 2019
21f5bfa
Attempted adding API component to user.list method
Steph0088 Sep 11, 2019
fc314b6
Fixed indentation/do&end issues
in-formation Sep 11, 2019
4a56f31
resolved conflict
Steph0088 Sep 11, 2019
dccd549
Resolved more merge conflicts
Steph0088 Sep 11, 2019
dd51b5c
deleted cassettes and added filter sensitive data for token
in-formation Sep 11, 2019
9bac8ab
Fixed list channel method and tests
Steph0088 Sep 12, 2019
149b664
Completed tests for users and channel class
Steph0088 Sep 12, 2019
7b9089a
Created while loop for slack.rb
in-formation Sep 12, 2019
2cc91bf
Created Channels list and Users list
Steph0088 Sep 12, 2019
a32b69a
Finished Wave 1
Steph0088 Sep 12, 2019
2a5d88b
pseudocode
Steph0088 Sep 12, 2019
9069a39
Added psuedocode for wave 2
in-formation Sep 12, 2019
4ff86ed
started writing code for wave 2, token issues
in-formation Sep 12, 2019
06908fe
Completed user details method
Steph0088 Sep 12, 2019
ed6d503
Added select channel details method
Steph0088 Sep 12, 2019
5d45c48
Cleaned up
Steph0088 Sep 13, 2019
08181a4
Started writing tests for user
in-formation Sep 13, 2019
466523c
Created more tests for User class
in-formation Sep 13, 2019
74ef32f
Fixed user class and created more tests
Steph0088 Sep 13, 2019
66f643d
Added tests for channel class
Steph0088 Sep 13, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
*.gem
*.rbc
/.config
Expand Down Expand Up @@ -53,4 +54,4 @@ build-iPhoneSimulator/
.env

# Ignore cassette files
/specs/cassettes/
/test/cassettes/
57 changes: 57 additions & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.env
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually don't need a .gitignore file in the lib folder... just one in the project root directory!

*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

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

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# Ignore environemnt variables
.env

# Ignore cassette files
/specs/cassettes/
49 changes: 49 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'httparty'
require 'dotenv'
Dotenv.load
require 'pry'
require_relative 'recipient'
require 'table_print'

class Channel < Recipient
attr_reader :slack_id, :name, :topic, :member_count
@@channels_list = []
BASE_URL = "https://slack.com/api/channels.list"
API_KEY = ENV['SLACK_API_TOKEN']

def initialize(slack_id, name, topic, member_count)
super(slack_id, name)
@topic = topic
@member_count = member_count
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do @topic or @member_count get used? Could we delete these?

@@channels_list << self
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's very clever to use the class variable @@channels_list and to shovel in self! However, does this variable ever get used beyond this? Do we need it?

end

def self.list
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice helper method!

query = {
token: API_KEY
}
response = HTTParty.get(BASE_URL, query: query)

return response
end

def self.printed_channels_list
channels_array = []

self.list["channels"].each do |channel|
channels_array << {"name" => channel["name"],"topic" => channel["purpose"]["value"], "Member Count"=> channel["num_members"], "Slack ID"=> channel["id"]}
end

return channels_array
end

def self.select_channel_details(desired_channel)
self.printed_channels_list.each do |channel|
if channel["name"] == desired_channel || channel["Slack ID"] == desired_channel
return channel
end
end
statement = "Not a valid Channel name/Slack ID"
return statement
end
end
14 changes: 14 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Recipient
attr_reader :slack_id, :name
class SlackApiError < Exception
end

def initialize(slack_id, name)
@slack_id = slack_id
@name = name
end

def self.list
raise NotImplementedError, "Implement me in a child class!"
end
end
42 changes: 40 additions & 2 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
#!/usr/bin/env ruby
require "httparty"
require_relative "channel"
require_relative "user"
require "dotenv"
Dotenv.load
require 'table_print'
require 'pry'

def main
puts "Welcome to the Ada Slack CLI!"
puts"Welcome to the Ada Slack CLI!"
puts"Select an option by number:"
options_array=["List Channels","List Users","Select User","Select Channel","Quit"]
options_array.each_with_index{ |channel, index|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: the syntax for this line means that every element in options_array when we iterate through it will be named channel... but options_array doesn't contain channels, it contains options! Would it make sense if this variable were named option instead of channel?

puts"#{index+1}.#{channel}"
}

user_answer = gets.chomp.to_i

while user_answer != 5
if user_answer == 1
Channel.printed_channels_list
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to puts this!


# TODO project
elsif user_answer == 2
puts User.printed_users_list

elsif user_answer == 3
puts User.printed_users_list
puts "Please enter a username or Slack ID:"
desired_person = gets.chomp
puts User.select_user_details(desired_person)

elsif user_answer == 4
Channel.printed_channels_list
puts "Please enter a channel name or Slack ID"
desired_channel = gets.chomp
puts Channel.select_channel_details(desired_channel)
end

puts "Select an option by number:"
options_array.each_with_index { |channel,index|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: same as above; instead of channel, is there a better variable name?

puts "#{index+1}.#{channel}"
}
user_answer = gets.chomp.to_i
end
puts "Thank you for using the Ada Slack CLI"
end

Expand Down
44 changes: 44 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'httparty'
require 'dotenv'
Dotenv.load
require 'pry'
require 'table_print'
class User < Recipient
attr_reader :slack_id, :name, :real_name
@@users_list = []
BASE_URL = "https://slack.com/api/users.list"
API_KEY = ENV['SLACK_API_TOKEN']

def initialize(slack_id, name, real_name)
super(slack_id, name)
@real_name = real_name
@@users_list << self
end

def self.list
query = {
token: API_KEY
}
response = HTTParty.get(BASE_URL, query: query)
return response
end

def self.printed_users_list
users_array = []
self.list["members"].each do |member|
users_array << {"User Name" => member["name"],"Real Name" => member["real_name"],"Slack ID"=> member["id"]}
end
return users_array
end

def self.select_user_details(desired_person)
self.printed_users_list.each do |user_hash|
if user_hash["User Name"] == desired_person || user_hash["Slack ID"] == desired_person
return user_hash
end
end

statement = "Not a valid Username/Slack ID"
return statement
end
end
Empty file added lib/workspace.rb
Empty file.
Loading