ayadn 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/switch.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
3
  class Switch
4
+
4
5
  def list
5
6
  home_path = Dir.home + "/ayadn"
6
7
  if File.exist?("#{home_path}/accounts.db")
@@ -24,6 +25,7 @@ module Ayadn
24
25
  please
25
26
  end
26
27
  end
28
+
27
29
  def switch(user)
28
30
  if user.empty? || user.nil?
29
31
  puts "\n\nOops, something went wrong, I couldn't get your username. Please try again.\n\n".color(:red)
data/lib/ayadn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.2.8"
3
+ VERSION = "1.2.9"
4
4
  end
data/lib/ayadn/view.rb CHANGED
@@ -23,8 +23,7 @@ module Ayadn
23
23
  end
24
24
 
25
25
  def show_simple_post(post, options)
26
- view = build_stream_without_index(post, options, {})
27
- puts view
26
+ puts build_stream_without_index(post, options, {})
28
27
  end
29
28
 
30
29
  def show_posted(resp)
@@ -268,15 +267,21 @@ module Ayadn
268
267
  puts "\e[H\e[2J"
269
268
  end
270
269
 
270
+ def page msg
271
+ clear_screen
272
+ puts msg
273
+ puts "\n"
274
+ end
275
+
276
+ def big_separator
277
+ "----------\n\n\n"
278
+ end
279
+
271
280
  private
272
281
 
273
282
  def get_broadcast_alias_from_id(event_id)
274
283
  al = Databases.get_alias_from_id(event_id)
275
- unless al.nil?
276
- al
277
- else
278
- event_id
279
- end
284
+ al.nil? ? event_id : al
280
285
  end
281
286
 
282
287
  def filter_nicerank posts, options
@@ -305,10 +310,7 @@ module Ayadn
305
310
 
306
311
  def build_stream_with_index(data, options, niceranks) #expects an array
307
312
  @view = ""
308
- posts = @workers.build_posts(data.reverse, niceranks)
309
-
310
- posts = filter_nicerank(posts, options)
311
-
313
+ posts = filter_nicerank(@workers.build_posts(data.reverse, niceranks), options)
312
314
  posts.each do |id,content|
313
315
  count = "%03d" % content[:count]
314
316
  if content[:username] == Settings.config[:identity][:username]
@@ -326,10 +328,7 @@ module Ayadn
326
328
 
327
329
  def build_stream_without_index(data, options, niceranks) #expects an array
328
330
  @view = ""
329
- posts = @workers.build_posts(data.reverse, niceranks)
330
-
331
- posts = filter_nicerank(posts, options)
332
-
331
+ posts = filter_nicerank(@workers.build_posts(data.reverse, niceranks), options)
333
332
  posts.each do |id,content|
334
333
  if content[:username] == Settings.config[:identity][:username]
335
334
  @view << content[:id].to_s.color(Settings.options[:colors][:id]).inverse + " "
data/lib/ayadn/workers.rb CHANGED
@@ -5,18 +5,14 @@ module Ayadn
5
5
  def build_aliases_list(list)
6
6
  table = init_table
7
7
  table.title = "List of your channel aliases".color(:cyan) + "".color(:white)
8
- list.each do |k,v|
9
- table << ["#{k}".color(:green), "#{v}".color(:red)]
10
- end
8
+ list.each {|k,v| table << ["#{k}".color(:green), "#{v}".color(:red)]}
11
9
  table
12
10
  end
13
11
 
14
12
  def build_blacklist_list(list)
15
13
  table = init_table
16
14
  table.title = "Your blacklist".color(:cyan) + "".color(:white)
17
- list.each do |k,v|
18
- table << ["#{v.capitalize}".color(:green), "#{k}".color(:red)]
19
- end
15
+ list.each {|k,v| table << ["#{v.capitalize}".color(:green), "#{k}".color(:red)]}
20
16
  table
21
17
  end
22
18
 
@@ -44,10 +40,10 @@ module Ayadn
44
40
 
45
41
  def build_followings_list(list, target) #takes a hash of users with ayadn format
46
42
  table = init_table
47
- if target == "me"
48
- table.title = "List of users you're following".color(:cyan) + "".color(:white)
43
+ table.title = if target == "me"
44
+ "List of users you're following".color(:cyan) + "".color(:white)
49
45
  else
50
- table.title = "List of users ".color(:cyan) + "#{target}".color(:red) + " is following ".color(:cyan) + "".color(:white)
46
+ "List of users ".color(:cyan) + "#{target}".color(:red) + " is following ".color(:cyan) + "".color(:white)
51
47
  end
52
48
  users_list = build_users_array(list)
53
49
  build_users_list(users_list, table)
@@ -55,27 +51,24 @@ module Ayadn
55
51
 
56
52
  def build_followers_list(list, target)
57
53
  table = init_table
58
- if target == "me"
59
- table.title = "List of your followers".color(:cyan) + "".color(:white)
54
+ table.title = if target == "me"
55
+ "List of your followers".color(:cyan) + "".color(:white)
60
56
  else
61
- table.title = "List of users following ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
57
+ "List of users following ".color(:cyan) + "#{target}".color(:red) + "".color(:white)
62
58
  end
63
- users_list = build_users_array(list)
64
- build_users_list(users_list, table)
59
+ build_users_list(build_users_array(list), table)
65
60
  end
66
61
 
67
62
  def build_muted_list(list)
68
63
  table = init_table
69
64
  table.title = "List of users you muted".color(:cyan) + "".color(:white)
70
- users_list = build_users_array(list)
71
- build_users_list(users_list, table)
65
+ build_users_list(build_users_array(list), table)
72
66
  end
73
67
 
74
68
  def build_blocked_list(list)
75
69
  table = init_table
76
70
  table.title = "List of users you blocked".color(:cyan) + "".color(:white)
77
- users_list = build_users_array(list)
78
- build_users_list(users_list, table)
71
+ build_users_list(build_users_array(list), table)
79
72
  end
80
73
 
81
74
  def build_users_list(list, table)
@@ -146,12 +139,14 @@ module Ayadn
146
139
  you_starred: post['you_starred'],
147
140
  source_name: source,
148
141
  source_link: post['source']['link'],
149
- canonical_url: post['canonical_url']
142
+ canonical_url: post['canonical_url'],
143
+ tags: hashtags,
144
+ links: extract_links(post),
145
+ mentions: mentions,
146
+ directed_to: mentions.first || false
150
147
  }
151
148
 
152
- values[:tags] = hashtags
153
-
154
- values[:links] = extract_links(post)
149
+ values[:checkins], values[:has_checkins] = extract_checkins(post)
155
150
 
156
151
  if post['repost_of']
157
152
  values[:is_repost] = true
@@ -194,10 +189,6 @@ module Ayadn
194
189
  values[:num_reposts] = 0
195
190
  end
196
191
 
197
- values[:mentions] = mentions
198
- values[:directed_to] = mentions.first || false
199
- values[:checkins], values[:has_checkins] = extract_checkins(post)
200
-
201
192
  posts[post['id'].to_i] = values
202
193
 
203
194
  end
@@ -225,12 +216,14 @@ module Ayadn
225
216
  end
226
217
 
227
218
  def build_channels(data, options = {})
228
- channels = []
229
- data.each { |ch| channels << ch }
230
219
  bucket = []
231
- puts "Downloading new channels and unknown users ids.\nThis is a one time operation, ids are being recorded in a database.\n\nPlease wait, it could take a while if you have many channels...".color(:cyan) unless options[:channels]
220
+ if options[:channels]
221
+ puts "Downloading list of channels and their users credentials.\n\nPlease wait, it could take a while if there are many results and users...".color(:cyan)
222
+ else
223
+ puts "Downloading new channels and unknown users ids.\nThis is a one time operation, ids are being recorded in a database.\n\nPlease wait, it could take a while if you have many channels...".color(:cyan)
224
+ end
232
225
  chan = Struct.new(:id, :num_messages, :subscribers, :type, :owner, :annotations, :readers, :editors, :writers, :you_subscribed, :unread, :recent_message_id, :recent_message)
233
- channels.each do |ch|
226
+ data.each do |ch|
234
227
  unless ch['writers']['user_ids'].empty?
235
228
  usernames = []
236
229
  ch['writers']['user_ids'].each do |id|
@@ -315,27 +308,33 @@ module Ayadn
315
308
  reg_tag = '#([[:alpha:]0-9_]{1,255})(?![\w+])'
316
309
  reg_mention = '@([A-Za-z0-9_]{1,20})(?![\w+])'
317
310
  reg_sentence = '^.+[\r\n]*'
318
- handles = Array.new
311
+ handles, words, sentences = [], [], []
319
312
  mentions.each {|username| handles << "@#{username}"}
320
- words = Array.new
321
- sentences = Array.new
322
313
  hashtag_color = Settings.options[:colors][:hashtags]
323
314
  mention_color = Settings.options[:colors][:mentions]
324
315
  text.scan(/#{reg_sentence}/) do |sentence|
325
316
  sentence.split(' ').each do |word|
317
+
318
+ word_chars = word.chars
319
+ sanitized, word = [], []
320
+ word_chars.each do |ch|
321
+ if UnicodeUtils.general_category(ch) == :Other_Symbol
322
+ sanitized << "#{ch} "
323
+ else
324
+ sanitized << ch
325
+ end
326
+ end
327
+ word = sanitized.join
328
+
326
329
  if word =~ /#\w+/
327
330
  slices = word.split('#')
328
331
  has_h = false
329
332
  slices.each do |tag|
330
- bit = tag.downcase.scan(/[[:alpha:]0-9_]/).join('')
331
- if hashtags.include? bit
332
- has_h = true
333
- end
333
+ has_h = true if hashtags.include?(tag.downcase.scan(/[[:alpha:]0-9_]/).join(''))
334
334
  end
335
335
  if has_h == true
336
336
  if slices.length > 1
337
- word = slices.join('#')
338
- words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
337
+ words << slices.join('#').gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
339
338
  else
340
339
  words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
341
340
  end
@@ -343,12 +342,21 @@ module Ayadn
343
342
  words << word
344
343
  end
345
344
  elsif word =~ /@\w+/
346
- @str = def_str(word, reg_split)
347
- if handles.include?(@str.downcase)
348
- words << word.gsub(/#{reg_mention}/, '@\1'.color(mention_color))
349
- else
350
- words << word
345
+ enc = []
346
+ warr = word.split(' ')
347
+ warr.each do |w|
348
+ @str = def_str(w, reg_split)
349
+ if handles.include?(@str.downcase)
350
+ if warr.length == 1
351
+ enc << w.gsub(/#{reg_mention}/, '@\1'.color(mention_color))
352
+ else
353
+ enc << " #{w.gsub(/#{reg_mention}/, '@\1'.color(mention_color))}"
354
+ end
355
+ else
356
+ enc << w
357
+ end
351
358
  end
359
+ words << enc.join
352
360
  else
353
361
  words << word
354
362
  end
data/lib/ayadn.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require_relative 'ayadn/version'
3
3
 
4
- %w{rest_client json thor rainbow/ext/string terminal-table yaml logger daybreak fileutils io/console}.each { |r| require "#{r}" }
4
+ %w{rest_client json thor rainbow/ext/string terminal-table yaml logger daybreak fileutils io/console unicode_utils/char_type}.each { |r| require "#{r}" }
5
5
 
6
6
  # winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
7
7
  # case Gem::Platform.local.os
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ayadn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -209,6 +209,7 @@ files:
209
209
  - lib/ayadn/blacklist.rb
210
210
  - lib/ayadn/cnx.rb
211
211
  - lib/ayadn/databases.rb
212
+ - lib/ayadn/debug.rb
212
213
  - lib/ayadn/descriptions.rb
213
214
  - lib/ayadn/endpoints.rb
214
215
  - lib/ayadn/errors.rb