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.
-
.default_nr ⇒ Object
readonly
Returns the value of attribute default_nr.
-
.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(acc_db) ⇒ Object
- .config_file ⇒ Object
- .create_api_file ⇒ Object
- .create_version_file ⇒ Object
- .defaults ⇒ Object
- .get_token ⇒ Object
- .has_token_file? ⇒ Boolean
- .has_version_file? ⇒ Boolean
- .init_config ⇒ Object
- .load_config ⇒ Object
- .new_api_file(api_file) ⇒ Object
- .read_api(api_file) ⇒ Object
- .read_token_file ⇒ Object
- .read_version_file ⇒ Object
- .restore_defaults ⇒ Object
- .save_config ⇒ Object
- .write_config_file(config_file, options) ⇒ 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 |
.default_nr ⇒ Object (readonly)
Returns the value of attribute default_nr.
9 10 11 |
# File 'lib/ayadn/settings.rb', line 9 def default_nr @default_nr 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(acc_db) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ayadn/settings.rb', line 48 def self.check_for_accounts(acc_db) unless File.exist?(acc_db) puts Status. exit end end |
.config_file ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ayadn/settings.rb', line 84 def self.config_file config_file = @config[:paths][:config] + "/config.yml" if File.exist?(config_file) begin conf = YAML.load(File.read(config_file)) # force delete obsolete keys (because legacy versions of the config file) conf[:timeline].delete_if {|k,_| k == :show_nicerank} conf[:colors].delete_if {|k,_| k == :nicerank} # force create mandatory keys (idem) conf[:nicerank] = @default_nr if conf[:nicerank].nil? || conf[:nicerank].size != 4 conf[:timeline][:show_debug] = false if conf[:timeline][:show_debug].nil? conf[:timeline][:show_spinner] = true if conf[:timeline][:show_spinner].nil? conf[:colors][:debug] = :red if conf[:colors][:debug].nil? conf[:nowplaying] = {} if conf[:nowplaying].nil? conf[:movie] = {hashtag: 'nowwatching'} if conf[:movie].nil? conf[:tvshow] = {hashtag: 'nowwatching'} if conf[:tvshow].nil? conf[:formats][:list] = {reverse: true} if conf[:formats][:list].nil? conf[:timeline][:compact] = false if conf[:timeline][:compact].nil? = conf self.write_config_file(config_file, ) 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
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ayadn/settings.rb', line 118 def self.create_api_file api_file = @config[:paths][:config] + "/api.json" if File.exist?(api_file) if ( File.ctime(api_file) < (Time.now - 172800) ) #48h in secs 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
130 131 132 |
# File 'lib/ayadn/settings.rb', line 130 def self.create_version_file File.write(@config[:paths][:config] + "/version.yml", {version: @config[:version]}.to_yaml) end |
.defaults ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/ayadn/settings.rb', line 166 def self.defaults { timeline: { directed: 1, deleted: 0, html: 0, annotations: 1, show_source: true, show_symbols: true, show_real_name: true, show_date: true, show_spinner: true, show_debug: false, compact: false }, counts: { default: 50, unified: 100, global: 100, checkins: 100, conversations: 50, photos: 50, trending: 100, mentions: 100, convo: 100, posts: 100, messages: 50, search: 200, whoreposted: 50, whostarred: 50, whatstarred: 100, files: 100 }, formats: { table: { width: 75 }, list: { reverse: true } }, colors: { id: :blue, index: :red, username: :green, name: :magenta, date: :cyan, link: :yellow, dots: :blue, hashtags: :cyan, mentions: :red, source: :cyan, symbols: :green, debug: :red }, backup: { auto_save_sent_posts: false, auto_save_sent_messages: false, auto_save_lists: false }, scroll: { timer: 3 }, nicerank: @default_nr, nowplaying: {}, movie: { hashtag: 'nowwatching' }, tvshow: { hashtag: 'nowwatching' } } end |
.get_token ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/ayadn/settings.rb', line 55 def self.get_token if self.has_token_file? @user_token = self.read_token_file else puts Status. exit end end |
.has_token_file? ⇒ Boolean
76 77 78 |
# File 'lib/ayadn/settings.rb', line 76 def self.has_token_file? File.exist?(@config[:paths][:auth] + "/token") end |
.has_version_file? ⇒ Boolean
154 155 156 |
# File 'lib/ayadn/settings.rb', line 154 def self.has_version_file? File.exist?(@config[:paths][:config] + "/version.yml") end |
.init_config ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ayadn/settings.rb', line 64 def self.init_config @config[:version] = VERSION @config[:platform] = RbConfig::CONFIG['host_os'] self.config_file self.create_api_file self.create_version_file 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 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ayadn/settings.rb', line 12 def self.load_config acc_db = Dir.home + "/ayadn/accounts.db" self.check_for_accounts(acc_db) db = Databases.init acc_db active = db['ACTIVE'] home = db[active][:path] @config = { paths: { home: home, log: "#{home}/log", db: "#{home}/db", pagination: "#{home}/pagination", config: "#{home}/config", auth: "#{home}/auth", downloads: "#{home}/downloads", backup: "#{home}/backup", posts: "#{home}/posts", messages: "#{home}/messages", lists: "#{home}/lists" }, identity: { id: db[active][:id], username: db[active][:username], handle: db[active][:handle] } } @default_nr = { threshold: 2.1, cache: 48, filter: true, filter_unranked: false } db.close = self.defaults end |
.new_api_file(api_file) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/ayadn/settings.rb', line 141 def self.new_api_file(api_file) api = API.new resp = api.get_config api.(resp) File.write(api_file, resp['data'].to_json) end |
.read_api(api_file) ⇒ Object
148 149 150 151 152 |
# File 'lib/ayadn/settings.rb', line 148 def self.read_api(api_file) content = JSON.parse(File.read(api_file)) @config[:post_max_length] = content['post']['text_max_length'] @config[:message_max_length] = content['message']['text_max_length'] end |
.read_token_file ⇒ Object
80 81 82 |
# File 'lib/ayadn/settings.rb', line 80 def self.read_token_file File.read(@config[:paths][:auth] + "/token") end |
.read_version_file ⇒ Object
158 159 160 |
# File 'lib/ayadn/settings.rb', line 158 def self.read_version_file YAML.load(File.read(@config[:paths][:config] + "/version.yml")) end |
.restore_defaults ⇒ Object
134 135 136 137 |
# File 'lib/ayadn/settings.rb', line 134 def self.restore_defaults self.load_config File.write(@config[:paths][:config] + "/config.yml", .to_yaml) end |
.save_config ⇒ Object
72 73 74 |
# File 'lib/ayadn/settings.rb', line 72 def self.save_config File.write(@config[:paths][:config] + "/config.yml", .to_yaml) end |
.write_config_file(config_file, options) ⇒ Object
162 163 164 |
# File 'lib/ayadn/settings.rb', line 162 def self.write_config_file(config_file, ) File.write(config_file, .to_yaml) end |