class Slackdo::Config

Public Instance Methods

add_category() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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