-
Notifications
You must be signed in to change notification settings - Fork 26
Branches - Farah && Steph #11
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
07fa5f1
50dd9ac
ff25ea4
33ee029
b91c159
eb1d375
49fa7e9
8fa86da
21f5bfa
fc314b6
4a56f31
dccd549
dd51b5c
9bac8ab
149b664
7b9089a
2cc91bf
a32b69a
2a5d88b
9069a39
4ff86ed
06908fe
ed6d503
5d45c48
08181a4
466523c
74ef32f
66f643d
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,57 @@ | ||
| .env | ||
| *.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/ | ||
| 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 | ||
|
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. Do @topic or @member_count get used? Could we delete these? |
||
| @@channels_list << self | ||
|
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 think that it's very clever to use the class variable |
||
| end | ||
|
|
||
| def self.list | ||
|
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. 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 | ||
| 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 |
| 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| | ||
|
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. Nitpick: the syntax for this line means that every element in |
||
| puts"#{index+1}.#{channel}" | ||
| } | ||
|
|
||
| user_answer = gets.chomp.to_i | ||
|
|
||
| while user_answer != 5 | ||
| if user_answer == 1 | ||
| Channel.printed_channels_list | ||
|
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. Forgot to |
||
|
|
||
| # 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| | ||
|
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. Nitpick: same as above; instead of |
||
| puts "#{index+1}.#{channel}" | ||
| } | ||
| user_answer = gets.chomp.to_i | ||
| end | ||
| puts "Thank you for using the Ada Slack CLI" | ||
| end | ||
|
|
||
|
|
||
| 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 |
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.
we actually don't need a
.gitignorefile in thelibfolder... just one in the project root directory!