ayadn 3.0 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -4
  3. data/CHANGELOG.md +12 -4
  4. data/README.md +2 -5
  5. data/ayadn.gemspec +0 -2
  6. data/doc/01-index.md +0 -3
  7. data/doc/02-install.md +0 -4
  8. data/doc/06-post.md +0 -16
  9. data/doc/{18-contact.md → 16-contact.md} +0 -0
  10. data/doc/{19-examples.md → 17-examples.md} +0 -0
  11. data/doc/18-develop.md +165 -0
  12. data/lib/ayadn/action.rb +206 -396
  13. data/lib/ayadn/alias.rb +1 -1
  14. data/lib/ayadn/annotations.rb +15 -27
  15. data/lib/ayadn/api.rb +39 -28
  16. data/lib/ayadn/app.rb +19 -29
  17. data/lib/ayadn/authorize.rb +22 -13
  18. data/lib/ayadn/blacklist.rb +6 -19
  19. data/lib/ayadn/channel_object.rb +75 -0
  20. data/lib/ayadn/check.rb +19 -11
  21. data/lib/ayadn/cnx.rb +9 -15
  22. data/lib/ayadn/databases.rb +15 -27
  23. data/lib/ayadn/debug.rb +9 -9
  24. data/lib/ayadn/descriptions.rb +1 -99
  25. data/lib/ayadn/diagnostics.rb +16 -15
  26. data/lib/ayadn/endpoints.rb +18 -22
  27. data/lib/ayadn/errors.rb +1 -1
  28. data/lib/ayadn/fileops.rb +12 -12
  29. data/lib/ayadn/filtered_post_object.rb +11 -0
  30. data/lib/ayadn/ids.rb +0 -3
  31. data/lib/ayadn/logs.rb +4 -4
  32. data/lib/ayadn/mark.rb +34 -30
  33. data/lib/ayadn/nicerank.rb +7 -7
  34. data/lib/ayadn/nowplaying.rb +8 -22
  35. data/lib/ayadn/pinboard.rb +8 -12
  36. data/lib/ayadn/post.rb +18 -18
  37. data/lib/ayadn/post_object.rb +118 -0
  38. data/lib/ayadn/preferences_object.rb +290 -0
  39. data/lib/ayadn/profile.rb +2 -2
  40. data/lib/ayadn/scroll.rb +58 -67
  41. data/lib/ayadn/search.rb +22 -15
  42. data/lib/ayadn/set.rb +93 -83
  43. data/lib/ayadn/settings.rb +25 -33
  44. data/lib/ayadn/status.rb +24 -26
  45. data/lib/ayadn/stream.rb +68 -66
  46. data/lib/ayadn/stream_object.rb +56 -0
  47. data/lib/ayadn/switch.rb +2 -2
  48. data/lib/ayadn/user_object.rb +116 -0
  49. data/lib/ayadn/version.rb +1 -1
  50. data/lib/ayadn/view.rb +255 -278
  51. data/lib/ayadn/workers.rb +172 -174
  52. data/spec/integration/action_spec.rb +55 -34
  53. data/spec/mock/ayadn.sqlite +0 -0
  54. data/spec/unit/annotations_spec.rb +54 -41
  55. data/spec/unit/api_spec.rb +78 -7
  56. data/spec/unit/blacklistworkers_spec.rb +92 -20
  57. data/spec/unit/databases_spec.rb +117 -36
  58. data/spec/unit/endpoints_spec.rb +82 -10
  59. data/spec/unit/nicerank_spec.rb +56 -27
  60. data/spec/unit/post_spec.rb +94 -21
  61. data/spec/unit/set_spec.rb +141 -210
  62. data/spec/unit/view_spec.rb +105 -32
  63. data/spec/unit/workers_spec.rb +143 -52
  64. metadata +12 -37
  65. data/doc/16-movie.md +0 -39
  66. data/doc/17-tvshow.md +0 -46
  67. data/lib/ayadn/nowwatching.rb +0 -118
  68. data/lib/ayadn/tvshow.rb +0 -162
data/lib/ayadn/workers.rb CHANGED
@@ -2,17 +2,15 @@
2
2
  module Ayadn
3
3
  class Workers
4
4
 
5
- attr_reader :thor
6
-
7
- def initialize
8
- @status = Status.new
5
+ def initialize status = Status.new
6
+ @status = status
9
7
  end
10
8
 
11
9
  def table_borders
12
- if Settings.options[:formats][:table][:borders] == true
13
- { :width => Settings.options[:formats][:table][:width], border_x: '—', border_i: '+', border_y: '|' }
10
+ if Settings.options.formats.table.borders
11
+ { :width => Settings.options.formats.table.width, border_x: '—', border_i: '+', border_y: '|' }
14
12
  else
15
- { :width => Settings.options[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' }
13
+ { :width => Settings.options.formats.table.width, border_x: ' ', border_i: ' ', border_y: ' ' }
16
14
  end
17
15
  end
18
16
 
@@ -23,7 +21,7 @@ module Ayadn
23
21
  table.headings = [ 'Channel', 'Alias' ]
24
22
  list.each_with_index do |obj, index|
25
23
  table << [obj[0].to_s.color(:green), obj[1].color(:red)]
26
- if index + 1 != list.length && Settings.options[:timeline][:compact] == false
24
+ if index + 1 != list.length && !Settings.options.timeline.compact
27
25
  table << :separator
28
26
  end
29
27
  end
@@ -38,7 +36,7 @@ module Ayadn
38
36
  list.sort!
39
37
  list.each_with_index do |obj, index|
40
38
  table << ["#{obj[1].capitalize}".to_s.force_encoding("UTF-8").color(:green), "#{obj[0]}".to_s.force_encoding("UTF-8").color(:red)]
41
- if index + 1 != list.length && Settings.options[:timeline][:compact] == false
39
+ if index + 1 != list.length && !Settings.options.timeline.compact
42
40
  table << :separator
43
41
  end
44
42
  end
@@ -46,27 +44,13 @@ module Ayadn
46
44
  end
47
45
 
48
46
  def build_reposted_list(list, target)
49
- table = init_table
50
- table.title = "List of users who reposted post ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
51
- users_list = []
52
- list.each do |obj|
53
- obj['name'].nil? ? name = "" : name = obj['name'].to_s.force_encoding("UTF-8")
54
- users_list << {:username => obj['username'], :name => name, :you_follow => obj['you_follow'], :follows_you => obj['follows_you'], :id => obj['id'], :posts => obj['counts']['posts']}
55
- end
56
- table.style = table_borders()
57
- return users_list, table
47
+ title = "List of users who reposted post ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
48
+ build_reposted_or_starred_list(list, title)
58
49
  end
59
50
 
60
51
  def build_starred_list(list, target)
61
- table = init_table
62
- table.title = "List of users who starred post ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
63
- users_list = []
64
- list.each do |obj|
65
- obj['name'].nil? ? name = "" : name = obj['name'].to_s.force_encoding("UTF-8")
66
- users_list << {:username => obj['username'], :name => name, :you_follow => obj['you_follow'], :follows_you => obj['follows_you'], :id => obj['id'], :posts => obj['counts']['posts']}
67
- end
68
- table.style = table_borders()
69
- return users_list, table
52
+ title = "List of users who starred post ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
53
+ build_reposted_or_starred_list(list, title)
70
54
  end
71
55
 
72
56
  def build_followings_list(list, target, options = {}) #takes a hash of users with ayadn format
@@ -124,62 +108,60 @@ module Ayadn
124
108
  obj[:name] = "" if obj[:name].nil?
125
109
  obj[:username].length > 23 ? username = "#{obj[:username][0..20]}..." : username = obj[:username]
126
110
  obj[:name].length > 23 ? name = "#{obj[:name][0..20]}..." : name = obj[:name]
127
- arr << [ "@#{username} ".color(Settings.options[:colors][:username]), "#{name.to_s.force_encoding('UTF-8')}", obj[:posts] ]
111
+ arr << [ "@#{username} ".color(Settings.options.colors.username), "#{name.to_s.force_encoding('UTF-8')}", obj[:posts] ]
128
112
  end
129
113
  if options[:reverse]
130
114
  arr.reverse!
131
115
  end
132
- if Settings.options[:formats][:list][:reverse] == true
116
+ if Settings.options.formats.list.reverse
133
117
  arr.reverse!
134
118
  end
135
119
  arr.each_with_index do |obj, index|
136
120
  table << arr[index]
137
- if index + 1 != arr.length && Settings.options[:timeline][:compact] == false
121
+ if index + 1 != arr.length && !Settings.options.timeline.compact
138
122
  table << :separator
139
123
  end
140
124
  end
141
125
  table
142
126
  end
143
127
 
144
- # builds a hash of hashes, each hash is a normalized post with post id as a key
145
- def build_posts(data, niceranks = {})
128
+ def build_posts(posts, niceranks = {})
146
129
  # skip objects in blacklist unless force
147
- posts = {}
148
- data.each.with_index(1) do |post, index|
149
- unless Settings.global[:force] == true
150
- if Settings.options[:blacklist][:active] == true
151
- if Databases.is_in_blacklist?('client', post['source']['name'].downcase)
152
- Debug.skipped({source: post['source']['name']})
130
+ results = []
131
+ posts.each.with_index(1) do |post, index|
132
+ unless Settings.global.force
133
+ if Settings.options.blacklist.active
134
+ if Databases.is_in_blacklist?('client', post.source.name.downcase)
135
+ Debug.skipped({source: post.source.name})
153
136
  next
154
137
  end
155
138
  end
156
139
  end
157
- unless Settings.global[:force] == true
158
- if Settings.options[:blacklist][:active] == true
159
- if Databases.is_in_blacklist?('user', post['user']['username'].downcase)
160
- Debug.skipped({user: post['user']['username']})
140
+ unless Settings.global.force
141
+ if Settings.options.blacklist.active
142
+ if Databases.is_in_blacklist?('user', post.user.username.downcase)
143
+ Debug.skipped({user: post.user.username})
161
144
  next
162
145
  end
163
146
  end
164
147
  end
165
148
  hashtags = extract_hashtags(post)
166
149
  @skip = false
167
- unless Settings.global[:force] == true
168
- if Settings.options[:blacklist][:active] == true
169
- hashtags.each do |h|
170
- if Databases.is_in_blacklist?('hashtag', h.downcase)
150
+ unless Settings.global.force
151
+ if Settings.options.blacklist.active
152
+ hashtags.each do |tag|
153
+ if Databases.is_in_blacklist?('hashtag', tag.downcase)
171
154
  @skip = true
172
- Debug.skipped({hashtag: h})
155
+ Debug.skipped({hashtag: tag})
173
156
  break
174
157
  end
175
158
  end
176
159
  end
177
160
  end
178
161
  next if @skip
179
- mentions= []
180
- post['entities']['mentions'].each { |m| mentions << m['name'] }
181
- unless Settings.global[:force] == true
182
- if Settings.options[:blacklist][:active] == true
162
+ mentions = extract_mentions(post)
163
+ unless Settings.global.force
164
+ if Settings.options.blacklist.active
183
165
  mentions.each do |m|
184
166
  if Databases.is_in_blacklist?('mention', m.downcase)
185
167
  @skip = true
@@ -190,9 +172,9 @@ module Ayadn
190
172
  end
191
173
  end
192
174
  next if @skip
193
- unless Settings.global[:force] == true
194
- if Settings.options[:blacklist][:active] == true
195
- post['text'].split(" ").each do |word|
175
+ unless Settings.global.force
176
+ if Settings.options.blacklist.active
177
+ post.text.split(" ").each do |word|
196
178
  target_word = word.gsub(/[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/, "")
197
179
  if Databases.is_in_blacklist?('word', target_word.downcase)
198
180
  Debug.skipped({word: target_word})
@@ -205,108 +187,105 @@ module Ayadn
205
187
  next if @skip
206
188
 
207
189
  # create custom objects from ADN response
208
- if niceranks[post['user']['id'].to_i]
209
- rank = niceranks[post['user']['id'].to_i][:rank]
210
- is_human = niceranks[post['user']['id'].to_i][:is_human]
190
+ filtered = FilteredPost.new(post)
191
+
192
+ user_id_int = post.user.id.to_i
193
+ if niceranks[user_id_int]
194
+ filtered.nicerank = niceranks[user_id_int][:rank]
195
+ filtered.is_human = niceranks[user_id_int][:is_human]
211
196
  else
212
- rank = false
213
- is_human = 'unknown'
197
+ filtered.nicerank = false
198
+ filtered.is_human = 'unknown'
214
199
  end
215
200
 
216
- if post['user'].has_key?('name')
217
- name = post['user']['name'].to_s.force_encoding("UTF-8")
201
+ if !post.user.name.blank?
202
+ filtered.name = post.user.name.force_encoding("UTF-8")
218
203
  else
219
- name = "(no name)"
204
+ filtered.name = "(no name)"
220
205
  end
221
206
 
222
- source = post['source']['name'].to_s.force_encoding("UTF-8")
223
-
224
- values = {
225
- count: index,
226
- id: post['id'].to_i,
227
- name: name,
228
- thread_id: post['thread_id'],
229
- username: post['user']['username'],
230
- user_id: post['user']['id'].to_i,
231
- nicerank: rank,
232
- is_human: is_human,
233
- handle: "@#{post['user']['username']}",
234
- type: post['user']['type'],
235
- date: parsed_time(post['created_at']),
236
- date_short: parsed_time_short(post['created_at']),
237
- you_starred: post['you_starred'],
238
- source_name: source,
239
- source_link: post['source']['link'],
240
- canonical_url: post['canonical_url'],
241
- tags: hashtags,
242
- links: extract_links(post),
243
- mentions: mentions,
244
- directed_to: mentions.first || false
245
- }
246
-
247
- values[:checkins], values[:has_checkins] = extract_checkins(post)
248
-
249
- if post['repost_of']
250
- values[:is_repost] = true
251
- values[:repost_of] = post['repost_of']['id']
252
- values[:original_poster] = post['repost_of']['user']['username']
207
+ source = post.source.name.force_encoding("UTF-8")
208
+
209
+ filtered.count = index
210
+ filtered.id = post.id.to_i
211
+ filtered.thread_id = post.thread_id
212
+ filtered.username = post.user.username
213
+ filtered.user_id = post.user.id.to_i
214
+ filtered.handle = "@#{post.user.username}"
215
+ filtered.type = post.user.type
216
+ filtered.date = parsed_time(post.created_at)
217
+ filtered.date_short = parsed_time_short(post.created_at)
218
+ filtered.you_starred = post.you_starred
219
+ filtered.source_name = source
220
+ filtered.source_link = post.source.link
221
+ filtered.canonical_url = post.canonical_url
222
+ filtered.tags = hashtags
223
+ filtered.links = extract_links(post)
224
+ filtered.mentions = mentions
225
+ filtered.directed_to = mentions.first || false
226
+ filtered.checkins, filtered.has_checkins = extract_checkins(post)
227
+
228
+ if !post.repost_of.nil?
229
+ filtered.is_repost = true
230
+ filtered.repost_of = post.repost_of.id
231
+ filtered.original_poster = post.repost_of.user.username
253
232
  else
254
- values[:is_repost] = false
255
- values[:repost_of] = nil
256
- values[:original_poster] = post['user']['username']
233
+ filtered.is_repost = false
234
+ filtered.repost_of = nil
235
+ filtered.original_poster = post.user.username
257
236
  end
258
237
 
259
- unless post['text'].nil?
260
- values[:raw_text] = post['text']
261
- values[:text] = colorize_text(post['text'], mentions, hashtags)
238
+ unless post.text.blank?
239
+ filtered.raw_text = post.text
240
+ filtered.text = colorize_text(post.text, mentions, hashtags)
262
241
  else
263
- values[:raw_text] = ""
264
- values[:text] = "(no text)"
242
+ filtered.raw_text = ""
243
+ filtered.text = "(no text)"
265
244
  end
266
245
 
267
- unless post['num_stars'].nil? || post['num_stars'] == 0
268
- values[:is_starred] = true
269
- values[:num_stars] = post['num_stars']
246
+ unless post.num_stars.nil? || post.num_stars == 0
247
+ filtered.is_starred = true
248
+ filtered.num_stars = post.num_stars
270
249
  else
271
- values[:is_starred] = false
272
- values[:num_stars] = 0
250
+ filtered.is_starred = false
251
+ filtered.num_stars = 0
273
252
  end
274
253
 
275
- if post['num_replies']
276
- values[:num_replies] = post['num_replies']
254
+ if !post.num_replies.nil?
255
+ filtered.num_replies = post.num_replies
277
256
  else
278
- values[:num_replies] = 0
257
+ filtered.num_replies = 0
279
258
  end
280
259
 
281
- if post['reply_to']
282
- values[:is_reply] = true
283
- values[:reply_to] = post['reply_to']
260
+ if !post.reply_to.nil?
261
+ filtered.is_reply = true
262
+ filtered.reply_to = post.reply_to
284
263
  else
285
- values[:is_reply] = false
286
- values[:reply_to] = nil
264
+ filtered.is_reply = false
265
+ filtered.reply_to = nil
287
266
  end
288
- if post['num_reposts']
289
- values[:num_reposts] = post['num_reposts']
267
+ if !post.num_reposts.nil?
268
+ filtered.num_reposts = post.num_reposts
290
269
  else
291
- values[:num_reposts] = 0
270
+ filtered.num_reposts = 0
292
271
  end
293
272
 
294
- posts[post['id'].to_i] = values
273
+ results << filtered
295
274
 
296
275
  end
297
276
 
298
- posts
277
+ results
299
278
  end
300
279
 
301
280
  def extract_links(post)
302
- links = post['entities']['links'].map { |l| l['url'] }
303
- unless post['annotations'].nil? || post['annotations'].empty?
304
- post['annotations'].each do |ann|
305
- if ann['type'] == "net.app.core.oembed"
306
- if ann['value']['embeddable_url']
307
- links << ann['value']['embeddable_url']
308
- elsif ann['value']['url'] && Settings.options[:channels][:links] == true
309
- links << ann['value']['url']
281
+ links = post.entities.links.map { |l| l.url }
282
+ unless post.annotations.blank?
283
+ post.annotations.each do |ann|
284
+ if ann.type == "net.app.core.oembed"
285
+ if ann.value['embeddable_url']
286
+ links << ann.value['embeddable_url']
287
+ elsif ann.value['url'] && Settings.options.channels.links
288
+ links << ann.value['url']
310
289
  end
311
290
  end
312
291
  end
@@ -322,26 +301,26 @@ module Ayadn
322
301
  'origin' => origin,
323
302
  'args' => args,
324
303
  'created_at' => Time.now,
325
- 'username' => Settings.config[:identity][:handle]
304
+ 'username' => Settings.config.identity.handle
326
305
  },
327
306
  'data' => links
328
307
  }
329
- filename = "#{Settings.config[:identity][:handle]}_#{origin}_links.json"
308
+ filename = "#{Settings.config.identity.handle}_#{origin}_links.json"
330
309
  FileOps.save_links(obj, filename)
331
310
  @status.links_saved(filename)
332
311
  end
333
312
 
334
313
  def extract_hashtags(post)
335
- post['entities']['hashtags'].map { |h| h['name'] }
314
+ post.entities.hashtags.map { |h| h.name }
336
315
  end
337
316
 
338
317
  def extract_mentions(post)
339
- post['entities']['mentions'].map { |m| m['name'] }
318
+ post.entities.mentions.map { |m| m.name }
340
319
  end
341
320
 
342
- def build_channels(data, options = {})
321
+ def build_channels(stream, options = {})
343
322
  bucket = []
344
- data = [data] unless data.is_a?(Array)
323
+ stream = [stream] unless stream.is_a?(Array)
345
324
  if options[:channels]
346
325
  @status.say_yellow :downloading, "list of channels and their users credentials"
347
326
  @status.say_info "it could take a while if there are many results and users"
@@ -350,19 +329,21 @@ module Ayadn
350
329
  @status.say_info "users are recorded in a database for later filtering and analyzing"
351
330
  @status.say_info "it could take a while if there are many results"
352
331
  end
332
+
353
333
  chan = Struct.new(:id, :num_messages, :subscribers, :type, :owner, :annotations, :readers, :editors, :writers, :you_subscribed, :unread, :recent_message_id, :recent_message)
334
+
354
335
  no_user = {}
355
- @api = API.new
356
- data.each do |ch|
357
- unless ch['writers']['user_ids'].empty?
358
- @status.say_cyan :parsing, "channel #{ch['id']}"
336
+ api = API.new
337
+ stream.each do |ch|
338
+ unless ch.writers.user_ids.empty?
339
+ @status.say_cyan :parsing, "channel #{ch.id}"
359
340
  usernames = []
360
- ch['writers']['user_ids'].each do |id|
341
+ ch.writers.user_ids.each do |id|
361
342
  next if no_user[id]
362
343
  db = Databases.find_user_by_id(id)
363
344
  if db.nil?
364
345
  @status.say_yellow :downloading, "user #{id}"
365
- resp = @api.get_user(id)
346
+ resp = api.get_user(id)
366
347
 
367
348
  if resp['meta']['code'] != 200
368
349
  @status.say_error "can't get user #{id}'s data, skipping"
@@ -382,22 +363,26 @@ module Ayadn
382
363
  usernames << the_username
383
364
  end
384
365
  end
385
- usernames << Settings.config[:identity][:handle] unless usernames.length == 1 && usernames.first == Settings.config[:identity][:handle]
366
+ usernames << Settings.config.identity.handle unless usernames.length == 1 && usernames.first == Settings.config[:identity][:handle]
386
367
  writers = usernames.join(", ")
387
368
  else
388
- writers = Settings.config[:identity][:handle]
369
+ writers = Settings.config.identity.handle
389
370
  end
390
- if ch['has_unread']
371
+ if ch.has_unread
391
372
  unread = "This channel has unread message(s)"
392
373
  else
393
374
  unread = "No unread messages"
394
375
  end
395
- bucket << chan.new(ch['id'], ch['counts']['messages'], ch['counts']['subscribers'], ch['type'], ch['owner'], ch['annotations'], ch['readers'], ch['editors'], writers, ch['you_subscribed'], unread, ch['recent_message_id'], ch['recent_message'])
376
+ bucket << chan.new(ch.id, ch.counts.messages, ch.counts.subscribers, ch.type, ch.owner, ch.annotations, ch.readers, ch.editors, writers, ch.you_subscribed, unread, ch.recent_message_id, ch.recent_message)
396
377
  end
397
- puts "\e[H\e[2J"
378
+ clear_screen
398
379
  bucket
399
380
  end
400
381
 
382
+ def clear_screen
383
+ puts "\e[H\e[2J"
384
+ end
385
+
401
386
  def parsed_time(string)
402
387
  "#{string[0...10]} #{string[11...19]}"
403
388
  end
@@ -513,8 +498,8 @@ module Ayadn
513
498
  reg_sentence = '^.+[\r\n]*'
514
499
  handles, words, sentences = [], [], []
515
500
  mentions.each {|username| handles << "@#{username}"}
516
- hashtag_color = Settings.options[:colors][:hashtags]
517
- mention_color = Settings.options[:colors][:mentions]
501
+ hashtag_color = Settings.options.colors.hashtags
502
+ mention_color = Settings.options.colors.mentions
518
503
  text.scan(/#{reg_sentence}/) do |sentence|
519
504
  sentence.split(' ').each do |word|
520
505
 
@@ -537,7 +522,7 @@ module Ayadn
537
522
  slices.each do |tag|
538
523
  has_h = true if hashtags.include?(tag.downcase.scan(/[[:alpha:]0-9_]/).join(''))
539
524
  end
540
- if has_h == true
525
+ if has_h
541
526
  if slices.length > 1
542
527
  words << slices.join('#').gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
543
528
  else
@@ -569,7 +554,7 @@ module Ayadn
569
554
  sentences << words.join(' ')
570
555
  words = Array.new
571
556
  end
572
- if Settings.options[:timeline][:compact] == true
557
+ if Settings.options.timeline.compact
573
558
  without_linebreaks = sentences.keep_if { |s| s != "" }
574
559
  without_linebreaks.join("\n")
575
560
  else
@@ -579,14 +564,14 @@ module Ayadn
579
564
 
580
565
  def links_from_posts(stream)
581
566
  links = []
582
- stream['data'].each do |post|
567
+ stream.posts.each do |post|
583
568
  extract_links(post).each {|l| links << l}
584
569
  end
585
570
  links.uniq
586
571
  end
587
572
 
588
573
  def all_but_me usernames
589
- arr = usernames.select {|user| user != 'me'}
574
+ arr = usernames.select { |user| user != 'me' && user != Settings.config.identity.username }
590
575
  at(arr)
591
576
  end
592
577
 
@@ -596,6 +581,18 @@ module Ayadn
596
581
 
597
582
  private
598
583
 
584
+ def build_reposted_or_starred_list list, title
585
+ table = init_table
586
+ table.title = title
587
+ users_list = []
588
+ list.each do |obj|
589
+ obj['name'].nil? ? name = "" : name = obj['name'].to_s.force_encoding("UTF-8")
590
+ users_list << {:username => obj['username'], :name => name, :you_follow => obj['you_follow'], :follows_you => obj['follows_you'], :id => obj['id'], :posts => obj['counts']['posts']}
591
+ end
592
+ table.style = table_borders()
593
+ return users_list, table
594
+ end
595
+
599
596
  def def_str(word, reg_split)
600
597
  splitted = word.split(/#{reg_split}/) if word =~ /#{reg_split}/
601
598
  if splitted
@@ -609,7 +606,7 @@ module Ayadn
609
606
 
610
607
  def init_table
611
608
  Terminal::Table.new do |t|
612
- t.style = { :width => Settings.options[:formats][:table][:width] }
609
+ t.style = { :width => Settings.options.formats.table.width }
613
610
  end
614
611
  end
615
612
 
@@ -623,38 +620,39 @@ module Ayadn
623
620
  def extract_checkins(post)
624
621
  has_checkins = false
625
622
  checkins = {}
626
- unless post['annotations'].nil? || post['annotations'].empty?
627
- post['annotations'].each do |obj|
628
- case obj['type']
623
+ unless post.annotations.blank?
624
+ post.annotations.each do |anno|
625
+ anno_value = anno.value
626
+ case anno.type
629
627
  when "net.app.core.checkin", "net.app.ohai.location"
630
628
  has_checkins = true
631
629
  checkins = {
632
- name: obj['value']['name'],
633
- address: obj['value']['address'],
634
- address_extended: obj['value']['address_extended'],
635
- locality: obj['value']['locality'],
636
- postcode: obj['value']['postcode'],
637
- country_code: obj['value']['country_code'],
638
- website: obj['value']['website'],
639
- telephone: obj['value']['telephone']
630
+ name: anno_value['name'],
631
+ address: anno_value['address'],
632
+ address_extended: anno_value['address_extended'],
633
+ locality: anno_value['locality'],
634
+ postcode: anno_value['postcode'],
635
+ country_code: anno_value['country_code'],
636
+ website: anno_value['website'],
637
+ telephone: anno_value['telephone']
640
638
  }
641
- unless obj['value']['categories'].nil?
642
- unless obj['value']['categories'][0].nil?
643
- checkins[:categories] = obj['value']['categories'][0]['labels'].join(", ")
639
+ unless anno_value['categories'].nil?
640
+ unless anno_value['categories'][0].nil?
641
+ checkins[:categories] = anno_value['categories'][0]['labels'].join(", ")
644
642
  end
645
643
  end
646
- unless obj['value']['factual_id'].nil?
647
- checkins[:factual_id] = obj['value']['factual_id']
644
+ unless anno_value['factual_id'].nil?
645
+ checkins[:factual_id] = anno_value['factual_id']
648
646
  end
649
- unless obj['value']['longitude'].nil?
650
- checkins[:longitude] = obj['value']['longitude']
651
- checkins[:latitude] = obj['value']['latitude']
647
+ unless anno_value['longitude'].nil?
648
+ checkins[:longitude] = anno_value['longitude']
649
+ checkins[:latitude] = anno_value['latitude']
652
650
  end
653
- unless obj['value']['title'].nil?
654
- checkins[:title] = obj['value']['title']
651
+ unless anno_value['title'].nil?
652
+ checkins[:title] = anno_value['title']
655
653
  end
656
- unless obj['value']['region'].nil?
657
- checkins[:region] = obj['value']['region']
654
+ unless anno_value['region'].nil?
655
+ checkins[:region] = anno_value['region']
658
656
  end
659
657
  end
660
658
  end