Module: Twido::Authentication
- Defined in:
- lib/twido/authentication.rb
Constant Summary collapse
- USER_CONFIG_PATH =
File.('~/.twido.conf')
Class Method Summary collapse
-
.authenticate ⇒ Object
Public: Creates a new Twitter::Client with the users credentials Returns a Twitter::Client Examples.
-
.complete_task(tweet) ⇒ Object
Public: makes a task done by deleting the tweet it came from Returns nil Examples .
-
.config_exists? ⇒ Boolean
Public: Checks to see if the config file exists on the user’s home folder.
-
.load_credentials ⇒ Object
Public: Loads the user’s twitter credentials from the config file on the user’s home folder.
-
.write_credentials_to_config(credentials) ⇒ Object
Public: Writes the user’s twitter login credentials to the config file on the user’s home folder.
Class Method Details
.authenticate ⇒ Object
Public: Creates a new Twitter::Client with the users credentials Returns a Twitter::Client Examples
self.authenticate()
# => Twitter::Client
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/twido/authentication.rb', line 64 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 |
.complete_task(tweet) ⇒ Object
Public: makes a task done by deleting the tweet it came from Returns nil Examples
self.complete_task(tweet)
=> nil
82 83 84 |
# File 'lib/twido/authentication.rb', line 82 def self.complete_task(tweet) Twitter::Client.new.status_destroy(id) end |
.config_exists? ⇒ Boolean
Public: Checks to see if the config file exists on the user’s home folder. Returns true or false Examples
self.config_exists?
#=> true
self.config_exists?
#=> false
30 31 32 |
# File 'lib/twido/authentication.rb', line 30 def self.config_exists? File.exist?(USER_CONFIG_PATH) end |
.load_credentials ⇒ Object
Public: Loads the user’s twitter credentials from the config file on the user’s home folder. Returns a hash filled with the credentials. Examples
self.load_credentials()
# => {consumer_key:'23459878923'...}
53 54 55 |
# File 'lib/twido/authentication.rb', line 53 def self.load_credentials() hash = YAML.load_file(USER_CONFIG_PATH) end |
.write_credentials_to_config(credentials) ⇒ Object
Public: 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
credentials = {consumer_key:'23459878923'...}
self.write_credentials_to_config(credentials)
#=> nil
42 43 44 |
# File 'lib/twido/authentication.rb', line 42 def self.write_credentials_to_config(credentials) File.open(USER_CONFIG_PATH, 'w') { |file| file.puts(credentials.to_yaml) } end |