Class: Ayadn::Action

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

Instance Method Summary collapse

Constructor Details

#initializeAction

Returns a new instance of Action.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ayadn/action.rb', line 11

def initialize
  @api = API.new
  @status = Status.new      
  @workers = Workers.new(@status)
  @view = View.new(@status, @workers)
  @check = Check.new(@status)
  Settings.load_config
  Settings.get_token
  Settings.init_config
  Logs.create_logger
  Databases.open_databases
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Uses method_missing to template a single method for several streams



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ayadn/action.rb', line 25

def method_missing(meth, *args)
  begin
    options = if args.size > 1
      args[1]
    else
      args[0]
    end
    Settings.options.timeline.compact = true if options[:compact]
    Settings.global.force = true if options[:force]
    stream = Stream.new(@api, @view, @workers, @check, @status)
    case meth
    when :mentions, :posts, :whatstarred, :whoreposted, :whostarred, :convo, :followings, :followers, :messages
      stream.send(meth, args[0], options)
    when :unified, :checkins, :global, :trending, :photos, :conversations, :interactions, :muted, :blocked, :random_posts
      stream.send(meth, options)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [meth, options]})
  end
end

Instance Method Details

#auto(options) ⇒ Object



519
520
521
522
523
524
525
526
527
# File 'lib/ayadn/action.rb', line 519

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

#block(usernames) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ayadn/action.rb', line 153

def block(usernames)
  begin
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.blocking(users.join(','))
    users.each do |user|
      resp = @api.block(user)
      @check.has_been_blocked(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#channels(options) ⇒ Object



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/ayadn/action.rb', line 386

def channels options
  begin
    # Input could be channel IDs or channel aliases
    channels = if options[:id]
      channel_id = options[:id].map {|id| @workers.get_channel_id_from_alias(id)}
      lambda { @api.get_channel(channel_id, options) }
    else
      lambda { @api.get_channels }
    end
    if options[:raw]
      @view.show_direct_raw(channels.call)
      exit
    else
      @view.downloading
      resp = channels.call
      @view.clear_screen
      data = resp["data"] 
      channels = data.map { |ch| ChannelObject.new(ch) }
      @view.show_channels(channels, options)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#delete(post_ids, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ayadn/action.rb', line 46

def delete(post_ids, options = {})
  begin
    ids = get_posts_ids_or_exit(post_ids) { @status.error_missing_post_id }
    ids = get_real_posts_ids_or_force(options, ids)
    puts "\n"
    ids.each do |post_id|
      @status.deleting_post(post_id)
      resp = @api.delete_post(post_id)
      @check.has_been_deleted(post_id, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_ids]})
  end
end

#delete_m(args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ayadn/action.rb', line 61

def delete_m(args)
  begin
    unless args.length >= 2
      @status.error_missing_message_id
      exit
    end
    channel = args[0]
    args.shift
    ids = get_posts_ids_or_exit(args) { @status.error_missing_message_id }
    channel_id = @workers.get_channel_id_from_alias(channel)
    puts "\n"
    ids.each do |message_id|
      @status.deleting_message(message_id)
      resp = @api.delete_message(channel_id, message_id)
      @check.message_has_been_deleted(message_id, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [args]})
  end
end

#download(file_id) ⇒ Object



376
377
378
379
380
381
382
383
384
# File 'lib/ayadn/action.rb', line 376

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

#files(options) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/ayadn/action.rb', line 359

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

#follow(usernames) ⇒ Object



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

def follow(usernames)
  begin
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.following(users.join(','))
    users.each do |user|
      resp = @api.follow(user)
      @check.has_been_followed(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#hashtag(hashtag, options) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/ayadn/action.rb', line 244

def hashtag(hashtag, options)
  begin
    search = Search.new(@api, @view, @workers)
    search.hashtag(hashtag, options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
  end
end

#messages_unread(options) ⇒ Object



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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/ayadn/action.rb', line 411

def messages_unread(options)
  begin
    Settings.options.timeline.compact = true if options[:compact]
    Settings.options.marker.messages = false if options[:silent] # Option to not mark the messages as read
    puts "\n"
    @status.say_nocolor :searching, "channels with unread PMs"
    channels_objects = @api.get_channels['data'].map { |obj| ChannelObject.new(obj) }
    unread_channels = []
    channels_objects.each do |ch|
      # Channels can be of many types, PMs are only one type
      if ch.type == "net.app.core.pm" && ch.has_unread
        unread_channels << ch.id
      end
    end
    if unread_channels.empty?
      @status.no_new_messages
      exit
    end
    unread_messages = {}
    unread_channels.reverse.each do |id|
      @status.say_nocolor :downloading, "messages from channel #{id}"
      # Find the last time we've done this
      since = Databases.find_last_id_from("channel:#{id}")
      unless since.nil?
        api_options = {count: 20, since_id: since}
      else
        api_options = {count: 20}
      end
      ch = @api.get_messages(id, api_options)
      # Find the last message seen and the last message in the channel
      last_read_id = ch['meta']['marker']['last_read_id'].to_i
      last_message_id = ch['meta']['max_id']
      messages = ch['data'].map { |msg| msg if msg['id'].to_i > last_read_id }
      unread_messages[id] = [messages, last_message_id]
    end
    # If we want to mark the messages as read
    if Settings.options.marker.messages
      unread_messages.each do |k,v|
        name = "channel:#{k}"
        # Save the reading position locally
        Databases.pagination_insert(name, v[1])
        # Mark as read
        resp = @api.update_marker(name, v[1])
        res = JSON.parse(resp)
        if res['meta']['code'] != 200
          @status.say_error "couldn't update channel #{k} as read"
        else
          @status.say_green :updated, "channel #{k} as read"
        end
      end
    end
    @view.clear_screen
    unread_messages.each do |k,v|
      @status.unread_from_channel(k)
      messages_objects = v[0].map { |post_hash| PostObject.new(post_hash) }
      @view.show_messages(messages_objects)
    end
    puts "\n" if Settings.options.timeline.compact
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#mute(usernames) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ayadn/action.rb', line 125

def mute(usernames)
  begin
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.muting(users.join(','))
    users.each do |user|
      resp = @api.mute(user)
      @check.has_been_muted(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#nowplaying(options = {}) ⇒ Object



664
665
666
667
668
669
670
671
672
673
674
# File 'lib/ayadn/action.rb', line 664

def nowplaying(options = {})
  Settings.options.timeline.compact = true if options[:compact]
  np = NowPlaying.new(@api, @view, @workers, @status, options)
  if options[:lastfm]
    np.lastfm(options)
  elsif options[:deezer]
    np.deezer(options)
  else
    np.itunes(options)
  end
end

#pin(post_id, usertags, options = {}) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/ayadn/action.rb', line 474

def pin(post_id, usertags, options = {})
  begin
    require 'pinboard'
    require 'base64'
  rescue LoadError => e
    puts "\nAYADN: Error while loading Gems\n\n"
    puts "RUBY: #{e}\n\n"
    exit
  end
  begin
    @check.bad_post_id(post_id)
    Settings.options.timeline.compact = true if options[:compact]
    post_id = get_real_post_id_or_force(options, post_id)
    @view.downloading
    # Get the details from the post we want to send to Pinboard
    # resp = @api.get_details(post_id)['data']
    @view.clear_screen
    # Extract links from the post
    post_object = PostObject.new(@api.get_details(post_id)['data'])
    links = @workers.extract_links(post_object)
    # In case the post has no text, to prevent an error
    post_object.text.nil? ? text = "" : text = post_object.text
    # The first tag is always "ADN"
    usertags << "ADN"
    handle = "@" + post_object.user.username
    post_text = "From: #{handle} -- Text: #{text} -- Links: #{links.join(" ")}"
    pinner = Ayadn::PinBoard.new
    unless pinner.has_credentials_file?
      # No Pinboard account registered? Ask for one.
      @status.no_pin_creds
      pinner.ask_credentials(@status)
      @status.pin_creds_saved
    end
    # Get stored credentials
    credentials = pinner.load_credentials
    maker = Struct.new(:username, :password, :url, :tags, :text, :description)
    bookmark = maker.new(credentials[0], credentials[1], post_object.canonical_url, usertags.join(","), post_text, post_object.canonical_url)
    @status.saving_pin
    pinner.pin(bookmark)
    @status.done
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, usertags]})
  end
end

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



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/ayadn/action.rb', line 551

def pmess(username, options = {})
  begin
    Settings.options.timeline.compact = true if options[:compact]
    Settings.options.marker.messages = false if options[:silent]
    @check.no_username(username)
    username = [@workers.add_arobase(username)]
    writer = Post.new(@status)
    @status.message_from(username)
    @status.message
    text = writer.compose.join("\n")
    writer.message_size_error(text) if !writer.message_size_ok?(text)
    @view.clear_screen
    @status.posting
    resp = writer.pm({options: options, text: text, username: username})
    post_object = PostObject.new(resp["data"])
    if Settings.options.marker.messages
      if resp['meta']['code'] == 200
        name = "channel:#{post_object.channel_id}"
        Databases.pagination_insert(name, post_object.id)
        marked = @api.update_marker(name, post_object.id)
        updated = JSON.parse(marked)
        if updated['meta']['code'] != 200
          raise "couldn't update channel #{post_object.channel_id} as read"
        end
      end
    end
    FileOps.save_message(resp) if Settings.options.backup.messages
    @view.clear_screen
    @status.yourmessage(username[0])
    @view.show_simple_post([post_object])
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#post(args, options) ⇒ Object



529
530
531
532
533
534
535
536
# File 'lib/ayadn/action.rb', line 529

def post(args, options)
  begin
    Settings.options.timeline.compact = true if options[:compact]
    post_and_show(Post.new(@status), args.join(" "), options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [args, options]})
  end
end

#postinfo(post_id, options) ⇒ Object



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/ayadn/action.rb', line 311

def (post_id, options)
  begin
    @check.bad_post_id(post_id)
    Settings.options.timeline.compact = true if options[:compact]
    post_id = get_real_post_id_or_force(options, post_id)
    details = lambda { @api.get_details(post_id, options) }
    if options[:raw]
      @view.show_raw(details.call, options)
      exit
    end
    @view.clear_screen
    response = details.call
    @check.no_details(response, post_id)

    post_object = PostObject.new(response["data"])

    if post_object.is_deleted
      @status.user_404(post_object.id)
      Errors.global_error({error: "user 404", caller: caller, data: [post_id, options]})
    end

    response = @api.get_user("@#{post_object.user.username}")
    user_object = UserObject.new(response, post_object.user.username)

    @status.
    @view.show_simple_post([post_object], options)
    puts "\n" if Settings.options.timeline.compact
    @status.say_info "author"
    puts "\n" unless Settings.options.timeline.compact
    # Is it us? ...
    if user_object.username == Settings.config.identity.username
      @view.show_userinfos(post_object.user, @api.get_token_info['data'], true)
    else
      @view.show_userinfos(post_object.user, nil, true)
    end

    if !post_object.repost_of.nil?
      @status.repost_info
      # If we ask infos for a reposted post, fetch the original instead
      Errors.repost(post_id, post_object.repost_of.id)
      @view.show_simple_post([post_object.repost_of], options)
      puts "\n" if Settings.options.timeline.compact
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, options]})
  end
end

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



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/ayadn/action.rb', line 586

def reply(post_id, options = {})
  begin
    Settings.options.timeline.compact = true if options[:compact]
    @check.bad_post_id(post_id)
    post_id = get_real_post_id_or_force(options, post_id)
    @status.replying_to(post_id)
    replied_to = @api.get_details(post_id)
    @check.no_details(replied_to, post_id)
    # API specifies to always reply to the original post of a reposted post. We offer the user an option to not.
    unless options[:noredirect]
      post_id = @workers.get_original_id(post_id, replied_to)
    end
    if replied_to['data']['repost_of']
      if post_id == replied_to['data']['repost_of']['id']
        replied_to = @api.get_details(post_id)
        @check.no_details(replied_to, post_id)
      end
    end
    # ----
    writer = Post.new(@status)
    @status.writing
    @status.reply
    text = writer.compose.join("\n")
    # Text length is tested in Post class for the reply command
    @view.clear_screen
    replied_to = @workers.build_posts([PostObject.new(replied_to['data'])])[0]
    resp = writer.reply({options: options, text: text, id: post_id, reply_to: replied_to})
    FileOps.save_post(resp) if Settings.options.backup.posts
    # ----
    # "options" from CLI is immutable, we have to make a copy to add items
    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
    stream = @api.get_convo(post_id)
    stream_object = StreamObject.new(stream)
    @view.render(stream_object, options)
    puts "\n" if Settings.options.timeline.compact && !options[:raw]
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_id, options]})
  end
end

#repost(post_ids, options = {}) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ayadn/action.rb', line 167

def repost(post_ids, options = {})
  begin
    ids = get_posts_ids_or_exit(post_ids) { @status.error_missing_post_id }
    ids = get_real_posts_ids_or_force(options, ids)
    puts "\n"
    ids.each do |post_id|
      @status.reposting(post_id)
      # Retrieve the post we want to repost
      resp = @api.get_details(post_id)
      # Verify it hasn't been already reposted by us
      @check.already_reposted(resp)
      # Maybe the post is already a repost by someone else?
      id = @workers.get_original_id(post_id, resp)
      # Repost then verify it has been done
      @check.has_been_reposted(id, @api.repost(id))
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_ids, id]})
  end
end

#search(words, options) ⇒ Object



253
254
255
256
257
258
259
260
# File 'lib/ayadn/action.rb', line 253

def search(words, options)
  begin
    search = Search.new(@api, @view, @workers)
    search.find(words, options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [words, options]})
  end
end

#send_to_channel(channel_id, options = {}) ⇒ Object



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/ayadn/action.rb', line 630

def send_to_channel(channel_id, options = {})
  begin
    Settings.options.timeline.compact = true if options[:compact]
    Settings.options.marker.messages = false if options[:silent]
    channel_id = @workers.get_channel_id_from_alias(channel_id)
    writer = Post.new(@status)
    @status.writing
    @status.message
    text = writer.compose.join("\n")
    writer.message_size_error(text) if !writer.message_size_ok?(text)
    @view.clear_screen
    @status.posting
    resp = writer.message({options: options, id: channel_id, text: text})
    post_object = PostObject.new(resp["data"])
    if Settings.options.marker.messages
      if resp['meta']['code'] == 200
        name = "channel:#{post_object.channel_id}"
        Databases.pagination_insert(name, post_object.id)
        marked = @api.update_marker(name, post_object.id)
        updated = JSON.parse(marked)
        if updated['meta']['code'] != 200
          raise "couldn't update channel #{post_object.channel_id} as read"
        end
      end
    end
    FileOps.save_message(resp) if Settings.options.backup.messages
    @view.clear_screen
    @status.yourpost
    @view.show_simple_post([post_object])
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
  end
end

#star(post_ids, options = {}) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ayadn/action.rb', line 227

def star(post_ids, options = {})
  begin
    ids = get_posts_ids_or_exit(post_ids) { @status.error_missing_post_id }
    ids = get_real_posts_ids_or_force(options, ids)
    puts "\n"
    ids.each do |post_id|
      @status.starring(post_id)
      resp = @api.get_details(post_id)
      @check.already_starred(resp)
      id = @workers.get_original_id(post_id, resp)
      @check.has_been_starred(id, @api.star(id))
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_ids]})
  end
end

#streamObject

This class is the main initializer + dispatcher It responds to the CLI commands dispatcher, app.rb



9
# File 'lib/ayadn/action.rb', line 9

require_relative "stream"

#unblock(usernames) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ayadn/action.rb', line 139

def unblock(usernames)
  begin
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.unblocking(users.join(','))
    users.each do |user|
      resp = @api.unblock(user)
      @check.has_been_unblocked(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unfollow(usernames) ⇒ Object



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

def unfollow(usernames)
  begin
    # Verify CLI input, remove current user from list (you never know) to avoid API error
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.unfollowing(users.join(','))
    users.each do |user|
      resp = @api.unfollow(user)
      @check.has_been_unfollowed(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unmute(usernames) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ayadn/action.rb', line 111

def unmute(usernames)
  begin
    users = get_all_usernames_but_me(usernames)
    puts "\n"
    @status.unmuting(users.join(','))
    users.each do |user|
      resp = @api.unmute(user)
      @check.has_been_unmuted(user, resp)
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [usernames]})
  end
end

#unrepost(post_ids, options = {}) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/ayadn/action.rb', line 188

def unrepost(post_ids, options = {})
  begin
    ids = get_posts_ids_or_exit(post_ids) { @status.error_missing_post_id }
    ids = get_real_posts_ids_or_force(options, ids)
    puts "\n"
    ids.each do |post_id|
      @status.unreposting(post_id)
      if @api.get_details(post_id)['data']['you_reposted']
        @check.has_been_unreposted(post_id, @api.unrepost(post_id))
      else
        @status.not_your_repost
      end
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_ids]})
  end
end

#unstar(post_ids, options = {}) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/ayadn/action.rb', line 206

def unstar(post_ids, options = {})
  begin
    ids = get_posts_ids_or_exit(post_ids) { @status.error_missing_post_id }
    ids = get_real_posts_ids_or_force(options, ids)
    puts "\n"
    ids.each do |post_id|
      @status.unstarring(post_id)
      resp = @api.get_details(post_id)
      id = @workers.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
        @status.not_your_starred
      end
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [post_ids]})
  end
end

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



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ayadn/action.rb', line 289

def userinfo(username, options = {})
  begin
    Settings.options.timeline.compact = true if options[:compact]
    @check.no_username(username)
    usernames = @workers.add_arobases_to_usernames(username)
    usernames.each.with_index do |username, index|
      if options[:raw]
        @view.show_raw(@api.get_user(username), options)
      else
        @view.downloading if index == 0
        user_object = UserObject.new(@api.get_user(username), username)
        # Is it us? If yes, get *our* info
        @check.same_username(user_object) ? token = @api.get_token_info['data'] : token = nil
        @view.clear_screen if index == 0
        @view.infos(user_object, token)
      end
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [username, options]})
  end
end

#userupdate(options) ⇒ Object



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

def userupdate options
  begin
    profile = Profile.new(options)
    profile.get_text_from_user
    profile.prepare_payload
    @status.updating_profile
    profile.update
    @status.done
    userinfo(['me'], options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#view_settings(options) ⇒ Object



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

def view_settings(options)
  begin
    if options[:raw]
      jj JSON.parse(Settings.options.to_h.to_json)
    else
      Settings.options.timeline.compact = true if options[:compact]
      @view.show_settings
    end
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [options]})
  end
end

#write(options) ⇒ Object



538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/ayadn/action.rb', line 538

def write(options)
  begin
    Settings.options.timeline.compact = true if options[:compact]
    writer = Post.new(@status)
    @status.writing
    @status.post
    text = writer.compose.join("\n")
    post_and_show(writer, text, options)
  rescue => e
    Errors.global_error({error: e, caller: caller, data: [text, options]})
  end
end