ayadn 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.5.1"
3
+ VERSION = "1.6.0"
4
4
  end
data/lib/ayadn/view.rb CHANGED
@@ -17,6 +17,13 @@ module Ayadn
17
17
  puts resp unless resp == ""
18
18
  end
19
19
 
20
+ def if_raw what, options
21
+ if options[:raw]
22
+ show_raw(what, options)
23
+ exit
24
+ end
25
+ end
26
+
20
27
  def show_raw(stream, options = {})
21
28
  #puts stream.to_json
22
29
  jj stream
@@ -259,7 +266,7 @@ module Ayadn
259
266
  end
260
267
  unless ch.recent_message.nil?
261
268
  unless ch.recent_message['text'].nil?
262
- view << "Most recent message (#{Workers.new.parsed_time(ch.recent_message['created_at'])}): ".color(:cyan)
269
+ view << "Most recent message (#{@workers.parsed_time(ch.recent_message['created_at'])}): ".color(:cyan)
263
270
  view << "\n"
264
271
  view << "---\n#{ch.recent_message['text']}\n---"
265
272
  end
@@ -276,6 +283,28 @@ module Ayadn
276
283
  puts view
277
284
  end
278
285
 
286
+ def render(stream, options = {}, niceranks = {})
287
+ unless options[:raw]
288
+ get(stream['data'], options, niceranks)
289
+ else
290
+ show_raw(stream)
291
+ end
292
+ end
293
+
294
+ def get(stream, options = {}, niceranks = {})
295
+ clear_screen()
296
+ if options[:index]
297
+ show_posts_with_index(stream, options, niceranks)
298
+ else
299
+ show_posts(stream, options, niceranks)
300
+ end
301
+ end
302
+
303
+ def get_simple_view(stream)
304
+ clear_screen()
305
+ show_simple_stream(stream)
306
+ end
307
+
279
308
  def clear_screen
280
309
  puts "\e[H\e[2J"
281
310
  end
@@ -286,6 +315,62 @@ module Ayadn
286
315
  puts "\n"
287
316
  end
288
317
 
318
+ def winsize
319
+ IO.console.winsize
320
+ end
321
+
322
+ def show_links(links)
323
+ links.each {|l| puts "#{l}\n".color(Settings.options[:colors][:link])}
324
+ end
325
+
326
+ def all_hashtag_links(stream, hashtag)
327
+ clear_screen()
328
+ puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan)
329
+ show_links(@workers.links_from_posts(stream))
330
+ end
331
+
332
+ def all_search_links(stream, words)
333
+ clear_screen()
334
+ puts "Links from posts containing word(s) '#{words}': \n".color(:cyan)
335
+ show_links(@workers.links_from_posts(stream))
336
+ end
337
+
338
+ def all_stars_links(stream)
339
+ clear_screen()
340
+ puts "Links from your starred posts: \n".color(:cyan)
341
+ show_links(@workers.links_from_posts(stream))
342
+ end
343
+
344
+ def infos(stream, token)
345
+ clear_screen()
346
+ show_userinfos(stream, token, true)
347
+ end
348
+
349
+ def downloading(options = {})
350
+ unless options[:raw]
351
+ clear_screen()
352
+ print Status.downloading
353
+ end
354
+ end
355
+
356
+ def list(what, list, target)
357
+ clear_screen()
358
+ case what
359
+ when :whoreposted
360
+ show_list_reposted(list, target)
361
+ when :whostarred
362
+ show_list_starred(list, target)
363
+ when :followings
364
+ show_list_followings(list, target)
365
+ when :followers
366
+ show_list_followers(list, target)
367
+ when :muted
368
+ show_list_muted(list)
369
+ when :blocked
370
+ show_list_blocked(list)
371
+ end
372
+ end
373
+
289
374
  def big_separator
290
375
  "----------\n\n\n"
291
376
  end
data/lib/ayadn/workers.rb CHANGED
@@ -81,7 +81,7 @@ module Ayadn
81
81
  end
82
82
 
83
83
  def build_users_list(list, table)
84
- users = Workers.at(list.map {|obj| obj[:username]})
84
+ users = at(list.map {|obj| obj[:username]})
85
85
  ids = list.map {|obj| obj[:id].to_i}
86
86
  ranks = NiceRank.new.from_ids(ids)
87
87
  indexed_ranks = {}
@@ -302,7 +302,7 @@ module Ayadn
302
302
  "#{string[0...10]} #{string[11...19]}"
303
303
  end
304
304
 
305
- def self.at usernames
305
+ def at usernames #TODO: consolidate
306
306
  usernames.map do |user|
307
307
  if user == 'me'
308
308
  'me'
@@ -314,7 +314,52 @@ module Ayadn
314
314
  end
315
315
  end
316
316
 
317
- def self.add_arobase_if_missing(username) # expects an array of username(s), works on the first one and outputs a string
317
+ def get_original_id(post_id, resp)
318
+ if resp['data']['repost_of']
319
+ puts Status.redirecting
320
+ id = resp['data']['repost_of']['id']
321
+ Errors.repost(post_id, id)
322
+ return id
323
+ else
324
+ return post_id
325
+ end
326
+ end
327
+
328
+ def get_channel_id_from_alias(channel_id)
329
+ unless channel_id.is_integer?
330
+ orig = channel_id
331
+ channel_id = Databases.get_channel_id(orig)
332
+ if channel_id.nil?
333
+ Errors.warn("Alias '#{orig}' doesn't exist.")
334
+ puts Status.no_alias
335
+ exit
336
+ end
337
+ end
338
+ channel_id
339
+ end
340
+
341
+ def length_of_index
342
+ Databases.get_index_length
343
+ end
344
+
345
+ def get_post_from_index id
346
+ Databases.get_post_from_index id
347
+ end
348
+
349
+ def get_real_post_id post_id
350
+ id = post_id.to_i
351
+ if id > 0 && id <= length_of_index
352
+ resp = get_post_from_index(id)
353
+ post_id = resp[:id]
354
+ end
355
+ post_id
356
+ end
357
+
358
+ def add_arobase username
359
+ add_arobase_if_missing(username)
360
+ end
361
+
362
+ def add_arobase_if_missing(username) # expects an array of username(s), works on the first one and outputs a string
318
363
  unless username.first == "me"
319
364
  username = username.first.chars
320
365
  username.unshift("@") unless username.first == "@"
@@ -324,26 +369,25 @@ module Ayadn
324
369
  username.join
325
370
  end
326
371
 
327
- def self.add_arobases_to_usernames args
328
- args.map! do |username|
372
+ def add_arobases_to_usernames args #TODO: replace
373
+ args.map do |username|
329
374
  if username == 'me'
330
- self.who_am_i
375
+ who_am_i
331
376
  else
332
377
  temp = username.chars
333
378
  temp.unshift("@") unless temp.first == "@"
334
379
  temp.join
335
380
  end
336
381
  end
337
- args
338
382
  end
339
383
 
340
- def self.who_am_i
384
+ def who_am_i
341
385
  db = Databases.init(Dir.home + "/ayadn/accounts.db")
342
386
  active = db['ACTIVE']
343
387
  db[active][:handle]
344
388
  end
345
389
 
346
- def self.remove_arobase_if_present args
390
+ def remove_arobase_if_present args
347
391
  args.map! do |username|
348
392
  temp = username.chars
349
393
  temp.shift if temp.first == "@"
@@ -352,7 +396,7 @@ module Ayadn
352
396
  args
353
397
  end
354
398
 
355
- def self.extract_users(resp)
399
+ def extract_users(resp)
356
400
  users_hash = {}
357
401
  resp['data'].each do |item|
358
402
  users_hash[item['id']] = [item['username'], item['name'], item['you_follow'], item['follows_you']]
@@ -424,6 +468,20 @@ module Ayadn
424
468
  sentences.join("\n")
425
469
  end
426
470
 
471
+ def links_from_posts(stream)
472
+ links = []
473
+ stream['data'].each do |post|
474
+ extract_links(post).each {|l| links << l}
475
+ end
476
+ links.uniq!
477
+ links
478
+ end
479
+
480
+ def all_but_me usernames
481
+ arr = usernames.select {|user| user != 'me'}
482
+ at(arr)
483
+ end
484
+
427
485
  private
428
486
 
429
487
  def def_str(word, reg_split)
@@ -444,11 +502,9 @@ module Ayadn
444
502
  end
445
503
 
446
504
  def build_users_array(list)
447
- users_list = []
448
- list.each do |key, value|
449
- users_list << {:username => value[0], :name => value[1], :you_follow => value[2], :follows_you => value[3], :id => key}
505
+ list.map do |key, value|
506
+ {:username => value[0], :name => value[1], :you_follow => value[2], :follows_you => value[3], :id => key}
450
507
  end
451
- users_list
452
508
  end
453
509
 
454
510
  def extract_checkins(post)
@@ -100,20 +100,4 @@ describe Ayadn::View do
100
100
  end
101
101
  end
102
102
 
103
- # let(:followers) { JSON.parse(File.read("spec/mock/fwr_@ayadn.json")) }
104
-
105
- # describe "#show_list_followers" do
106
- # it "outputs the list of followers" do
107
- # list = Ayadn::Workers.extract_users(followers[0])
108
- # printed = capture_stdout do
109
- # Ayadn::View.new.show_list_followers(list, '@ayadn')
110
- # end
111
- # expect(printed).to include "@ericd"
112
- # expect(printed).to include "Nicolas Maumont"
113
- # end
114
- # end
115
-
116
-
117
-
118
-
119
103
  end
@@ -17,6 +17,7 @@ describe Ayadn::Workers do
17
17
  Ayadn::Logs.stub(:rec).and_return("logged")
18
18
  Ayadn::Databases.stub(:blacklist).and_return("blacklist")
19
19
  Ayadn::Databases.stub(:users).and_return("users")
20
+ @workers = Ayadn::Workers.new
20
21
  end
21
22
 
22
23
  let(:data) { JSON.parse(File.read("spec/mock/stream.json")) }
@@ -25,7 +26,7 @@ describe Ayadn::Workers do
25
26
 
26
27
  describe "#build_posts" do
27
28
  it "builds posts hash from stream" do
28
- posts = Ayadn::Workers.new.build_posts(data['data'])
29
+ posts = @workers.build_posts(data['data'])
29
30
  expect(posts.length).to eq 10
30
31
  expect(posts[23187363][:name]).to eq 'App.net Staff'
31
32
  expect(posts[23184500][:username]).to eq 'wired'
@@ -44,7 +45,7 @@ describe Ayadn::Workers do
44
45
  expect(posts[23187443].length).to eq 33
45
46
  end
46
47
  it "gets oembed link from checkins post" do
47
- posts = Ayadn::Workers.new.build_posts(checkins['data'])
48
+ posts = @workers.build_posts(checkins['data'])
48
49
  expect(posts[27101186][:links]).to eq ["https://photos.app.net/27101186/1"]
49
50
  expect(posts[27080492][:links]).to eq ["http://sprintr.co/27080492"]
50
51
  expect(posts[27073989][:links]).to eq ["http://pic.favd.net/27073989", "https://photos.app.net/27073989/1"]
@@ -53,21 +54,21 @@ describe Ayadn::Workers do
53
54
 
54
55
  describe "#extract_hashtags" do
55
56
  it "extracts hashtags" do
56
- tags = Ayadn::Workers.new.extract_hashtags(data['data'][0])
57
+ tags = @workers.extract_hashtags(data['data'][0])
57
58
  expect(tags).to eq ['photography']
58
59
  end
59
60
  end
60
61
 
61
62
  describe "#extract_links" do
62
63
  it "extracts links" do
63
- links = Ayadn::Workers.new.extract_links(data['data'][0])
64
+ links = @workers.extract_links(data['data'][0])
64
65
  expect(links).to eq ['http://feed.500px.com/~r/500px-best/~3/c2tMPEJVf6I/61517259']
65
66
  end
66
67
  end
67
68
 
68
69
  describe "#extract_checkins" do
69
70
  it "extracts checkins" do
70
- posts = Ayadn::Workers.new.build_posts(checkins['data'])
71
+ posts = @workers.build_posts(checkins['data'])
71
72
  expect(posts.length).to eq 10
72
73
  expect(posts[27101186][:has_checkins]).to be true
73
74
  expect(posts[27101186][:checkins][:name]).to eq "Hobbs State Park"
@@ -86,7 +87,7 @@ describe Ayadn::Workers do
86
87
  # describe "#build_followers_list" do
87
88
  # it 'builds the followers table list' do
88
89
  # printed = capture_stdout do
89
- # puts Ayadn::Workers.new.build_followers_list(list, "@test")
90
+ # puts @workers.build_followers_list(list, "@test")
90
91
  # end
91
92
  # expect(printed).to include "@test"
92
93
  # expect(printed).to include "@bond"
@@ -97,7 +98,7 @@ describe Ayadn::Workers do
97
98
  # describe "#build_followings_list" do
98
99
  # it 'builds the followings table list' do
99
100
  # printed = capture_stdout do
100
- # puts Ayadn::Workers.new.build_followings_list(list, "@test")
101
+ # puts @workers.build_followings_list(list, "@test")
101
102
  # end
102
103
  # #expect(printed).to include "+~~~~"
103
104
  # expect(printed).to include "@test"
@@ -109,7 +110,7 @@ describe Ayadn::Workers do
109
110
  # describe "#build_muted_list" do
110
111
  # it 'builds the muted table list' do
111
112
  # printed = capture_stdout do
112
- # puts Ayadn::Workers.new.build_muted_list(list)
113
+ # puts @workers.build_muted_list(list)
113
114
  # end
114
115
  # #expect(printed).to include "+----"
115
116
  # expect(printed).to include "@bond"
@@ -120,7 +121,7 @@ describe Ayadn::Workers do
120
121
  # describe "#build_blocked_list" do
121
122
  # it 'builds the blocked table list' do
122
123
  # printed = capture_stdout do
123
- # puts Ayadn::Workers.new.build_blocked_list(list)
124
+ # puts @workers.build_blocked_list(list)
124
125
  # end
125
126
  # #expect(printed).to include "+----"
126
127
  # expect(printed).to include "@bond"
@@ -128,19 +129,19 @@ describe Ayadn::Workers do
128
129
  # end
129
130
  # end
130
131
 
131
- describe ".add_arobase_if_missing" do
132
+ describe "#add_arobase_if_missing" do
132
133
  it 'adds @ to username' do
133
- expect(Ayadn::Workers.add_arobase_if_missing(["user"])).to eq "@user"
134
+ expect(@workers.add_arobase_if_missing(["user"])).to eq "@user"
134
135
  end
135
136
  it 'does nothing to @username' do
136
- expect(Ayadn::Workers.add_arobase_if_missing(["@user"])).to eq "@user"
137
+ expect(@workers.add_arobase_if_missing(["@user"])).to eq "@user"
137
138
  end
138
139
  end
139
140
 
140
- describe ".remove_arobase_if_present" do
141
+ describe "#remove_arobase_if_present" do
141
142
  it "removes @ from username" do
142
- expect(Ayadn::Workers.remove_arobase_if_present(["@user"])).to eq ["user"]
143
- expect(Ayadn::Workers.remove_arobase_if_present(["user"])).to eq ["user"]
143
+ expect(@workers.remove_arobase_if_present(["@user"])).to eq ["user"]
144
+ expect(@workers.remove_arobase_if_present(["user"])).to eq ["user"]
144
145
  end
145
146
  end
146
147
 
@@ -148,7 +149,7 @@ describe Ayadn::Workers do
148
149
  it "colorizes mentions and hashtags" do
149
150
  text = regex_post['data']['text']
150
151
  mentions = regex_post['data']['entities']['mentions']
151
- expect(Ayadn::Workers.new.colorize_text(text, mentions, ['false', 'true', 'test', 'regex'])).to eq "\e[36m#test\e[0m \e[36m#regex\e[0m\n@aya_tests's \e[36m#true\e[0m\n(@aya_tests) \e[36m#true\e[0m\n@AyA_TeSts \e[36m#true\e[0m\n@aya_test \e[36m#false\e[0m\naya@aya_tests.yolo \e[36m#false\e[0m\n-@aya_tests:ohai! \e[36m#true\e[0m\ntext,@aya_tests,txt \e[36m#true\e[0m"
152
+ expect(@workers.colorize_text(text, mentions, ['false', 'true', 'test', 'regex'])).to eq "\e[36m#test\e[0m \e[36m#regex\e[0m\n@aya_tests's \e[36m#true\e[0m\n(@aya_tests) \e[36m#true\e[0m\n@AyA_TeSts \e[36m#true\e[0m\n@aya_test \e[36m#false\e[0m\naya@aya_tests.yolo \e[36m#false\e[0m\n-@aya_tests:ohai! \e[36m#true\e[0m\ntext,@aya_tests,txt \e[36m#true\e[0m"
152
153
  end
153
154
  end
154
155
 
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.5.1
4
+ version: 1.6.0
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-07-25 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: spotlite
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: tvdb_party
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.7'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.7'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: bundler
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -229,9 +257,11 @@ files:
229
257
  - doc/13-bookmark.md
230
258
  - doc/14-set.md
231
259
  - doc/15-nowplaying.md
232
- - doc/16-contact.md
233
- - doc/17-shortcuts.md
234
- - doc/18-examples.md
260
+ - doc/16-movie.md
261
+ - doc/17-tvshow.md
262
+ - doc/18-contact.md
263
+ - doc/19-examples.md
264
+ - doc/shortcuts.md
235
265
  - lib/ayadn.rb
236
266
  - lib/ayadn/action.rb
237
267
  - lib/ayadn/alias.rb
@@ -239,6 +269,7 @@ files:
239
269
  - lib/ayadn/app.rb
240
270
  - lib/ayadn/authorize.rb
241
271
  - lib/ayadn/blacklist.rb
272
+ - lib/ayadn/check.rb
242
273
  - lib/ayadn/cnx.rb
243
274
  - lib/ayadn/databases.rb
244
275
  - lib/ayadn/debug.rb
@@ -250,13 +281,18 @@ files:
250
281
  - lib/ayadn/logs.rb
251
282
  - lib/ayadn/mark.rb
252
283
  - lib/ayadn/nicerank.rb
284
+ - lib/ayadn/nowplaying.rb
285
+ - lib/ayadn/nowwatching.rb
253
286
  - lib/ayadn/pinboard.rb
254
287
  - lib/ayadn/post.rb
255
288
  - lib/ayadn/scroll.rb
289
+ - lib/ayadn/search.rb
256
290
  - lib/ayadn/set.rb
257
291
  - lib/ayadn/settings.rb
258
292
  - lib/ayadn/status.rb
293
+ - lib/ayadn/stream.rb
259
294
  - lib/ayadn/switch.rb
295
+ - lib/ayadn/tvshow.rb
260
296
  - lib/ayadn/version.rb
261
297
  - lib/ayadn/view.rb
262
298
  - lib/ayadn/workers.rb