Sha256: 02c3d2f68c234bd184f963cd5366d2514ef1ecebf83623dc5e9a2a824e6c6e7b

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 KB

Contents

module Flydata
  class Credentials
    include Helpers
    attr_reader :token
    def initialize
      read_credentials
    end
    def authenticate!
      @authenticated = true
    end
    def authenticated?
      @authenticated
    end
    def write_credentials(token)
      dir = File.dirname(credentials_file)
      FileUtils.mkdir_p(dir)
      File.delete(credentials_file) if FileTest.exists?(credentials_file)
      File.open(credentials_file, 'w', 0400) do |out|
	    out.puts token
      end
      FileUtils.chmod(0700, dir)
      @token = token
    end
    def read_credentials
      if FileTest.exist?(credentials_file)
        File.open(credentials_file, 'r') do |f|
          @token = f.gets.chomp
          @authenticated = true if @token
        end
      else
        @token = nil
      end
    end
    private
    def credentials_file
      File.join(home_directory, '.flydata', 'credentials')
    end
    def encode(str)
      str.unpack('H*') # want to change more complecated? still useful for shoulder hacking.
    end
    def decode(str)
      [str].pack('H*')
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
flydata-0.0.5.3 lib/flydata/credentials.rb
flydata-0.0.5.2 lib/flydata/credentials.rb
flydata-0.0.5.1 lib/flydata/credentials.rb
flydata-0.0.5.0 lib/flydata/credentials.rb
flydata-0.0.4.4 lib/flydata/credentials.rb
flydata-0.0.4.3 lib/flydata/credentials.rb
flydata-0.0.4.2 lib/flydata/credentials.rb
flydata-0.0.4.1 lib/flydata/credentials.rb
flydata-0.0.4.0 lib/flydata/credentials.rb
flydata-0.0.3.8 lib/flydata/credentials.rb
flydata-0.0.3.7 lib/flydata/credentials.rb
flydata-0.0.3.6 lib/flydata/credentials.rb
flydata-0.0.3.5 lib/flydata/credentials.rb
flydata-0.0.3.4 lib/flydata/credentials.rb
flydata-0.0.3.3 lib/flydata/credentials.rb
flydata-0.0.3.2 lib/flydata/credentials.rb
flydata-0.0.3.1 lib/flydata/credentials.rb
flydata-0.0.3 lib/flydata/credentials.rb
flydata-0.0.3.rc1 lib/flydata/credentials.rb