Class: Qa::Authorities::Discogs::GenericAuthority
- Includes:
- DiscogsTranslation, WebServiceBase
- Defined in:
- lib/qa/authorities/discogs/generic_authority.rb
Constant Summary
Constants included from DiscogsUtils
DiscogsUtils::DISCOGS_FORMATS_MAPPING, DiscogsUtils::DISCOGS_GENRE_MAPPING
Instance Attribute Summary collapse
-
#primary_artists ⇒ Object
Returns the value of attribute primary_artists.
Attributes included from WebServiceBase
Instance Method Summary collapse
-
#build_query_url(q, subauthority) ⇒ String
The url.
-
#find(id, tc) ⇒ Object
If the subauthority = “all” (though it shouldn’t), call the fetch_discogs_results method to determine whether the id matches a release or master.
-
#find_url(id, subauthority) ⇒ String
The url.
-
#initialize(subauthority) ⇒ GenericAuthority
constructor
A new instance of GenericAuthority.
-
#search(q, tc) ⇒ Object
Json results.
Methods included from DiscogsTranslation
#build_graph, #build_instance_statements, #build_master_statements, #compile_rdf_statements, #get_primary_artists_stmts, #get_primary_instance_definition, #get_primary_work_definition, #master_only
Methods included from DiscogsInstanceBuilder
#build_base_materials, #build_format_characteristics, #build_format_desc_stmts, #build_format_name_stmts, #build_provision_activity_stmts, #get_format_stmts, #get_identifiers_stmts, #get_labels_stmts
Methods included from DiscogsUtils
#bf_agent_predicate, #bf_agent_type_object, #bf_main_title_predicate, #bf_role_predicate, #bf_role_type_object, #build_year_statements, #contruct_stmt_literal_object, #contruct_stmt_uri_object, #discogs_formats, #discogs_genres, #get_year_rdf, #rdf_type_predicate, #rdfs_label_predicate
Methods included from DiscogsWorksBuilder
#build_artist_array, #build_artist_role_stmts, #build_genres, #build_genres_and_styles, #build_secondary_works, #build_track_artists, #build_track_extraartists, #get_extra_artists_stmts, #get_genres_stmts, #get_tracklist_artists_stmts
Methods included from WebServiceBase
Methods inherited from Base
Constructor Details
#initialize(subauthority) ⇒ GenericAuthority
Returns a new instance of GenericAuthority.
11 12 13 14 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 11 def initialize() @subauthority = self.primary_artists = [] end |
Instance Attribute Details
#primary_artists ⇒ Object
Returns the value of attribute primary_artists.
8 9 10 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 8 def primary_artists @primary_artists end |
Instance Method Details
#build_query_url(q, subauthority) ⇒ String
Returns the url.
50 51 52 53 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 50 def build_query_url(q, ) escaped_q = ERB::Util.url_encode(q) "https://api.discogs.com/database/search?q=#{escaped_q}&type=#{}&key=#{discogs_key}&secret=#{discogs_secret}" end |
#find(id, tc) ⇒ Object
If the subauthority = “all” (though it shouldn’t), call the fetch_discogs_results method to determine whether the id matches a release or master. And if the requested format is json-ld, call the build_graph method in the translation module; otherwise, just return the Discogs json. check the response to determine if it should go to the translation module.
39 40 41 42 43 44 45 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 39 def find(id, tc) response = tc.params["subauthority"].include?("all") ? fetch_discogs_results(id) : json(find_url(id, tc.params["subauthority"])) return response if response["message"].present? return build_graph(response, format: :jsonld) if jsonld?(tc) return build_graph(response, format: :n3) if n3?(tc) response end |
#find_url(id, subauthority) ⇒ String
Returns the url.
58 59 60 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 58 def find_url(id, ) "https://api.discogs.com/#{}s/#{id}" end |
#search(q, tc) ⇒ Object
Returns json results.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qa/authorities/discogs/generic_authority.rb', line 19 def search(q, tc) # Discogs distinguishes between masters and releases, where a release represents a specific # physical or digital object and a master represents a set of similar releases. Use of a # subauthority (e.g., /qa/search/discogs/master) will target a specific type. Using the "all" # subauthority will search for both types. unless discogs_key && discogs_secret Rails.logger.error "Questioning Authority tried to call Discogs, but no secret and/or key were set." return [] end (json(build_query_url(q, tc.params["subauthority"]))) end |