Class: Beats::Command::Api

Inherits:
Base
  • Object
show all
Defined in:
lib/beats/commands/api.rb

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

has_command?, #initialize

Constructor Details

This class inherits a constructor from Beats::Command::Base

Instance Method Details

#infoObject



5
6
7
# File 'lib/beats/commands/api.rb', line 5

def info
  display YAML.dump(client.index)
end

#searchObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/beats/commands/api.rb', line 19

def search
  interactive do |args|
    query = args.join(' AND ')
    display "Searching for: \"#{query}\""
    results = client.search(query)
    display "#{results['total']} item(s) found"
    %w(artists albums tracks).each do |collection|
      next unless results[collection].is_a?(Array)
      display_resources(results[collection])
    end
  end
end

#showObject



9
10
11
12
13
14
15
16
17
# File 'lib/beats/commands/api.rb', line 9

def show
  if args.empty?
    raise CommandFailed, command_usage('show', 'URI [...]')
  else
    display_resources(args.map { |uri|
      client.resource(CGI.escape(uri))
    })
  end
end