Sha256: a73e105260667853a026552480b0927d41442599bc995d1fb1d58780e92335ce

Contents?: true

Size: 642 Bytes

Versions: 4

Compression:

Stored size: 642 Bytes

Contents

require "yaml"

module Tumblr
  class Credentials
    FILE_NAME = ".tumblr"

    attr_reader :path

    def initialize(path = nil)
      @path = !path.nil? ? File.expand_path(path) : File.join(File.expand_path("~"), FILE_NAME)
    end

    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

    def read
      YAML.load_file path
    rescue Errno::ENOENT
      {}
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tumblr-rb-2.1.1 lib/tumblr/credentials.rb
tumblr-rb-2.1.0 lib/tumblr/credentials.rb
tumblr-rb-2.0.0 lib/tumblr/credentials.rb
tumblr-rb-2.0.0.alpha lib/tumblr/credentials.rb