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], 'hl' => true }
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.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'public/app/services/archives_space_client.rb', line 29 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
21 22 23 |
# File 'public/app/services/archives_space_client.rb', line 21 def self.init @instance = self.new end |
.instance ⇒ Object
25 26 27 |
# File 'public/app/services/archives_space_client.rb', line 25 def self.instance @instance end |
Instance Method Details
#advanced_search(base, page = 1, search_opts = {}) ⇒ Object
handles multi-line searching
61 62 63 64 65 66 67 |
# File 'public/app/services/archives_space_client.rb', line 61 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
82 83 84 85 86 87 88 89 90 |
# File 'public/app/services/archives_space_client.rb', line 82 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
92 93 94 95 96 97 98 |
# File 'public/app/services/archives_space_client.rb', line 92 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
129 130 131 132 133 134 135 136 |
# File 'public/app/services/archives_space_client.rb', line 129 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
110 111 112 113 114 115 116 117 118 119 120 |
# File 'public/app/services/archives_space_client.rb', line 110 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
122 123 124 125 126 127 |
# File 'public/app/services/archives_space_client.rb', line 122 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
41 42 43 44 45 46 47 48 49 50 |
# File 'public/app/services/archives_space_client.rb', line 41 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
52 53 54 55 56 57 58 |
# File 'public/app/services/archives_space_client.rb', line 52 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
70 71 72 73 74 75 76 77 78 79 80 |
# File 'public/app/services/archives_space_client.rb', line 70 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
100 101 102 103 104 105 106 107 |
# File 'public/app/services/archives_space_client.rb', line 100 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 |