lib/ayadn/action.rb in ayadn-1.7.0 vs lib/ayadn/action.rb in ayadn-1.7.1

- old
+ new

@@ -309,47 +309,66 @@ end end def view_settings(options) begin - options[:raw] ? (puts Settings.options.to_json) : @view.show_settings + if options[:raw] + jj JSON.parse(Settings.config.to_json) + jj JSON.parse(Settings.options.to_json) + else + @view.show_settings + end rescue => e Errors.global_error({error: e, caller: caller, data: [options]}) end end - def userinfo(username, options) + def userupdate options begin + profile = Profile.new(options) + profile.get_text_from_user + profile.prepare_payload + puts "\n\nUpdating profile...\n".color(:green) + profile.update + puts Status.done + userinfo('me') + rescue => e + Errors.global_error({error: e, caller: caller, data: [options]}) + end + end + + def userinfo(username, options = {}) + begin + username = [username] unless username.is_a?(Array) Check.no_username(username) username = @workers.add_arobase(username) - @view.downloading(options) if options[:raw] - resp = @api.get_user(username) - @view.show_raw(resp, options) - exit + @view.show_raw(@api.get_user(username), options) + else + @view.downloading + stream = @api.get_user(username) + Check.no_user(stream, username) + Check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil + @view.clear_screen + @view.infos(stream['data'], token) end - stream = @api.get_user(username) - Check.no_user(stream, username) - Check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil - @view.infos(stream['data'], token) rescue => e Errors.global_error({error: e, caller: caller, data: [username, options]}) end end def postinfo(post_id, options) begin Settings.options[:force] = true if options[:force] Check.bad_post_id(post_id) - @view.downloading(options) + details = lambda { @api.get_details(post_id, options) } if options[:raw] - details = @api.get_details(post_id, options) - @view.show_raw(details, options) + @view.show_raw(details.call, options) exit end @view.clear_screen - response = @api.get_details(post_id, options) + response = details.call Check.no_post(response, post_id) resp = response['data'] response = @api.get_user("@#{resp['user']['username']}") Check.no_user(response, response['data']['username']) stream = response['data'] @@ -371,18 +390,20 @@ end end def files(options) begin - @view.downloading(options) + get_files = lambda { @api.get_files_list(options) } if options[:raw] - @view.show_raw(@api.get_files_list(options), options) - exit + @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 - list = @api.get_files_list(options) - @view.clear_screen - list.empty? ? Errors.no_data('files') : @view.show_files_list(list) rescue => e Errors.global_error({error: e, caller: caller, data: [options]}) end end @@ -394,18 +415,29 @@ rescue => e Errors.global_error({error: e, caller: caller, data: [file_id, file['url']]}) end end - def channels + def channels options begin - @view.downloading - resp = @api.get_channels - @view.clear_screen - @view.show_channels(resp) + 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_raw(channels.call) + exit + else + @view.downloading + resp = channels.call + @view.clear_screen + @view.show_channels(resp) + end rescue => e - Errors.global_error({error: e, caller: caller, data: [resp['meta']]}) + Errors.global_error({error: e, caller: caller, data: [options]}) end end def messages(channel_id, options) begin @@ -574,11 +606,11 @@ end end def nowplaying(options = {}) np = NowPlaying.new(@api, @view, @workers) - options['lastfm'] ? np.lastfm(options) : np.itunes(options) + options[:lastfm] ? np.lastfm(options) : np.itunes(options) end def nowwatching(args, options = {}) begin abort(Status.error_missing_title) if args.empty? @@ -594,13 +626,13 @@ def tvshow(args, options = {}) begin abort(Status.error_missing_title) if args.empty? client = TvShow.new - if options['alt'] - show_obj = client.find_alt(args.join(' ')) + show_obj = if options[:alt] + client.find_alt(args.join(' ')) else - show_obj = client.find(args.join(' ')) + client.find(args.join(' ')) end candidate = client.create_details(show_obj) candidate.ok ? candidate.post(options) : candidate.cancel rescue => e puts Status.wtf