Class: Tumblr::Credentials
- Inherits:
-
Object
- Object
- Tumblr::Credentials
- Defined in:
- lib/tumblr/credentials.rb
Constant Summary collapse
- FILE_NAME =
".tumblr"
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #read ⇒ Object
- #write(consumer_key, consumer_secret, token, token_secret) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Credentials
Returns a new instance of Credentials.
9 10 11 |
# File 'lib/tumblr/credentials.rb', line 9 def initialize(path = nil) @path = !path.nil? ? File.(path) : File.join(File.("~"), FILE_NAME) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/tumblr/credentials.rb', line 7 def path @path end |
Instance Method Details
#read ⇒ Object
24 25 26 27 28 |
# File 'lib/tumblr/credentials.rb', line 24 def read YAML.load_file path rescue Errno::ENOENT {} end |
#write(consumer_key, consumer_secret, token, token_secret) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tumblr/credentials.rb', line 13 def write(consumer_key, consumer_secret, token, token_secret) File.open(path, "w") do |io| YAML.dump({ "consumer_key" => consumer_key, "consumer_secret" => consumer_secret, "token" => token, "token_secret" => token_secret }, io) end end |