Class: Chimps::Commands::Search

Inherits:
Chimps::Command show all
Includes:
Utils::ActsOnResource, Utils::HttpFormat
Defined in:
lib/chimps-cli/commands/search.rb

Constant Summary collapse

USAGE =
"usage: chimps search [OPTIONS] QUERY"
HELP =
<<EOF

Search for #{default_resources_type} on Infochimps for the given
QUERY.

Examples:

  $ chimps search music                    # search all datasets for 'music'
  $ chimps search --my 'finance AND nyse'  # search your datasets for 'finance' and 'nyse'
EOF

Instance Attribute Summary

Attributes inherited from Chimps::Command

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::ActsOnResource

#first_arg_is_resource_type?, #has_resource_identifier?, included, #plural_resource, #resource_identifier, #resource_path, #resource_type, #resources_path

Methods included from Utils::HttpFormat

#headers, included, #normalize_fmt

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Class Method Details

.allowed_resourcesObject



9
10
11
# File 'lib/chimps-cli/commands/search.rb', line 9

def self.allowed_resources
  %w[dataset]
end

.allowed_response_fmtsObject



13
14
15
# File 'lib/chimps-cli/commands/search.rb', line 13

def self.allowed_response_fmts
  super().concat(['tsv'])
end

.default_response_fmtObject



17
18
19
# File 'lib/chimps-cli/commands/search.rb', line 17

def self.default_response_fmt
  'tsv'
end

Instance Method Details

#execute!Object



48
49
50
# File 'lib/chimps-cli/commands/search.rb', line 48

def execute!
  Request.new(path, :query_params => query_params, :sign => config[:my]).get(headers).print(config)
end

#pathObject



44
45
46
# File 'lib/chimps-cli/commands/search.rb', line 44

def path
  config[:my] ? "/my/search.#{response_fmt}" : "/search.#{response_fmt}"
end

#queryObject

Raises:



33
34
35
36
# File 'lib/chimps-cli/commands/search.rb', line 33

def query
  raise CLIError.new(self.class::USAGE) if config.rest.size < 2
  config.rest[1..-1].join(' ')
end

#query_paramsObject



38
39
40
41
42
# File 'lib/chimps-cli/commands/search.rb', line 38

def query_params
  {:query => query}.tap do |qp|
    qp[:skip_header] = true if config[:skip_column_names]
  end
end