class Fourteeninch::Auth

Public Class Methods

auth(re_auth = false) click to toggle source
# File lib/fourteeninch/auth.rb, line 4
def self.auth(re_auth = false)
  Fourteeninch.load_settings if !re_auth

  if re_auth || !(Fourteeninch.api_key && Fourteeninch.api_secret)
    print 'Enter your fourteeninch e-mail: '
    email = $stdin.gets.chomp

    print 'Enter your fourteeninch password: '
    system 'stty -echo'
    password = $stdin.gets.chomp
    system 'stty echo'

    puts "\nAuthorizing..."

    if (auth = Fourteeninch::Client.auth(email, password)) && (auth.is_a?(Hash)) && (auth.has_key?('api_key')) && (auth.has_key?('api_secret'))
      File.open(Fourteeninch.settings_file,'w') do|file|
        Marshal.dump({:api_key => auth['api_key'], :api_secret => auth['api_secret']}, file)
      end
      puts "=> You have been authorized. Make sure you log out after finished" if re_auth
      return true
    else
      puts auth['error'] || "Could not authorize, check your e-mail or password."
      return false
    end
  else
    return true
  end
end
logout() click to toggle source
# File lib/fourteeninch/auth.rb, line 34
def self.logout
  File.delete(Fourteeninch.settings_file) if File.exist?(Fourteeninch.settings_file)
  puts ""
  puts "You have been logged out."
end