ayadn 1.8.2 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/CHANGELOG.md +73 -52
  4. data/README.md +17 -3
  5. data/ayadn.gemspec +3 -4
  6. data/doc/01-index.md +6 -5
  7. data/doc/02-install.md +23 -1
  8. data/doc/03-first-steps.md +22 -28
  9. data/doc/04-options.md +1 -1
  10. data/doc/05-streams.md +29 -9
  11. data/doc/06-post.md +13 -5
  12. data/doc/07-actions.md +63 -1
  13. data/doc/08-listings.md +112 -4
  14. data/doc/09-accounts.md +17 -3
  15. data/doc/10-nicerank.md +5 -5
  16. data/doc/11-blacklist.md +8 -14
  17. data/doc/12-alias.md +1 -13
  18. data/doc/14-set.md +8 -110
  19. data/doc/15-nowplaying.md +16 -4
  20. data/doc/18-contact.md +14 -13
  21. data/doc/19-examples.md +2 -0
  22. data/lib/ayadn/action.rb +322 -183
  23. data/lib/ayadn/alias.rb +17 -45
  24. data/lib/ayadn/annotations.rb +1 -1
  25. data/lib/ayadn/api.rb +7 -8
  26. data/lib/ayadn/app.rb +99 -12
  27. data/lib/ayadn/authorize.rb +92 -57
  28. data/lib/ayadn/blacklist.rb +52 -62
  29. data/lib/ayadn/check.rb +81 -74
  30. data/lib/ayadn/cnx.rb +77 -26
  31. data/lib/ayadn/databases.rb +890 -105
  32. data/lib/ayadn/debug.rb +30 -89
  33. data/lib/ayadn/descriptions.rb +876 -329
  34. data/lib/ayadn/endpoints.rb +2 -2
  35. data/lib/ayadn/errors.rb +9 -9
  36. data/lib/ayadn/extend.rb +8 -1
  37. data/lib/ayadn/fileops.rb +10 -8
  38. data/lib/ayadn/mark.rb +79 -56
  39. data/lib/ayadn/migration.rb +427 -0
  40. data/lib/ayadn/nicerank.rb +74 -72
  41. data/lib/ayadn/nowplaying.rb +123 -60
  42. data/lib/ayadn/nowwatching.rb +26 -10
  43. data/lib/ayadn/pinboard.rb +12 -7
  44. data/lib/ayadn/post.rb +40 -37
  45. data/lib/ayadn/profile.rb +5 -2
  46. data/lib/ayadn/scroll.rb +20 -5
  47. data/lib/ayadn/search.rb +30 -22
  48. data/lib/ayadn/set.rb +146 -50
  49. data/lib/ayadn/settings.rb +66 -67
  50. data/lib/ayadn/status.rb +459 -234
  51. data/lib/ayadn/stream.rb +80 -46
  52. data/lib/ayadn/switch.rb +51 -47
  53. data/lib/ayadn/tvshow.rb +47 -15
  54. data/lib/ayadn/version.rb +1 -1
  55. data/lib/ayadn/view.rb +119 -60
  56. data/lib/ayadn/workers.rb +144 -92
  57. data/lib/ayadn.rb +7 -8
  58. data/spec/mock/ayadn/accounts.sqlite +0 -0
  59. data/spec/mock/ayadn.sqlite +0 -0
  60. data/spec/unit/annotations_spec.rb +12 -13
  61. data/spec/unit/api_spec.rb +3 -4
  62. data/spec/unit/blacklistworkers_spec.rb +18 -23
  63. data/spec/unit/databases_spec.rb +51 -36
  64. data/spec/unit/endpoints_spec.rb +5 -2
  65. data/spec/unit/extend_spec.rb +24 -0
  66. data/spec/unit/nicerank_spec.rb +13 -13
  67. data/spec/unit/post_spec.rb +47 -36
  68. data/spec/unit/set_spec.rb +67 -96
  69. data/spec/unit/view_spec.rb +12 -6
  70. data/spec/unit/workers_spec.rb +38 -12
  71. data/tags +1285 -0
  72. metadata +29 -39
  73. data/spec/mock/aliases.db +0 -0
  74. data/spec/mock/blacklist.db +0 -0
  75. data/spec/mock/bookmarks.db +0 -0
  76. data/spec/mock/channels.db +0 -0
  77. data/spec/mock/index.db +0 -0
  78. data/spec/mock/nicerank.db +0 -0
  79. data/spec/mock/pagination.db +0 -0
  80. data/spec/mock/users.db +0 -0
  81. data/spec/unit/status_spec.rb +0 -9
@@ -56,7 +56,7 @@ module Ayadn
56
56
  else
57
57
  API.build_query({count: Settings.options[:counts][:global]})
58
58
  end
59
- if Settings.options[:force]
59
+ if Settings.global[:force] == true
60
60
  "#{@posts_url}stream/global?#{@options_list}"
61
61
  else
62
62
  "#{@posts_url}stream/global?access_token=#{Settings.user_token}#{@options_list}"
@@ -105,7 +105,7 @@ module Ayadn
105
105
  else
106
106
  API.build_query({count: Settings.options[:counts][:posts]})
107
107
  end
108
- if Settings.options[:force]
108
+ if Settings.global[:force] == true
109
109
  "#{@users_url}#{username}/posts/?#{@options_list}"
110
110
  else
111
111
  "#{@users_url}#{username}/posts/?access_token=#{Settings.user_token}#{@options_list}"
data/lib/ayadn/errors.rb CHANGED
@@ -3,7 +3,11 @@ module Ayadn
3
3
  class Errors
4
4
 
5
5
  def self.global_error(args)
6
- abort(Status.wtf) if Logs.nil? || Logs.rec.nil?
6
+ if Logs.nil? || Logs.rec.nil?
7
+ Status.new.wtf
8
+ exit
9
+ end
10
+ thor = Thor::Shell::Color.new
7
11
  Logs.rec.error "--BEGIN--"
8
12
  Logs.rec.error "CAUSE: #{args[:error]}"
9
13
  Logs.rec.debug "DATA: #{args[:data]}"
@@ -14,9 +18,9 @@ module Ayadn
14
18
  "#{dir}/#{file}"
15
19
  end
16
20
  Logs.rec.debug "STACK: #{stack}"
17
- #Logs.rec.debug "STACK: #{args[:caller]}"
18
21
  Logs.rec.error "--END--"
19
- puts "\nError logged in #{Settings.config[:paths][:log]}/ayadn.log\n".color(:blue)
22
+ thor.say_status :error, "logged in #{Settings.config[:paths][:log]}/ayadn.log", :red
23
+ puts "\n"
20
24
  Debug.err(args[:error], stack)
21
25
  exit
22
26
  end
@@ -41,14 +45,10 @@ module Ayadn
41
45
  Logs.nr.warn msg
42
46
  end
43
47
 
44
- def self.whine(status, resp)
45
- puts status
46
- self.error("#{status} => #{resp['meta']}")
47
- end
48
-
49
48
  def self.no_data(where)
50
49
  self.warn "In action/#{where}: no data"
51
- abort(Status.empty_list)
50
+ Status.new.empty_list
51
+ exit
52
52
  end
53
53
 
54
54
  end
data/lib/ayadn/extend.rb CHANGED
@@ -1,7 +1,14 @@
1
1
  # encoding: utf-8
2
2
  class String
3
3
  def is_integer?
4
- self.to_i.to_s == self
4
+ begin
5
+ temp = self.to_i.to_s
6
+ return false if temp == "0"
7
+ Integer(temp)
8
+ return true
9
+ rescue ArgumentError
10
+ return false
11
+ end
5
12
  end
6
13
  end
7
14
  class Integer
data/lib/ayadn/fileops.rb CHANGED
@@ -34,10 +34,6 @@ module Ayadn
34
34
  File.write(Settings.config[:paths][:downloads] + "/#{name}", file)
35
35
  end
36
36
 
37
- def self.old_ayadn?
38
- Dir.exist?(Dir.home + "/ayadn/data")
39
- end
40
-
41
37
  def self.upload_files files
42
38
  files.map do |file|
43
39
  puts "\n#{file}\n\n"
@@ -56,13 +52,17 @@ module Ayadn
56
52
  `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file}" -F 'public=true' -X POST`
57
53
  end
58
54
  rescue Errno::ENOENT
59
- abort(Status.no_curl)
55
+ Status.new.no_curl
56
+ exit
60
57
  end
61
58
  end
62
59
 
63
60
  def self.make_paths(files_array)
64
61
  files_array.map do |file|
65
- abort(Status.bad_path) unless File.exist?(file)
62
+ unless File.exist?(file)
63
+ Status.new.bad_path
64
+ exit
65
+ end
66
66
  File.absolute_path(file)
67
67
  end
68
68
  end
@@ -71,7 +71,8 @@ module Ayadn
71
71
  begin
72
72
  `curl -X POST -H "Authorization: Bearer #{Settings.user_token}" -F "avatar=@#{file}" #{Endpoints.new.avatar}`
73
73
  rescue Errno::ENOENT
74
- abort(Status.no_curl)
74
+ Status.new.no_curl
75
+ exit
75
76
  end
76
77
  end
77
78
 
@@ -79,7 +80,8 @@ module Ayadn
79
80
  begin
80
81
  `curl -X POST -H "Authorization: Bearer #{Settings.user_token}" -F "cover=@#{file}" #{Endpoints.new.cover}`
81
82
  rescue Errno::ENOENT
82
- abort(Status.no_curl)
83
+ Status.new.no_curl
84
+ exit
83
85
  end
84
86
  end
85
87
 
data/lib/ayadn/mark.rb CHANGED
@@ -5,21 +5,29 @@ module Ayadn
5
5
  desc "add POST_ID (TITLE)", "Create a bookmark for this conversation"
6
6
  long_desc Descriptions.mark_add
7
7
  map "create" => :add
8
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
8
9
  def add(*args)
9
10
  begin
10
11
  init
12
+ status = Status.new
11
13
  unless args.empty?
12
14
  double = args.dup
13
15
  post_id, convo_title = double.shift, double.join(' ')
14
16
  else
15
- abort Status.wrong_arguments
17
+ status.wrong_arguments
18
+ exit
19
+ end
20
+ Check.new.bad_post_id(post_id)
21
+ if options[:force]
22
+ Settings.global[:force] = true
23
+ else
24
+ post_id = Workers.new.get_real_post_id(post_id)
16
25
  end
17
- abort Status.error_missing_post_id unless post_id.is_integer?
18
26
  convo_title = post_id if convo_title == ''
19
27
  api, workers, view = API.new, Workers.new, View.new
20
28
  users, bucket = [], []
21
29
  view.clear_screen
22
- puts "\nAnalyzing conversation...\n".inverse
30
+ status.info(:connected, "analyzing conversation", :yellow)
23
31
  resp = api.get_convo(post_id, options)
24
32
  posts = workers.build_posts(resp['data'].reverse)
25
33
  posts.each do |id, post|
@@ -30,31 +38,29 @@ module Ayadn
30
38
  users.uniq!
31
39
  now = Time.now.to_s
32
40
  bookmark = {
33
- id: post_id,
34
- root_id: bucket[0][:id],
35
- last_id: (bucket.last)[:id],
36
- title: convo_title,
37
- first_date: bucket[0][:date],
38
- last_date: (bucket.last)[:date],
39
- mark_date: now[0..18],
40
- first_poster: bucket[0][:original_poster],
41
- last_poster: (bucket.last)[:username],
42
- users: users,
43
- size: bucket.length,
44
- url: bucket[0][:canonical_url],
45
- root_text: bucket[0][:raw_text],
46
- root_colorized_text: bucket[0][:text]
41
+ 'id' => post_id,
42
+ 'root_id' => bucket[0][:id],
43
+ 'last_id' => (bucket.last)[:id],
44
+ 'title' => convo_title,
45
+ 'first_date' => bucket[0][:date],
46
+ 'last_date' => (bucket.last)[:date],
47
+ 'mark_date' => now[0..18],
48
+ 'first_poster' => bucket[0][:original_poster],
49
+ 'last_poster' => (bucket.last)[:username],
50
+ 'users' => users,
51
+ 'size' => bucket.length,
52
+ 'url' => bucket[0][:canonical_url],
53
+ 'root_text' => bucket[0][:raw_text],
54
+ 'root_colorized_text' => bucket[0][:text]
47
55
  }
48
56
  view.clear_screen
49
- puts "Bookmarked conversation:\n".color(:green)
57
+ status.info(:done, "bookmarked conversation:", :green)
50
58
  puts make_entry bookmark
51
59
  Databases.add_bookmark bookmark
52
- Logs.rec.info "Added conversation bookmark for post #{bookmark[:id]}."
53
- puts Status.done
60
+ Logs.rec.info "Added conversation bookmark for post #{bookmark['id']}."
61
+ status.done
54
62
  rescue => e
55
63
  Errors.global_error({error: e, caller: caller, data: [args]})
56
- ensure
57
- Databases.close_all
58
64
  end
59
65
  end
60
66
 
@@ -64,18 +70,19 @@ module Ayadn
64
70
  def list
65
71
  begin
66
72
  init
67
- list = []
68
- Databases.bookmarks.each {|i,v| list << v}
73
+ list = Databases.all_bookmarks
69
74
  if options[:raw]
70
75
  jj JSON.parse(list.to_json)
71
76
  exit
72
77
  end
78
+ if list.empty?
79
+ Status.new.empty_list
80
+ exit
81
+ end
73
82
  puts "\n"
74
- list.each {|marked| puts make_entry marked; puts "\n"}
83
+ list.each {|marked| puts make_entry(JSON.parse(marked[1])); puts "\n"}
75
84
  rescue => e
76
85
  Errors.global_error({error: e, caller: caller, data: [args, options]})
77
- ensure
78
- Databases.close_all
79
86
  end
80
87
  end
81
88
 
@@ -83,56 +90,72 @@ module Ayadn
83
90
  def clear
84
91
  begin
85
92
  init
86
- puts "\n\nAre you sure you want to erase all the content of your bookmarks database?\n\n[y/N]\n".color(:red)
93
+ status = Status.new
94
+ status.ask_clear_bookmarks
87
95
  input = STDIN.getch
88
96
  if input == 'y' || input == 'Y'
89
97
  Databases.clear_bookmarks
90
98
  Logs.rec.info "Cleared the bookmarks database."
91
- puts Status.done
99
+ status.done
92
100
  else
93
- abort Status.canceled
101
+ status.canceled
102
+ exit
94
103
  end
95
104
  rescue => e
96
105
  Errors.global_error({error: e, caller: caller, data: []})
97
- ensure
98
- Databases.close_all
99
106
  end
100
107
  end
101
108
 
102
109
  desc "delete POST_ID", "Delete entry POST_ID from your bookmarked conversations"
103
110
  map "remove" => :delete
104
111
  long_desc Descriptions.mark_delete
105
- def delete *args
112
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
113
+ def delete(*args)
106
114
  begin
107
115
  init
108
- args.empty? ? abort(Status.wrong_arguments) : post_id = args[0]
109
- abort Status.error_missing_post_id unless post_id.is_integer?
116
+ status = Status.new
117
+ if args.empty?
118
+ status.wrong_arguments
119
+ exit
120
+ else
121
+ post_id = args[0]
122
+ end
123
+ Check.new.bad_post_id(post_id)
124
+ if options[:force]
125
+ Settings.global[:force] = true
126
+ else
127
+ post_id = Workers.new.get_real_post_id(post_id)
128
+ end
110
129
  Databases.delete_bookmark post_id
111
- puts Status.done
130
+ status.done
112
131
  rescue => e
113
132
  Errors.global_error({error: e, caller: caller, data: [args]})
114
- ensure
115
- Databases.close_all
116
133
  end
117
134
  end
118
135
 
119
136
  desc "rename POST_ID NEW_TITLE", "Rename bookmark POST_ID"
120
137
  long_desc Descriptions.mark_rename
121
- def rename *args
138
+ option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
139
+ def rename(*args)
122
140
  begin
123
141
  init
142
+ status = Status.new
124
143
  unless args.empty? || args[1].nil?
125
- post_id, new_title = args[0], args[1]
144
+ arguments = args.dup
145
+ post_id = arguments.shift
126
146
  else
127
147
  abort Status.wrong_arguments
128
148
  end
129
- abort Status.error_missing_post_id unless post_id.is_integer?
130
- Databases.rename_bookmark post_id, new_title
131
- puts Status.done
149
+ Check.new.bad_post_id(post_id)
150
+ if options[:force]
151
+ Settings.global[:force] = true
152
+ else
153
+ post_id = Workers.new.get_real_post_id(post_id)
154
+ end
155
+ Databases.rename_bookmark post_id, arguments.join(" ")
156
+ status.done
132
157
  rescue => e
133
158
  Errors.global_error({error: e, caller: caller, data: [args]})
134
- ensure
135
- Databases.close_all
136
159
  end
137
160
  end
138
161
 
@@ -141,27 +164,27 @@ module Ayadn
141
164
  def make_entry content
142
165
  entry = ""
143
166
  entry << "Post id:".color(:cyan)
144
- entry << "\t#{content[:id]}\n".color(Settings.options[:colors][:username])
145
- unless content[:title].is_integer?
167
+ entry << "\t#{content['id']}\n".color(Settings.options[:colors][:username])
168
+ unless content['title'].is_integer?
146
169
  entry << "Title:".color(:cyan)
147
- entry << "\t\t#{content[:title]}\n".color(Settings.options[:colors][:id])
170
+ entry << "\t\t#{content['title']}\n".color(Settings.options[:colors][:id])
148
171
  end
149
172
  entry << "Date:".color(:cyan)
150
- entry << "\t\t#{content[:first_date]}\n".color(Settings.options[:colors][:date])
173
+ entry << "\t\t#{content['first_date']}\n".color(Settings.options[:colors][:date])
151
174
  # entry << "Bookmarked:".color(:cyan)
152
- # entry << "\t#{content[:mark_date]}\n".color(Settings.options[:colors][:date])
175
+ # entry << "\t#{content['mark_date']}\n".color(Settings.options[:colors][:date])
153
176
  entry << "Posts:".color(:cyan)
154
- entry << "\t\t#{content[:size]}\n".color(Settings.options[:colors][:name])
177
+ entry << "\t\t#{content['size']}\n".color(Settings.options[:colors][:name])
155
178
  entry << "Posters:".color(:cyan)
156
179
  posters = []
157
- content[:users].each {|mention| posters << "@#{mention}"}
180
+ content['users'].each {|mention| posters << "@#{mention}"}
158
181
  entry << "\t#{posters.join(', ')}\n".color(Settings.options[:colors][:mentions])
159
- # entry << "First:\t\t@#{content[:first_poster]}\n"
160
- # entry << "Last:\t\t@#{content[:last_poster]}\n"
182
+ # entry << "First:\t\t@#{content['first_poster']}\n"
183
+ # entry << "Last:\t\t@#{content['last_poster']}\n"
161
184
  entry << "Link:".color(:cyan)
162
- entry << "\t\t#{content[:url]}\n".color(Settings.options[:colors][:link])
185
+ entry << "\t\t#{content['url']}\n".color(Settings.options[:colors][:link])
163
186
  entry << "Beginning:".color(:cyan)
164
- text = content[:root_text].gsub(/[\r\n]/, ' ')
187
+ text = content['root_text'].gsub(/[\r\n]/, ' ')
165
188
  if text.length <= 60
166
189
  entry << "\t#{text}\n"
167
190
  else