Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b63e0a5
tested
stupendousC Sep 10, 2019
31db231
Halfway thru reading API response methods
stupendousC Sep 10, 2019
8a389c4
success w/ httparty.get, tested
stupendousC Sep 10, 2019
d1fb25b
able to initialize @all_users in new Workspace obj, tested
stupendousC Sep 10, 2019
31c79ea
nothing really changed
stupendousC Sep 10, 2019
0f610dd
testing making new workspae & @all_channels, :-|
stupendousC Sep 10, 2019
d2cd820
Done with User.new() and reading from API. Testing ok
stupendousC Sep 10, 2019
8aa2913
halfway done w/ initialization...
stupendousC Sep 11, 2019
da75190
all files up
stupendousC Sep 11, 2019
832b730
User.load_users and all existing code tested w/ 100% coverage
stupendousC Sep 11, 2019
ffabc94
everything works EXCEPT .get_ids and therefore .load_all. work in pr…
stupendousC Sep 11, 2019
43485bc
Channel.load tested w/ 100% coverage
stupendousC Sep 11, 2019
50a1cf5
can add User and Channel instances from API, tested w/ 100% coverage
stupendousC Sep 11, 2019
a716232
show_meu in progress
stupendousC Sep 12, 2019
f3e9a2a
Added menu option functionality
stupendousC Sep 12, 2019
c10d5c2
refactored menu options
stupendousC Sep 12, 2019
7b0020d
passed w/ 100% coverage
stupendousC Sep 12, 2019
6a2941d
fixed bugs, tested w/ 100% coverage
stupendousC Sep 12, 2019
f8e746b
fixed bugs with 100% test coverage
stupendousC Sep 12, 2019
87ec16b
formatting, cleaned up
stupendousC Sep 12, 2019
27aeaf5
Working on testing the codes, currently 66% coverage
stupendousC Sep 12, 2019
4cd392e
user interface works so far. will add send_msg function later
stupendousC Sep 12, 2019
7256b19
cleaned up formatting. Everything tested 100% coverage except for wor…
stupendousC Sep 13, 2019
4986838
changed workspace.show_menu name to workspace.menu_choices_hash, for …
stupendousC Sep 13, 2019
a783fd3
fixed typo, fat fingers
stupendousC Sep 13, 2019
8f0daf3
deleted print statements
stupendousC Sep 13, 2019
5e3d391
Will raise SlackAPIError when appropriate. Tested w/ 100% coverage
stupendousC Sep 13, 2019
07c5b0c
added send_message, tested
stupendousC Sep 13, 2019
475c093
halfway thru menu_action testing
stupendousC Sep 13, 2019
724f0cc
almost one w/ testing menu_action. ~80% coverage
stupendousC Sep 13, 2019
88e0489
Everything tested w/ 100% coverage, yay
stupendousC Sep 13, 2019
7ec0f06
fixed all typos. everything tested at 100% coverage, yay
stupendousC Sep 13, 2019
c9765da
Delete WT2.yml
stupendousC Sep 13, 2019
3b51ad3
Delete WT3.yml
stupendousC Sep 14, 2019
ebaf37d
Delete WT4.yml
stupendousC Sep 14, 2019
0919a0e
Delete WT_BOGUS_KEY.yml
stupendousC Sep 14, 2019
29fa31b
Add files via upload
stupendousC Sep 14, 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
2 changes: 1 addition & 1 deletion .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
Binary file added lib/IMG_9240 copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require_relative 'lib_helper.rb'
require_relative 'recipient'

class Channel < Recipient
attr_reader :topic, :member_count

def initialize(id:, name:, topic:, member_count:)
super(id: id, name: name)
@topic = topic
@member_count = member_count
end

def details
return {id: id, name: name, topic: topic , member_count: member_count}
end


def self.get
url = "https://slack.com/api/conversations.list"
params = { token: KEY }
response = super(url, params)
# sleep(0.25)
return response
end

def self.get_ids
response = (self.get)["channels"]
all_channel_ids = response.map do |channel_info|
channel_info["id"]
end
return all_channel_ids
end

def self.get_names
response = (self.get)["channels"]
all_channel_names = response.map do |channel_info|
channel_info["name"]
end
return all_channel_names
end

def self.get_topics
response = (self.get)["channels"]
all_topics = response.map do |channel_info|
channel_info["topic"]["value"]
end
return all_topics
end

def self.get_member_counts
response = (self.get)["channels"]
member_counts = response.map do |channel_info|
channel_info["num_members"]
end
return member_counts
end

def self.load_all
names = self.get_names

Choose a reason for hiding this comment

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

The way these methods are seperated is a little awkward and inefficient because the same api ends up getting called 4 times when all of that information is available in the response from each call.

Choose a reason for hiding this comment

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

I understand the tradeoff though because it enables smaller, succinct methods, one for each attribute. You could accomplish both of these things by pulling the call to self.get out of these methods. If self.get were called directing from self.load_all, the results from self.get could be passed to each method like so:
result = self.get
self.get_names(result)
...

ids = self.get_ids
member_counts = self.get_member_counts
topics = self.get_topics
all_channels = []

ids.length.times do |index|
new_channel = Channel.new(name: names[index], id: ids[index], member_count:member_counts[index], topic:topics[index])
all_channels << new_channel
end

return all_channels
end

end
10 changes: 10 additions & 0 deletions lib/lib_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'httparty'
require 'awesome_print'
require 'dotenv'
require 'terminal-table'


Dotenv.load


KEY = ENV["SLACK_KEY"]
30 changes: 30 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative 'lib_helper.rb'

class Recipient

attr_reader :id, :name

def initialize(id:, name:)
@id = id
@name = name
end

def self.get(url, params)
response = HTTParty.get(url, query: params)

if response["ok"] == true
return response
else
raise SlackAPIError, "API request failed!"
end
end

def details
raise NotImplementedError, "Do this either User or Channel"
end

def self.load_all
raise NotImplementedError, "Do this either User or Channel"
end

end
39 changes: 35 additions & 4 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
#!/usr/bin/env ruby
require 'awesome_print'
require 'httparty'
require 'dotenv'
Dotenv.load

def main
puts "Welcome to the Ada Slack CLI!"
require_relative 'lib_helper.rb'
require_relative 'recipient.rb'
require_relative 'user.rb'
require_relative 'channel.rb'
require_relative 'slackapierror.rb'
require_relative 'workspace.rb'

# TODO project

puts "Thank you for using the Ada Slack CLI"
def main
puts "\nWelcome to the Ada Slack CLI!\n\n"
ws1 = Workspace.new

choices_hash = ws1.menu_choices_hash
main_menu = ws1.main_menu(headings: ["", "MAIN MENU"], rows_as_hash: choices_hash)

quit_program = false
while quit_program == false
puts
puts main_menu
print "Please select from main menu: "
choice = gets.chomp()

result = ws1.menu_action(choice)

if result
if (result.class == User) || (result.class == Channel)
ws1.entity = result
end
end

puts "Press any key to get back to menu"
gets
end
end

main if __FILE__ == $PROGRAM_NAME
47 changes: 47 additions & 0 deletions lib/slack_playing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby
require 'awesome_print'
require 'httparty'
require 'dotenv'
Dotenv.load
# will raise error if key not found
Dotenv.require_keys("SLACK_KEY")
puts ENV["SLACK_KEY"]

# THESE ARE THE 3 THINGS WE'RE ALLOWED TO DO ON THIS API
# chat:write:bot
# channels:read
# users:read

def main
puts "\nWelcome to the Ada Slack CLI!\n\n"

url = "https://slack.com/api/channels.list"
query_params = { token: ENV["SLACK_KEY"] }
response = HTTParty.get(url, query: query_params)
ap response
puts
url = "https://slack.com/api/users.list"
query_params = { token: ENV["SLACK_KEY"] }
response = HTTParty.get(url, query: query_params)
ap response
puts
# url = "https://slack.com/api/chat.postMessage"
# query_params = { token: ENV["SLACK_KEY"], channel: "CN5R2SQ8L", text: "CHECK THIS OUT!!!"}
# response = HTTParty.get(url, query: query_params)
# # ap response
# puts


url = "https://slack.com/api/chat.postEphemeral"
query_params = { token: ENV["SLACK_KEY"], channel: "CN5R2SQ8L", text: "HI!!", user: "UN69JD3V3"}
response = HTTParty.get(url, query: query_params)
ap response
puts




puts "\nThank you for using the Ada Slack CLI\n\n"
end

main if __FILE__ == $PROGRAM_NAME
4 changes: 4 additions & 0 deletions lib/slackapierror.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require_relative 'lib_helper.rb'

class SlackAPIError < StandardError
end
63 changes: 63 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require_relative 'lib_helper.rb'
require_relative 'recipient'

class User < Recipient
attr_reader :real_name

def initialize(id:, name:, real_name:)
super(id: id, name: name)
@real_name = real_name
end

def details
return {id: id, name: name, real_name: real_name}
end

def self.get
url = "https://slack.com/api/users.list"
params = { token: KEY }
response = super(url, params)
# sleep(0.25)
return response
end

def self.get_real_names
response = (self.get)["members"]
all_real_names = response.map do |member_info|
member_info["real_name"]
end
return all_real_names
end

def self.get_names
response = (self.get)["members"]
all_names = response.map do |member_info|
member_info["name"]
end
return all_names
end

def self.get_ids
response = (self.get)["members"]
all_ids = response.map do |member_info|
member_info["id"]
end
return all_ids
end

def self.load_all
real_names = self.get_real_names
names = self.get_names
ids = self.get_ids
all_users = []

ids.length.times do |index|
new_user = User.new(id: ids[index], name: names[index], real_name: real_names[index])
all_users << new_user
end

return all_users
end


end
Loading