Module: Twido::Authentication

Defined in:
lib/twido/authentication.rb

Constant Summary

USER_CONFIG_PATH =
File.expand_path('~/.twido.conf')

Class Method Summary (collapse)

Class Method Details

+ (Object) authenticate

Creates a new Twitter::Client with the users credentials Returns a Twitter::Client Examples



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/twido/authentication.rb', line 48

def self.authenticate   
  if self.config_exists?
    if twitter_client = Twitter::Client.new(self.load_credentials())
      twitter_client
    else
      abort 'ERROR: Error authenticating your account, run setup to reconfigure'
    end
  else
    abort 'ERROR: You have not setup twido yet, run twido setup to configure it.'
  end
end

+ (Object) complete_task(tweet)

makes a task done by deleting the tweet it came from Returns nil Examples



66
67
68
# File 'lib/twido/authentication.rb', line 66

def self.complete_task(tweet)
  Twitter::Client.new.status_destroy(id)
end

+ (Boolean) config_exists?

Checks to see if the config file exists on the user's home folder. Returns true or false Examples

Returns:

  • (Boolean)


14
15
16
# File 'lib/twido/authentication.rb', line 14

def self.config_exists?
  File.exist?(USER_CONFIG_PATH)
end

+ (Object) load_credentials

Loads the user's twitter credentials from the config file on the user's home folder. Returns a hash filled with the credentials. Examples



37
38
39
# File 'lib/twido/authentication.rb', line 37

def self.load_credentials()
  hash = YAML.load_file(USER_CONFIG_PATH)
end

+ (Object) write_credentials_to_config(credentials)

Writes the user's twitter login credentials to the config file on the user's home folder. Returns nil credentials - The user's twitter log in credentials. Examples



26
27
28
# File 'lib/twido/authentication.rb', line 26

def self.write_credentials_to_config(credentials)
  File.open(USER_CONFIG_PATH, 'w') { |file| file.puts(credentials.to_yaml) }
end