Module: Conf
- Extended by:
- Conf
- Included in:
- Conf
- Defined in:
- lib/pocketbeuter/conf.rb,
lib/pocketbeuter/get_access_token_and_username.rb
Defined Under Namespace
Modules: GetAccessToken
Constant Summary collapse
- ADD_URL =
'https://getpocket.com/v3/add'
- SEND_URL =
'https://getpocket.com/v3/send'
- GET_URL =
'https://getpocket.com/v3/get'
- OAUTH_URL =
'https://getpocket.com/v3/oauth/request'
- AUTH_URL =
'https://getpocket.com/auth/authorize'
- OAUTH_AUTH_URL =
'https://getpocket.com/v3/oauth/authorize'
Instance Method Summary collapse
- #config ⇒ Object
- #default_config ⇒ Object
- #init ⇒ Object
- #load_config ⇒ Object
- #save_config ⇒ Object
Instance Method Details
#config ⇒ Object
11 12 13 |
# File 'lib/pocketbeuter/conf.rb', line 11 def config @config ||= {} end |
#default_config ⇒ Object
19 20 21 22 23 |
# File 'lib/pocketbeuter/conf.rb', line 19 def default_config config[:dir] = File.('~/.pocketbeuter') config[:file] = config[:dir] + '/config' config[:cache] = config[:dir] + '/cache' end |
#init ⇒ Object
14 15 16 17 18 |
# File 'lib/pocketbeuter/conf.rb', line 14 def init load_config GetAccessToken.get_access_token_and_username save_config end |
#load_config ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pocketbeuter/conf.rb', line 24 def load_config default_config if File.exists?(config[:file]) @config = YAML.load_file(config[:file]) else File.open(config[:file], mode: 'w', perm: 0600).close end end |
#save_config ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pocketbeuter/conf.rb', line 32 def save_config unless File.exists?(config[:dir]) FileUtils.mkdir_p(config[:dir]) end if File.exists?(config[:file]) File.open(config[:file], 'w') { |f| f.write(config.to_yaml) } else File.open(config[:file], mode: 'w', perm: 0600).close end end |