Class: ArchivesSpaceClient
- Inherits:
-
Object
- Object
- ArchivesSpaceClient
- Defined in:
- public/app/services/archives_space_client.rb
Overview
This class provides access to the basic ArchivesSpace API endpoints. A single instance will be shared between all running request threads, so it should be thread safe!
Constant Summary collapse
- LOGIN_TIMEOUT_SECONDS =
10
- DEFAULT_SEARCH_OPTS =
{ 'publish' => true, 'page_size' => AppConfig[:pui_search_results_page_size] }
Class Method Summary collapse
Instance Method Summary collapse
-
#advanced_search(base, page = 1, search_opts = {}) ⇒ Object
handles multi-line searching.
-
#get_raw_record(uri, search_opts = {}) ⇒ Object
-
#get_record(uri, search_opts = {}) ⇒ Object
-
#get_repos_sublist(uri, type, search_opts = {}) ⇒ Object
-
#get_tree(node_uri) ⇒ Object
calls the ‘/search/published_tree’ endpoint.
-
#get_types_counts(record_type_list, repo_uri = nil) ⇒ Object
-
#initialize(archivesspace_url: AppConfig[:backend_url], username: AppConfig[:public_username], password: AppConfig[:public_user_secret]) ⇒ ArchivesSpaceClient
constructor
A new instance of ArchivesSpaceClient.
-
#list_repositories ⇒ Object
-
#search(query, page = 1, search_opts = {}) ⇒ Object
-
#search_records(record_list, search_opts = {}, full_notes = false) ⇒ Object
calls the ‘/search/records’ endpoint.
-
#search_repository(base, repo_id, page = 1, search_opts = {}) ⇒ Object
Constructor Details
#initialize(archivesspace_url: AppConfig[:backend_url], username: AppConfig[:public_username], password: AppConfig[:public_user_secret]) ⇒ ArchivesSpaceClient
Returns a new instance of ArchivesSpaceClient.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'public/app/services/archives_space_client.rb', line 27 def initialize(archivesspace_url: AppConfig[:backend_url], username: AppConfig[:public_username], password: AppConfig[:public_user_secret]) @url = archivesspace_url @username = username @password = password @login_mutex = Mutex.new @session = nil end |
Class Method Details
.init ⇒ Object
19 20 21 |
# File 'public/app/services/archives_space_client.rb', line 19 def self.init @instance = self.new end |
.instance ⇒ Object
23 24 25 |
# File 'public/app/services/archives_space_client.rb', line 23 def self.instance @instance end |
Instance Method Details
#advanced_search(base, page = 1, search_opts = {}) ⇒ Object
handles multi-line searching
59 60 61 62 63 64 65 |
# File 'public/app/services/archives_space_client.rb', line 59 def advanced_search(base, page = 1, search_opts = {}) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) url = build_url(base, search_opts.merge(:page => page)) results = do_search(url) SolrResults.new(results) end |
#get_raw_record(uri, search_opts = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'public/app/services/archives_space_client.rb', line 80 def get_raw_record(uri, search_opts = {}) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) url = build_url('/search/records', search_opts.merge("uri[]" => ASUtils.wrap(uri))) results = do_search(url) raise RecordNotFound.new if results.fetch('results', []).empty? ASUtils.json_parse(results.fetch('results').fetch(0).fetch('json')) end |
#get_record(uri, search_opts = {}) ⇒ Object
90 91 92 93 94 95 96 |
# File 'public/app/services/archives_space_client.rb', line 90 def get_record(uri, search_opts = {}) results = search_records(ASUtils.wrap(uri), search_opts, full_notes = true) raise RecordNotFound.new if results.empty? results.first end |
#get_repos_sublist(uri, type, search_opts = {}) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'public/app/services/archives_space_client.rb', line 127 def get_repos_sublist(uri, type, search_opts = {}) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) search_opts = search_opts.merge({"q" => "(used_within_published_repository:\"#{uri}\" AND publish:true AND types:pui_#{type})"}) url = build_url("/search", search_opts) results = do_search(url) SolrResults.new(results, search_opts) end |
#get_tree(node_uri) ⇒ Object
calls the ‘/search/published_tree’ endpoint
108 109 110 111 112 113 114 115 116 117 118 |
# File 'public/app/services/archives_space_client.rb', line 108 def get_tree(node_uri) tree = {} url = build_url('/search/published_tree', {:node_uri => node_uri}) begin results = do_search(url, true) tree = ASUtils.json_parse(results['tree_json']) rescue RequestFailedException => error Rails.logger.error("Tree search failed on #{node_uri} : #{error}") end tree end |
#get_types_counts(record_type_list, repo_uri = nil) ⇒ Object
120 121 122 123 124 125 |
# File 'public/app/services/archives_space_client.rb', line 120 def get_types_counts(record_type_list, repo_uri = nil) opts = {"record_types[]" => record_type_list} opts["repo_uri"] = repo_uri if repo_uri url = build_url('/search/record_types_by_repository', opts) results = do_search(url) end |
#list_repositories ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'public/app/services/archives_space_client.rb', line 39 def list_repositories repos = {} results = search_all_results("primary_type:repository") results.map { |result| Repository.from_json(ASUtils.json_parse(result['json'])) } .each { |r| repos[r['uri']] = r } repos end |
#search(query, page = 1, search_opts = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'public/app/services/archives_space_client.rb', line 50 def search(query, page = 1, search_opts = {}) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) url = build_url('/search', search_opts.merge(:q => query, :page => page)) results = do_search(url) SolrResults.new(results, search_opts) end |
#search_records(record_list, search_opts = {}, full_notes = false) ⇒ Object
calls the ‘/search/records’ endpoint
68 69 70 71 72 73 74 75 76 77 78 |
# File 'public/app/services/archives_space_client.rb', line 68 def search_records(record_list, search_opts = {}, full_notes = false) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) url = build_url('/search/records', search_opts.merge("uri[]" => record_list)) results = do_search(url) # Ensure that the order of our results matches the order of `record_list` results['results'] = results['results'].sort_by {|result| record_list.index(result.fetch('uri'))} SolrResults.new(results, search_opts, full_notes) end |
#search_repository(base, repo_id, page = 1, search_opts = {}) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'public/app/services/archives_space_client.rb', line 98 def search_repository( base, repo_id, page = 1, search_opts = {}) search_opts = DEFAULT_SEARCH_OPTS.merge(search_opts) url = build_url(base, search_opts.merge(:page => page)) results = do_search(url) SolrResults.new(results, search_opts) end |