class Object
Constants
- LangDescr
- LangExtensions
Public Instance Methods
creatFileWrTr(filename, msg)
click to toggle source
# File lib/wputils.rb, line 75 def creatFileWrTr(filename, msg) hf = File.new(filename, File::CREAT|File::TRUNC|File::RDWR,0600) hf.write msg hf.close end
createAuthFile(url, authfile)
click to toggle source
# File lib/initcommand.rb, line 44 def createAuthFile(url, authfile) uriclass = URI.parse(url) perms = String.new if uriclass.scheme == "http" or uriclass.scheme == "https" then perms = Net::HTTP.get(URI.parse(url)) elsif uriclass.scheme == "file" then urlfile = File.open(uriclass.path, "r") perms = urlfile.read urlfile.close else urlfile = File.open(url, "r") perms = urlfile.read urlfile.close end # puts perms f = File.new(authfile, File::CREAT|File::TRUNC | File::WRONLY, 0600) f.write perms f.close end
createSubTreeDirectory(workDir, ovrwr, url)
click to toggle source
# File lib/initcommand.rb, line 4 def createSubTreeDirectory(workDir, ovrwr, url) workPath = ENV['HOME'] + '/' + workDir if Dir.exists? workPath then if ovrwr then eraseDirAll(workPath) else STDERR.puts "#{workPath} already exists" exit 1 end end Dir.mkdir workPath File.chmod(0700, workPath) Dir.mkdir workPath + '/config' File.chmod(0700, workPath + '/config') Dir.mkdir workPath + '/history' File.chmod(0700, workPath + '/history') createAuthFile(url, workPath + '/config/auth') end
endIfNil(value, msg)
click to toggle source
# File lib/wputils.rb, line 55 def endIfNil(value, msg) if value.nil? STDERR.puts msg exit 1 end end
eraseDirAll(dir)
click to toggle source
# File lib/initcommand.rb, line 25 def eraseDirAll(dir) if Dir.exists? dir then Dir.foreach(dir) do |filename| if not (filename == '.' or filename == '..') then pathname = dir + '/' + filename if File.file? pathname then File.delete pathname elsif File.directory? pathname then eraseDirAll pathname else puts "This never could happen #{pathname}" # Unknown file end end end Dir.delete(dir) end end
fetch_response(url, method= :get)
click to toggle source
# File lib/wputils.rb, line 16 def fetch_response(url, method= :get) conn = Faraday.new do |b| b.use FaradayMiddleware::FollowRedirects; b.adapter :net_http end return conn.send method, url rescue Faraday::Error, Faraday::Error::ConnectionFailed => e return nil end
getPScfgFile()
click to toggle source
# File lib/wputils.rb, line 31 def getPScfgFile() filepath=File.join(ENV['HOME'], '.powerslave', 'config', 'auth') YAML.load_file(filepath) end
getWPTag(options)
click to toggle source
# File lib/wputils.rb, line 45 def getWPTag(options) pTag="NOTAGDEF" if options[:tag] != nil pTag = options[:tag] elsif ENV["WPTAG"] != nil pTag = ENV["WPTAG"] end return ("#" + pTag) end
getWPcfgFile(file)
click to toggle source
# File lib/wputils.rb, line 26 def getWPcfgFile(file) filepath=file || File.join(ENV['HOME'], '.whiplash', 'config' ,'auth') YAML.load_file(filepath) end
get_tweeter_client(yamlconf)
click to toggle source
# File lib/wputils.rb, line 36 def get_tweeter_client(yamlconf) client = Twitter::REST::Client.new do |config| config.consumer_key = yamlconf['consumer_key'] config.consumer_secret = yamlconf['consumer_secret'] config.access_token = yamlconf['access_token'] config.access_token_secret = yamlconf['access_token_secret'] end end
printLevelMsg(levelMsg, currentLevel, msg)
click to toggle source
# File lib/wputils.rb, line 62 def printLevelMsg(levelMsg, currentLevel, msg) case currentLevel when 0 levelMsg = 0 when 1, levelMsg == currentLevel STDERR.puts msg when 2, levelMsg <= currentLevel STDERR.puts msg when 3, levelMsg <= currentLevel STDERR.puts msg end end
resolve_redirects(url)
click to toggle source
# File lib/wputils.rb, line 7 def resolve_redirects(url) response = fetch_response(url, method= :head) if response return response.to_hash[:url].to_s else return nil end end