Class: Tumblr::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/tumblr/credentials.rb

Constant Summary collapse

FILE_NAME =
".tumblr"

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(path) : File.join(File.expand_path("~"), FILE_NAME)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/tumblr/credentials.rb', line 7

def path
  @path
end

Instance Method Details

#readObject



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