class Archivist::Client::Base
This is the primary interface of the gem. Example Usage:
require 'archivist/client' # Create an Archivist client: client = Archivist::Client::Base.new # Search for the books you're interested in: books = client.search(:start_year => 1500, :end_year => 1510) # Download them: books.each do |book| puts book.download end
Attributes
conn[R]
filters[RW]
Public Class Methods
new(opts = {}, filter_opts = {})
click to toggle source
filter_opts can be provided here, or when search is called. filters_opts are:
:language => if *any* search opts provided there. :start_year => search opts takes precedence when provided there.
# File lib/archivist/client/base.rb, line 31 def initialize(opts = {}, filter_opts = {}) @filters = Archivist::Client::Filters.new(filter_opts) @opts = { page: 1, rows: 50 }.merge(opts) @conn = DEFAULT_CONNECTION end
Public Instance Methods
search(opts = {})
click to toggle source
# File lib/archivist/client/base.rb, line 41 def search(opts = {}) Model::QueryResponse.new.tap do |qr| response = @conn.get('/advancedsearch.php', params(opts)) rep = Representation::QueryResponse.new(qr) begin rep.from_json(response.body) rescue => e $stderr.puts "Unable to parse as Archivist::Representation::QueryResponse:" $stderr.puts response.body raise e end end end
Private Instance Methods
params(opts = {})
click to toggle source
# File lib/archivist/client/base.rb, line 62 def params(opts = {}) { q: query(opts), fl: %w(identifier title creator date language mediattype), sort: ['date asc'], output: 'json' }.merge(@opts).merge(opts) end
query(opts)
click to toggle source
# File lib/archivist/client/base.rb, line 57 def query(opts) @filters.update(opts) @filters.to_query end