Class: Ayadn::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAction

Returns a new instance of Action.



5
6
7
8
9
10
11
12
13
14
# File 'lib/ayadn/action.rb', line 5

def initialize
  @api = API.new
  @view = View.new
  Settings.load_config
  Settings.get_token
  Settings.init_config
  Logs.create_logger
  Databases.open_databases
  at_exit { Databases.close_all }
end

Class Method Details

.quit(msg) ⇒ Object



1397
1398
1399
1400
# File 'lib/ayadn/action.rb', line 1397

def self.quit msg
  puts msg
  exit
end

Instance Method Details

#auto(options) ⇒ Object



651
652
653
654
655
656
657
658
659
# File 'lib/ayadn/action.rb', line 651

def auto(options)
  begin
    @view.clear_screen
    puts Status.auto
    Post.new.auto_readline
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#block(usernames) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/ayadn/action.rb', line 321

def block(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.blocking(users.join(','))
    users.each do |user|
      resp = @api.block(user)
      check_has_been_blocked(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#blocked(options) ⇒ Object



495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/ayadn/action.rb', line 495

def blocked(options)
  begin
    doing(options)
    if_raw_list(nil, :blocked, options)
    list = @api.get_blocked
    no_data('blocked') if list.empty?
    get_list(:blocked, list, nil)
    Databases.add_to_users_db_from_list(list)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#channelsObject



594
595
596
597
598
599
600
601
602
603
# File 'lib/ayadn/action.rb', line 594

def channels
  begin
    doing()
    resp = @api.get_channels
    @view.clear_screen
    @view.show_channels(resp)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [resp['meta']]})
  end
end

#checkins(options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ayadn/action.rb', line 29

def checkins(options)
  begin
    doing(options)
    stream = @api.get_checkins(options)
    stop_if_no_new_posts(stream, options, 'explore:checkins')
    Databases.save_max_id(stream)
    render_view(stream, options)
    Scroll.new(@api, @view).checkins(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#conversations(options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ayadn/action.rb', line 84

def conversations(options)
  begin
    doing(options)
    stream = @api.get_conversations(options)
    stop_if_no_new_posts(stream, options, 'explore:replies')
    Databases.save_max_id(stream)
    render_view(stream, options)
    Scroll.new(@api, @view).replies(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#convo(post_id, options) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/ayadn/action.rb', line 195

def convo(post_id, options)
  begin
    stop_if_bad_post_id(post_id)
    doing(options)
    details = @api.get_details(post_id, options)
    stop_if_404(details, post_id)
    id = get_original_id(post_id, details)
    stream = get_convo id, options
    Databases.pagination["replies:#{id}"] = stream['meta']['max_id']
    options = options.dup
    unless details['data']['reply_to'].nil?
      options[:reply_to] = details['data']['reply_to'].to_i
    end
    options[:post_id] = post_id.to_i
    render_view(stream, options)
    Scroll.new(@api, @view).convo(id, options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
  end
end

#delete(post_id) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/ayadn/action.rb', line 222

def delete(post_id)
  begin
    stop_if_bad_post_id(post_id)
    print Status.deleting_post(post_id)
    check_has_been_deleted(post_id, @api.delete_post(post_id))
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id]})
  end
end

#delete_m(args) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/ayadn/action.rb', line 232

def delete_m(args)
  begin
    missing_message_id unless args.length == 2
    message_id = args[1]
    missing_message_id unless message_id.is_integer?
    channel_id = get_channel_id_from_alias(args[0])
    print Status.deleting_message(message_id)
    resp = @api.delete_message(channel_id, message_id)
    check_message_has_been_deleted(message_id, resp)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [message_id]})
  end
end

#download(file_id) ⇒ Object



584
585
586
587
588
589
590
591
592
# File 'lib/ayadn/action.rb', line 584

def download(file_id)
  begin
    file = @api.get_file(file_id)['data']
    FileOps.download_url(file['name'], file['url'])
    puts Status.downloaded(file['name'])
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [file_id, file['url']]})
  end
end

#files(options) ⇒ Object



569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/ayadn/action.rb', line 569

def files(options)
  begin
    doing(options)
    if options[:raw]
      @view.show_raw(@api.get_files_list(options), options)
      exit
    end
    list = @api.get_files_list(options)
    @view.clear_screen
    list.empty? ? no_data('files') : @view.show_files_list(list)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#follow(usernames) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/ayadn/action.rb', line 261

def follow(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.following(users.join(','))
    users.each do |user|
      resp = @api.follow(user)
      check_has_been_followed(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#followers(username, options) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/ayadn/action.rb', line 465

def followers(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    if_raw_list(username, :followers, options)
    list = @api.get_followers(username)
    auto_save_followers(list)
    no_data('followers') if list.empty?
    get_list(:followers, list, username)
    Databases.add_to_users_db_from_list(list)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#followings(username, options) ⇒ Object



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/ayadn/action.rb', line 449

def followings(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    if_raw_list(username, :followings, options)
    list = @api.get_followings(username)
    auto_save_followings(list)
    no_data('followings') if list.empty?
    get_list(:followings, list, username)
    Databases.add_to_users_db_from_list(list)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#get_convo(id, options) ⇒ Object



216
217
218
219
220
# File 'lib/ayadn/action.rb', line 216

def get_convo id, options
  stream = @api.get_convo(id, options)
  stop_if_no_post(stream, id)
  stream
end

#global(settings) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ayadn/action.rb', line 42

def global(settings)
  begin
    options = settings.dup
    options[:filter] = nicerank_true()
    doing(options)
    stream = @api.get_global(options)
    niceranks = NiceRank.new.get_ranks(stream)
    stop_if_no_new_posts(stream, options, 'global')
    Databases.save_max_id(stream)
    render_view(stream, options, niceranks)
    Scroll.new(@api, @view).global(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#hashtag(hashtag, options) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/ayadn/action.rb', line 393

def hashtag(hashtag, options)
  begin
    doing(options)
    stream = @api.get_hashtag(hashtag)
    stop_if_no_data(stream, 'hashtag')
    if options[:extract]
      view_all_hashtag_links(stream, hashtag)
    else
      render_view(stream, options)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
  end
end

#interactions(options) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ayadn/action.rb', line 131

def interactions(options)
  begin
    doing(options)
    stream = @api.get_interactions
    if_raw_show(stream, options)
    @view.clear_screen
    @view.show_interactions(stream['data'])
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#mentions(username, options) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ayadn/action.rb', line 97

def mentions(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    stream = @api.get_mentions(username, options)
    stop_if_no_user(stream, username)
    Databases.save_max_id(stream)
    options = options.dup
    options[:in_mentions] = true
    stop_if_no_data(stream, 'mentions')
    render_view(stream, options)
    Scroll.new(@api, @view).mentions(username, options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#messages(channel_id, options) ⇒ Object



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/ayadn/action.rb', line 605

def messages(channel_id, options)
  begin
    channel_id = get_channel_id_from_alias(channel_id)
    doing(options)
    resp = @api.get_messages(channel_id, options)
    stop_if_no_new_posts(resp, options, "channel:#{channel_id}")
    Databases.save_max_id(resp)
    if_raw_show(resp, options)
    stop_if_no_data(resp, 'messages')
    render_view(resp, options)
    Scroll.new(@api, @view).messages(channel_id, options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
  end
end

#mute(usernames) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/ayadn/action.rb', line 291

def mute(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.muting(users.join(','))
    users.each do |user|
      resp = @api.mute(user)
      check_has_been_muted(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#muted(options) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/ayadn/action.rb', line 481

def muted(options)
  begin
    doing(options)
    if_raw_list(nil, :muted, options)
    list = @api.get_muted
    auto_save_muted(list)
    no_data('muted') if list.empty?
    get_list(:muted, list, nil)
    Databases.add_to_users_db_from_list(list)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#nowplaying(options = {}) ⇒ Object



802
803
804
# File 'lib/ayadn/action.rb', line 802

def nowplaying(options = {})
  options['lastfm'] ? np_lastfm(options) : np_itunes(options)
end

#photos(options) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ayadn/action.rb', line 71

def photos(options)
  begin
    doing(options)
    stream = @api.get_photos(options)
    stop_if_no_new_posts(stream, options, 'explore:photos')
    Databases.save_max_id(stream)
    render_view(stream, options)
    Scroll.new(@api, @view).photos(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#pin(post_id, usertags) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/ayadn/action.rb', line 621

def pin(post_id, usertags)
  require 'pinboard'
  require 'base64'
  begin
    stop_if_bad_post_id(post_id)
    doing()
    resp = get_data_from_response(@api.get_details(post_id))
    @view.clear_screen
    links = Workers.new.extract_links(resp)
    resp['text'].nil? ? text = "" : text = resp['text']
    usertags << "ADN"
    handle = "@" + resp['user']['username']
    post_text = "From: #{handle} -- Text: #{text} -- Links: #{links.join(" ")}"
    pinner = Ayadn::PinBoard.new
    unless pinner.has_credentials_file?
      puts Status.no_pin_creds
      pinner.ask_credentials
      puts Status.pin_creds_saved
    end
    credentials = pinner.load_credentials
    maker = Struct.new(:username, :password, :url, :tags, :text, :description)
    bookmark = maker.new(credentials[0], credentials[1], resp['canonical_url'], usertags.join(","), post_text, links[0])
    puts Status.saving_pin
    pinner.pin(bookmark)
    puts Status.done
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, usertags]})
  end
end

#pmess(username, options = {}) ⇒ Object



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
# File 'lib/ayadn/action.rb', line 710

def pmess(username, options = {})
	begin
    files = FileOps.make_paths(options['embed']) if options['embed']
    stop_if_no_username(username)
    username = [add_arobase(username)]
		messenger = Post.new
    puts Status.message_from(username)
		puts Status.message
		lines_array = messenger.compose
		messenger.check_message_length(lines_array)
    text = lines_array.join("\n")
		@view.clear_screen
    if options['embed']
      puts Status.uploading(options['embed'])
      resp = messenger.send_pm_embedded(username, text, files)
    else
      puts Status.posting
      resp = messenger.send_pm(username, text)
    end
    FileOps.save_message(resp) if Settings.options[:backup][:auto_save_sent_messages]
		@view.clear_screen
		puts Status.yourmessage
		@view.show_posted(resp)
	rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
	end
end

#post(args, options) ⇒ Object



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/ayadn/action.rb', line 661

def post(args, options)
  begin
    writer = Post.new
    @view.clear_screen
    if options['embed']
      embed = options['embed']
      text = args.join(" ")
      puts Status.uploading(embed)
      resp = writer.send_embedded(text, FileOps.make_paths(embed))
    else
      puts Status.posting
      resp = writer.post(args)
    end
    FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
    @view.clear_screen
    puts Status.yourpost
    @view.show_posted(resp)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [args, options]})
  end
end

#postinfo(post_id, options) ⇒ Object



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/ayadn/action.rb', line 535

def (post_id, options)
  begin
    stop_if_bad_post_id(post_id)
    doing(options)
    if options[:raw]
      details = @api.get_details(post_id, options)
      @view.show_raw(details, options)
      exit
    end
    @view.clear_screen
    response = @api.get_details(post_id, options)
    stop_if_no_post(response, post_id)
    resp = response['data']
    response = @api.get_user("@#{resp['user']['username']}")
    stop_if_no_user(response, response['data']['username'])
    stream = response['data']
    puts "POST:\n".inverse
    @view.show_simple_post([resp], options)
    if resp['repost_of']
      puts "REPOST OF:\n".inverse
      Errors.repost(post_id, resp['repost_of']['id'])
      @view.show_simple_post([resp['repost_of']], options)
    end
    puts "AUTHOR:\n".inverse
    if response['data']['username'] == Settings.config[:identity][:username]
      @view.show_userinfos(stream, @api.get_token_info['data'], true)
    else
      @view.show_userinfos(stream, nil, true)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, options]})
  end
end

#posts(username, options) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ayadn/action.rb', line 115

def posts(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    stream = @api.get_posts(username, options)
    stop_if_no_user(stream, username)
    Databases.save_max_id(stream)
    stop_if_no_data(stream, 'mentions')
    render_view(stream, options)
    Scroll.new(@api, @view).posts(username, options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#random_posts(options) ⇒ Object



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/ayadn/action.rb', line 806

def random_posts(options)
  begin
    _, cols = winsize
    max_posts = cols / 12
    @view.clear_screen
    puts "Fetching random posts, please wait...".color(:cyan)
    @max_id = @api.get_global({count: 1})['meta']['max_id'].to_i
    @view.clear_screen
    counter = 1
    wait = options[:wait] || 5
    loop do
      begin
        @random_post_id = rand(@max_id)
        @resp = @api.get_details(@random_post_id, {})
        next if @resp['data']['is_deleted']
        @view.show_simple_post([@resp['data']], {})
        counter += 1
        if counter == max_posts
          countdown(wait)
          @view.clear_screen
          counter = 1
        end
      rescue Interrupt
        abort(Status.canceled)
      end
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
  end
end

#reply(post_id, options = {}) ⇒ Object



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
# File 'lib/ayadn/action.rb', line 758

def reply(post_id, options = {})
  begin
    files = FileOps.make_paths(options['embed']) if options['embed']
    post_id = get_real_post_id(post_id)
  	puts Status.replying_to(post_id)
  	replied_to = @api.get_details(post_id)
    stop_if_no_post(replied_to, post_id)
    post_id = get_original_id(post_id, replied_to)
    if replied_to['data']['repost_of']
      if post_id == replied_to['data']['repost_of']['id']
        replied_to = @api.get_details(post_id)
        stop_if_no_post(replied_to, post_id)
      end
    end
    poster = Post.new
    puts Status.writing
    puts Status.reply
    lines_array = poster.compose
    poster.check_post_length(lines_array)
    @view.clear_screen
    reply = poster.reply(lines_array.join("\n"), Workers.new.build_posts([replied_to['data']]))
    if options['embed']
      puts Status.uploading(options['embed'])
      resp = poster.send_reply_embedded(reply, post_id, files)
    else
      puts Status.posting
      resp = poster.send_reply(reply, post_id)
    end
    FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
    @view.clear_screen
    puts Status.done

    options = options.dup
    unless resp['data']['reply_to'].nil?
      options[:reply_to] = resp['data']['reply_to'].to_i
    end
    options[:post_id] = resp['data']['id'].to_i

    render_view(@api.get_convo(post_id), options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, options]})
  end
end

#repost(post_id) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/ayadn/action.rb', line 336

def repost(post_id)
  begin
    stop_if_bad_post_id(post_id)
    puts Status.reposting(post_id)
    resp = @api.get_details(post_id)
    check_if_already_reposted(resp)
    id = get_original_id(post_id, resp)
    check_has_been_reposted(id, @api.repost(id))
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, id]})
  end
end

#search(words, options) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/ayadn/action.rb', line 408

def search(words, options)
  begin
    doing(options)
    stream = if options[:users]
      @api.search_users words, options
    elsif options[:annotations]
      @api.search_annotations words, options
    elsif options[:channels]
      splitted = splitter_all words
      @api.search_channels splitted.join(','), options
    elsif options[:messages]
      words = words.split(',')
      channel_id = get_channel_id_from_alias(words[0])
      words.shift
      splitted = splitter_all words.join(' ')
      @api.search_messages channel_id, splitted.join(','), options
    else
      splitted = splitter_all words
      @api.get_search splitted.join(','), options
    end
    stop_if_no_data(stream, 'search')
    if options[:users]
      stream['data'].sort_by! {|obj| obj['counts']['followers']}
      stream['data'].each do |obj|
        puts @view.big_separator
        @view.show_userinfos(obj, nil, false)
      end
    elsif options[:channels]
      @view.show_channels stream, options
    else
      if options[:extract]
        view_all_search_links(stream, words)
      else
        render_view(stream, options)
      end
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [words, options]})
  end
end

#send_to_channel(channel_id) ⇒ Object



738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/ayadn/action.rb', line 738

def send_to_channel(channel_id)
	begin
    channel_id = get_channel_id_from_alias(channel_id)
	messenger = Post.new
    puts Status.writing
	puts Status.post
	lines_array = messenger.compose
	messenger.check_message_length(lines_array)
	@view.clear_screen
	puts Status.posting
	resp = messenger.send_message(channel_id, lines_array.join("\n"))
    FileOps.save_message(resp) if Settings.options[:backup][:auto_save_sent_messages]
	@view.clear_screen
	puts Status.yourpost
	@view.show_posted(resp)
	rescue => e
    Errors.global_error({error: e, caller: caller, data: [channel_id]})
	end
end

#star(post_id) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/ayadn/action.rb', line 380

def star(post_id)
  begin
    stop_if_bad_post_id(post_id)
    puts Status.starring(post_id)
    resp = @api.get_details(post_id)
    check_if_already_starred(resp)
    id = get_original_id(post_id, resp)
    check_has_been_starred(id, @api.star(id))
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id]})
  end
end


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ayadn/action.rb', line 58

def trending(options)
  begin
    doing(options)
    stream = @api.get_trending(options)
    stop_if_no_new_posts(stream, options, 'explore:trending')
    Databases.save_max_id(stream)
    render_view(stream, options)
    Scroll.new(@api, @view).trending(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#unblock(usernames) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/ayadn/action.rb', line 306

def unblock(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.unblocking(users.join(','))
    users.each do |user|
      resp = @api.unblock(user)
      check_has_been_unblocked(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unfollow(usernames) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/ayadn/action.rb', line 246

def unfollow(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.unfollowing(users.join(','))
    users.each do |user|
      resp = @api.unfollow(user)
      check_has_been_unfollowed(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unified(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ayadn/action.rb', line 16

def unified(options)
  begin
    doing(options)
    stream = @api.get_unified(options)
    stop_if_no_new_posts(stream, options, 'unified')
    Databases.save_max_id(stream)
    render_view(stream, options)
    Scroll.new(@api, @view).unified(options) if options[:scroll]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#unmute(usernames) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/ayadn/action.rb', line 276

def unmute(usernames)
  begin
    stop_if_no_username(usernames)
    users = all_but_me(usernames)
    puts Status.unmuting(users.join(','))
    users.each do |user|
      resp = @api.unmute(user)
      check_has_been_unmuted(user, resp)
      sleep 1 unless users.length == 1
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unrepost(post_id) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/ayadn/action.rb', line 349

def unrepost(post_id)
  begin
    stop_if_bad_post_id(post_id)
    puts Status.unreposting(post_id)
    if @api.get_details(post_id)['data']['you_reposted']
      check_has_been_unreposted(post_id, @api.unrepost(post_id))
    else
      puts Status.not_your_repost
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id]})
  end
end

#unstar(post_id) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/ayadn/action.rb', line 363

def unstar(post_id)
  begin
    stop_if_bad_post_id(post_id)
    puts Status.unstarring(post_id)
    resp = @api.get_details(post_id)
    id = get_original_id(post_id, resp)
    resp = @api.get_details(id)
    if resp['data']['you_starred']
      check_has_been_unstarred(id, @api.unstar(id))
    else
      puts Status.not_your_starred
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id]})
  end
end

#userinfo(username, options) ⇒ Object



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/ayadn/action.rb', line 516

def userinfo(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    if options[:raw]
      resp = @api.get_user(username)
      @view.show_raw(resp, options)
      exit
    end
    stream = @api.get_user(username)
    stop_if_no_user(stream, username)
    same_username?(stream) ? token = @api.get_token_info['data'] : token = nil
    get_infos(stream['data'], token)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#versionObject



837
838
839
840
841
842
843
844
845
846
847
# File 'lib/ayadn/action.rb', line 837

def version
  begin
    puts "\nAYADN\n".color(:red)
    puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
    puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(Settings.options[:colors][:link])
    puts "Docs:\t\t".color(:cyan) + "http://ayadn-app.net/doc/".color(Settings.options[:colors][:link])
    puts "\n"
  rescue => e
    Errors.global_error({error: e, caller: caller, data: []})
  end
end

#view_settings(options) ⇒ Object



508
509
510
511
512
513
514
# File 'lib/ayadn/action.rb', line 508

def view_settings(options)
  begin
    options[:raw] ? (puts Settings.options.to_json) : @view.show_settings
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#whatstarred(username, options) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ayadn/action.rb', line 143

def whatstarred(username, options)
  begin
    stop_if_no_username(username)
    username = add_arobase(username)
    doing(options)
    stream = @api.get_whatstarred(username, options)
    stop_if_no_user(stream, username)
    stop_if_no_data(stream, 'whatstarred')
    options[:extract] ? view_all_stars_links(stream) : render_view(stream, options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#whoreposted(post_id, options) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/ayadn/action.rb', line 157

def whoreposted(post_id, options)
  begin
    stop_if_bad_post_id(post_id)
    doing(options)
    details = @api.get_details(post_id, options)
    stop_if_404(details, post_id)
    id = get_original_id(post_id, details)
    list = @api.get_whoreposted(id)
    if_raw_show(list, options)
    unless list['data'].empty?
      get_list(:whoreposted, list['data'], post_id)
    else
      puts Status.nobody_reposted
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, options]})
  end
end

#whostarred(post_id, options) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ayadn/action.rb', line 176

def whostarred(post_id, options)
  begin
    stop_if_bad_post_id(post_id)
    doing(options)
    details = @api.get_details(post_id, options)
    stop_if_404(details, post_id)
    id = get_original_id(post_id, details)
    list = @api.get_whostarred(id)
    if_raw_show(list, options)
    unless list['data'].empty?
      get_list(:whostarred, list['data'], id)
    else
      puts Status.nobody_starred
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
  end
end

#write(options) ⇒ Object



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/ayadn/action.rb', line 683

def write(options)
  begin
    files = FileOps.make_paths(options['embed']) if options['embed']
    writer = Post.new
    puts Status.writing
    puts Status.post
    lines_array = writer.compose
    writer.check_post_length(lines_array)
    text = lines_array.join("\n")
    if options['embed']
      @view.clear_screen
      puts Status.uploading(options['embed'])
      resp = writer.send_embedded(text, files)
    else
      resp = writer.send_post(text)
    end
    @view.clear_screen
    puts Status.posting
    FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
    @view.clear_screen
    puts Status.yourpost
    @view.show_posted(resp)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [text, options]})
  end
end