Class: Slackdo::Config
- Inherits:
-
Object
- Object
- Slackdo::Config
- Defined in:
- lib/slackdo.rb
Instance Method Summary collapse
- #add_category ⇒ Object
- #add_label ⇒ Object
- #configure_init ⇒ Object
- #configure_slack_webhook ⇒ Object
- #configure_trello_api ⇒ Object
- #disable_trello ⇒ Object
- #enable_trello ⇒ Object
- #remove_category ⇒ Object
- #remove_label ⇒ Object
Instance Method Details
#add_category ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/slackdo.rb', line 29 def add_category file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) cat = $prompt.ask('What is the category you wish to add?') unless hash['categories'].include?(cat.upcase) hash['categories'].push(cat.upcase) File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts "Category '#{cat.upcase}' was added..." else puts "Category '#{cat.upcase}' already exists..." end end |
#add_label ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/slackdo.rb', line 53 def add_label file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) id = $prompt.ask('What is the ID of the label you wish to add?') hash['trello_label_ids'].push(id) File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts "Label with ID '#{id}' was added..." end |
#configure_init ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/slackdo.rb', line 11 def configure_init `mkdir #{ENV['HOME']}/.slackdo` unless File.exist?("#{ENV['HOME']}/.slackdo") unless File.exist?("#{ENV['HOME']}/.slackdo/config.json") system "touch #{ENV['HOME']}/.slackdo/config.json" hash = { "slack_webhook" => "", "allow_trello_pushing" => "false", "trello_public_key" => "", "trello_member_token" => "", "trello_list_id" => "", "trello_label_ids" => [], "categories" => ["GENERAL"] } File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end end end |
#configure_slack_webhook ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/slackdo.rb', line 117 def configure_slack_webhook file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) webhook = $prompt.ask('What is your Slack webhook?', default: hash['slack_webhook']) hash["slack_webhook"] = webhook File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts 'Slack API was configured...' end |
#configure_trello_api ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/slackdo.rb', line 102 def configure_trello_api file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) public_key = $prompt.ask('What is your Trello public key?', default: hash['trello_public_key']) member_token = $prompt.ask('What is your Trello member token?', default: hash['trello_member_token']) list_id = $prompt.ask('What is your Trello list ID where the cards should be created?', default: hash['trello_list_id']) hash["trello_public_key"] = public_key hash["trello_member_token"] = member_token hash["allow_trello_pushing"] = "true" hash["trello_list_id"] = list_id File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts 'Trello API was configured...' end |
#disable_trello ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/slackdo.rb', line 93 def disable_trello file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) hash["allow_trello_pushing"] = "false" File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts 'Trello has been disabled...' end |
#enable_trello ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/slackdo.rb', line 84 def enable_trello file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) hash["allow_trello_pushing"] = "true" File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts 'Trello has been enabled...' end |
#remove_category ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/slackdo.rb', line 43 def remove_category file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) cat = $prompt.select('What is the category you wish to remove?', hash['categories']) hash['categories'].delete(cat) File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts "Category '#{cat}' was removed..." end |
#remove_label ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/slackdo.rb', line 63 def remove_label Card.configure_trello file = File.read("#{ENV['HOME']}/.slackdo/config.json") hash = JSON.parse(file) label_names = [] hash['trello_label_ids'].each do |i| label_name = Trello::Label.find(i).name label_names.push(label_name) end label = $prompt.select('What is the label you wish to remove?', label_names) id = "" hash['trello_label_ids'].each do |i| label_name = Trello::Label.find(i).name id = i if label_name == label end hash['trello_label_ids'].delete(id) File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f| f.write(hash.to_json) end puts "Label '#{label}' was removed..." end |