Class: Ayadn::Settings
- Inherits:
-
Object
- Object
- Ayadn::Settings
- Defined in:
- lib/ayadn/settings.rb
Constant Summary collapse
- AYADN_CLIENT_ID =
"hFsCGArAjgJkYBHTHbZnUvzTmL4vaLHL"
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
-
.global ⇒ Object
Returns the value of attribute global.
-
.options ⇒ Object
Returns the value of attribute options.
-
.user_token ⇒ Object
readonly
Returns the value of attribute user_token.
Class Method Summary collapse
- .check_for_accounts ⇒ Object
- .config_file ⇒ Object
- .create_api_file ⇒ Object
- .create_version_file ⇒ Object
- .get_token ⇒ Object
- .has_token_file? ⇒ Boolean
- .init_config ⇒ Object
- .init_sqlite(sqlaccounts) ⇒ Object
- .load_config ⇒ Object
- .read_token_file ⇒ Object
- .restore_defaults ⇒ Object
- .save_config ⇒ Object
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/ayadn/settings.rb', line 8 def config @config end |
.global ⇒ Object
Returns the value of attribute global.
8 9 10 |
# File 'lib/ayadn/settings.rb', line 8 def global @global end |
.options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/ayadn/settings.rb', line 8 def end |
.user_token ⇒ Object (readonly)
Returns the value of attribute user_token.
9 10 11 |
# File 'lib/ayadn/settings.rb', line 9 def user_token @user_token end |
Class Method Details
.check_for_accounts ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ayadn/settings.rb', line 37 def self.check_for_accounts sqlaccounts = Dir.home + "/ayadn/accounts.sqlite" status = Status.new if File.exist?(sqlaccounts) # Ayadn 2.x with already authorized account(s) return self.init_sqlite(sqlaccounts) else if File.exist?(Dir.home + "/ayadn/accounts.db") # Ayadn 1.x with already authorized account(s) status.has_to_migrate exit else # Ayadn 1.x without any authorized account (gem installed but no ~/ayadn folder) status. exit end end end |
.config_file ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ayadn/settings.rb', line 91 def self.config_file config_file = @config[:paths][:config] + "/config.yml" if File.exist?(config_file) begin # conf = YAML.load(File.read(config_file)) # @options = conf = YAML.load(File.read(config_file)) # self.write_config_file(config_file, @options) rescue => e Errors.global_error({error: e, caller: caller, data: []}) end else begin self.write_config_file(config_file, ) rescue => e Errors.global_error({error: e, caller: caller, data: []}) end end end |
.create_api_file ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ayadn/settings.rb', line 111 def self.create_api_file api_file = @config[:paths][:config] + "/api.json" if File.exist?(api_file) # should be 48h in secs (172800) # but since ADN's API won't change any time soon... if ( File.ctime(api_file) < (Time.now - 604800) ) self.new_api_file(api_file) end else self.new_api_file(api_file) end self.read_api(api_file) end |
.create_version_file ⇒ Object
125 126 127 |
# File 'lib/ayadn/settings.rb', line 125 def self.create_version_file File.write(@config[:paths][:config] + "/version.yml", {version: @config[:version]}.to_yaml) end |
.get_token ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/ayadn/settings.rb', line 60 def self.get_token if self.has_token_file? @user_token = self.read_token_file else Status.new. exit end end |
.has_token_file? ⇒ Boolean
83 84 85 |
# File 'lib/ayadn/settings.rb', line 83 def self.has_token_file? File.exist?(@config[:paths][:auth] + "/token") end |
.init_config ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/ayadn/settings.rb', line 69 def self.init_config @config[:version] = VERSION @config[:platform] = RbConfig::CONFIG['host_os'] @config[:ruby] = RUBY_VERSION @config[:locale] = ENV["LANG"] self.config_file self.create_api_file self.create_version_file end |
.init_sqlite(sqlaccounts) ⇒ Object
56 57 58 |
# File 'lib/ayadn/settings.rb', line 56 def self.init_sqlite(sqlaccounts) Databases.active_account(Amalgalite::Database.new(sqlaccounts)) end |
.load_config ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ayadn/settings.rb', line 12 def self.load_config active = self.check_for_accounts home = active[3] @config = { paths: { home: home, log: "#{home}/log", db: "#{home}/db", config: "#{home}/config", auth: "#{home}/auth", downloads: "#{home}/downloads", posts: "#{home}/posts", messages: "#{home}/messages", lists: "#{home}/lists" }, identity: { id: active[1], username: active[0], handle: active[2] } } = self.defaults @global = {scrolling: false, force: false} end |
.read_token_file ⇒ Object
87 88 89 |
# File 'lib/ayadn/settings.rb', line 87 def self.read_token_file File.read(@config[:paths][:auth] + "/token") end |
.restore_defaults ⇒ Object
129 130 131 132 |
# File 'lib/ayadn/settings.rb', line 129 def self.restore_defaults self.load_config File.write(@config[:paths][:config] + "/config.yml", .to_yaml) end |
.save_config ⇒ Object
79 80 81 |
# File 'lib/ayadn/settings.rb', line 79 def self.save_config File.write(@config[:paths][:config] + "/config.yml", .to_yaml) end |