Class: Summon::CLI
Defined Under Namespace
Classes: Config
Class Method Summary collapse
Class Method Details
.execute(stdout, arguments = []) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/summon/cli.rb', line 7 def self.execute(stdout, arguments=[]) config = Config.load = { :log => {:level => :warn} } params = { "s.pn" => 1, "s.ps" => 10, "s.q" => [], "s.fq" => [], "s.st" => [], "s.cmd" => [], "s.ff" => [], "s.fvf" => [], "s.fvgf" => [], "s.rff" => [], "s.hs" => "*", "s.he" => "*", "s.role" => "none" } raw = nil do_benchmarks = false = %w( ) parser = OptionParser.new do |opts| opts. = " Summon Unified Discovery Service\n\n Usage: \#{File.basename($0)} [options] [text query]*\n See: http://api.summon.serialssolutions.com/help for details\n\n BANNER\n opts.separator \"API query parameters\"\n opts.on(\"--s.cmd=COMMAND\", String, \"Command: pass a command to the API\") {|cmd| params[\"s.cmd\"] << cmd} \n opts.on(\"--s.q=QUERY\", String, \"Query Term: add an all-field text query to the search\") {|q| params[\"s.q\"] << q}\n opts.on(\"--s.fq=QUERY\", String, \"Filter Query: add a filter query which does not affect document relevance\") {|fq| params[\"s.fq\"] << fq}\n opts.on(\"--s.st=FIELD,VALUE\", String, \"Search Term: add a query term to a field\") {|t| params[\"s.st\"] << t}\n opts.on(\"--s.ff=FIELD,MODE,PAGE\", String, \"Facet Field: request facet counts for the given Field\") {|f| params['s.ff'] << f}\n opts.on(\"--s.fvf=FIELD,VALUE,NEGATED\", \"Facet Value Filter: applies an exact-value filter for a facet value within a facetable field: e.g. ContentType,Book\") {|fvf| params[\"s.fvf\"] << fvf}\n opts.on(\"--s.fvgf=FIELD,MODE,VALUES\", \"Facet Value Group Filter: advanced functionality. see official api docs. e.g. 'SubjectTerms,or,northern+america,u.s.,canada'\")\n opts.on(\"--s.rff=<facetField>, <minValue>:<maxValue>[:<inclusive>][, <minValue>:<maxValue>[:<inclusive>]]*\", \"Range Facet Field: e.g. PublicationDate,1971:1980,1981:1990,1991:2000,2001:2010\") {|rff| params[\"s.rff\"] << rff}\n opts.on(\"--s.rf=<fieldName>, <minValue>:<maxValue>[:<inclusive>]\", \"Range Filter: filter the result list to values lying within the range. e.g. PublicationDate,1971:1980\")\n opts.on(\"--s.hl=BOOLEAN\", \"Highlight: turn highlighting on or off: e.g. --s.hl=false\") {|hl| params[\"s.hl\"] = hl}\n opts.on(\"--s.hs=DELIMITER\", String, \"Highlight Start: demarcate the beginning of a term hit. default is *\") {|d| params[\"s.hs\"] = d}\n opts.on(\"--s.he=DELIMITER\", String, \"Highlight End: demarcate the beginning of a term hit. default is *\") {|d| params[\"s.he\"] = d}\n opts.on(\"--s.ps=INT\", Integer, \"Page Size: number of documents to return per page\") {|n| params[\"s.ps\"] = n}\n opts.on(\"--s.pn=INT\", Integer, \"Page Number: start the results at this page, starting with 1\") {|n| params[\"s.pn\"] = n}\n opts.on(\"--s.ho=BOOLEAN\", \"Holdings Only: restrict this search to my institution's holdings only \") {|n| params[\"s.ho\"] = n}\n opts.on(\"--s.sort=FIELD:DIRECTION\", \"Sort: specifiy sort order (e.g. PublicationDate:DESC)\") {|s| params[\"s.sort\"] = s}\n opts.on(\"--s.dym=BOOLEAN\", \"Did You Mean?: enables or disables search suggestions.\") {|dym| params[\"s.dym\"] = dym}\n opts.on(\"--s.role=VALUE\", \"API Authorization Role. e.g. --s.role=none (default) or --s.role=authenticated\") {|s| params[\"s.role\"] = s}\n\n opts.separator \"\"\n opts.separator \"Configuration Options\"\n opts.on(\"-u\", \"--url=KEY\", String, \"Summon API Base URL\", \"Default: http://api.summon.serialssolutions.com\",\n \"Default: ~/.summonrc[url]\") {|key| options[:url] = key}\n opts.on(\"-i\", \"--access-id=ID\", String,\n \"Summon API Access ID\",\n \"Default: ~/.summonrc[access_id]\") { |id| options[:access_id] = id }\n opts.on(\"-k\", \"--secret-key=KEY\", String, \"Summon API Secret Key\", \"Default: ~/.summonrc[secret_key]\") {|key| options[:secret_key] = key}\n opts.on(\"-c --sersol-client-id=CLIENT_HASH\", String, \"Specific Serials Solutions Client ID to use when making this query\", \n \"Only useful when your access id is authorized to query multiple accounts\") {|id| options[:client_key] = config.client_key(id)}\n\n opts.on(\"--benchmark\", \"Benchmark the the query\") { do_benchmarks = true}\n opts.on(\"-g\", \"--get=URL\", \"Takes a raw summon url, and queries the api without first performing any encoding.\") {|url| raw = url}\n opts.on(\"--verbose\", \"output more request information\") {options[:log].merge! :level => :info }\n opts.on(\"--debug\", \"output very detailed information\") {options[:log].merge! :level => :debug }\n opts.on(\"-h\", \"--help\",\n \"Show this help message.\") { stdout.puts opts; exit }\n \n begin\n opts.parse!(arguments)\n rescue OptionParser::ParseError => e\n puts e.message; exit\n end \n \n params[\"s.q\"] << ARGV.join(' ') unless ARGV.empty?\n\n if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }\n stdout.puts opts; exit\n end\n end\n begin\n if do_benchmarks\n require 'summon/benchmark'\n b = Summon::Benchmark.new\n service = Summon::Service.new(config.options.merge(options).merge(:benchmark => b))\n raw ? service.transport.urlget(raw) : service.transport.get(\"/search\", params)\n b.output\n else\n service = Summon::Service.new(config.options.merge(options))\n puts JSON.pretty_generate(raw ? service.transport.urlget(raw) : service.transport.get(\"/search\", params))\n end\n rescue Summon::Transport::TransportError => e\n puts e.message\n end\nend\n".gsub(/^ /,'') |