Class: NetFlix::Credentials

Inherits:
Valuable show all
Defined in:
lib/net_flix/credentials.rb

Constant Summary collapse

CONFIG_FILENAME =
File.join( File.expand_path('config'), 'netflix_credentials.yml')

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Valuable

#attributes, attributes, create_accessor_for, create_setter_for, #deep_duplicate_of, defaults, has_collection, has_value, #initialize

Constructor Details

This class inherits a constructor from Valuable

Class Method Details

.config_file_exists?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/net_flix/credentials.rb', line 20

def config_file_exists?
  File.exist? CONFIG_FILENAME
end

.from_fileObject



16
17
18
# File 'lib/net_flix/credentials.rb', line 16

def from_file
  new(config_file_exists? ? YAML.load(File.open(CONFIG_FILENAME)) : {}) 
end

Instance Method Details

#to_file!Object

class methods



26
27
28
29
30
# File 'lib/net_flix/credentials.rb', line 26

def to_file!
  credentials_store = File.new(CONFIG_FILENAME, 'w')
  credentials_store.puts(self.to_yaml)
  credentials_store.close
end

#to_yamlObject



32
33
34
# File 'lib/net_flix/credentials.rb', line 32

def to_yaml
  attributes.to_yaml
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/net_flix/credentials.rb', line 10

def valid?
  (key && secret) != nil
end