Sha256: 6b67c8a71ddba52869a4fefdf09c6e5387a254696bd8bc848c483ff52aa60cdc
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
class MemeGenerator class Campfire CONFIG_PATH = File.join(File.expand_path("~/.memegen"), ".campfire") class << self def config return unless File.exists?(CONFIG_PATH) @config ||= read_config end def prompt_config puts "Set your Campfire credentials..." print "Subdomain : " subdomain = gets.strip print "Token : " token = gets.strip print "Room : " room = gets.strip write_config([subdomain, token, room]) puts "Config saved successfully!" end def upload(path) require 'tinder' require 'open-uri' puts "Uploading... " silence_stream(STDERR) do campfire = Tinder::Campfire.new config[:subdomain], :token => config[:token] room = campfire.rooms.detect { |room| room.name == config[:room] } room.upload(path) end end private def silence_stream(stream) old_stream = stream.dup stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) end # Lame format is to keep dependencies at a minimum def read_config data = File.read(CONFIG_PATH) values = data.split("|") { :subdomain => values[0], :token => values[1], :room => values[2] } end def write_config(config) File.open(CONFIG_PATH, "w") do |file| file.write(config.join("|")) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
memegen-1.0.0 | lib/meme_generator/campfire.rb |
memegen-0.0.10 | lib/meme_generator/campfire.rb |
memegen-0.0.9 | lib/meme_generator/campfire.rb |