Class: Talis::Bibliography::Work
- Extended by:
- Forwardable, Talis::Bibliography, OAuthService
- Defined in:
- lib/talis/bibliography/work.rb
Overview
Represents bibliographic works API operations provided by the Metatron gem https://github.com/talis/metatron_rb
In order to perform remote operations, the client must be configured with a valid OAuth client that is allowed to query nodes:
Talis::Authentication.client_id = 'client_id'
Talis::Authentication.client_secret = 'client_secret'
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
TODO: call assets route if not set.
-
#id ⇒ Object
Returns the value of attribute id.
-
#manifestations ⇒ Object
readonly
TODO: call manifestation route if not set.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
-
#work_data ⇒ Object
readonly
Returns the value of attribute work_data.
Attributes included from OAuthService
#client_id, #client_secret, #oauth_host
Class Method Summary collapse
-
.find(request_id: new_req_id, query:, include: [], opts: {}) ⇒ MetatronClient::WorkResultSet
Search for bibliographic works where works are of type Talis::Bibliography::Work, which are also available directly via the Enumerable methods: each, find, find_all, first, last.
-
.get(request_id: new_req_id, id:) ⇒ Object
Fetch a single work by id.
Instance Method Summary collapse
-
#hydrate_relationships(resources) ⇒ Object
By default, the metatron client returns generic ResourceLink objects as the related resources.
-
#initialize(work_data = nil) ⇒ Work
constructor
A new instance of Work.
Methods included from Talis::Bibliography
Methods inherited from Resource
Constructor Details
#initialize(work_data = nil) ⇒ Work
Returns a new instance of Work.
90 91 92 93 94 95 96 |
# File 'lib/talis/bibliography/work.rb', line 90 def initialize(work_data = nil) if work_data.is_a? MetatronClient::WorkData parse_work_data work_data else @work_data = MetatronClient::WorkData.new end end |
Instance Attribute Details
#assets ⇒ Object (readonly)
TODO: call assets route if not set
104 105 106 |
# File 'lib/talis/bibliography/work.rb', line 104 def assets @assets end |
#id ⇒ Object
Returns the value of attribute id.
19 20 21 |
# File 'lib/talis/bibliography/work.rb', line 19 def id @id end |
#manifestations ⇒ Object (readonly)
TODO: call manifestation route if not set
99 100 101 |
# File 'lib/talis/bibliography/work.rb', line 99 def manifestations @manifestations end |
#title ⇒ Object
Returns the value of attribute title.
19 20 21 |
# File 'lib/talis/bibliography/work.rb', line 19 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
19 20 21 |
# File 'lib/talis/bibliography/work.rb', line 19 def type @type end |
#work_data ⇒ Object (readonly)
Returns the value of attribute work_data.
18 19 20 |
# File 'lib/talis/bibliography/work.rb', line 18 def work_data @work_data end |
Class Method Details
.find(request_id: new_req_id, query:, include: [], opts: {}) ⇒ MetatronClient::WorkResultSet
Search for bibliographic works
where works are of type Talis::Bibliography::Work, which are also available
directly via the Enumerable methods: each, find, find_all, first, last
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/talis/bibliography/work.rb', line 45 def find(request_id: new_req_id, query:, include: [], opts: {}) query = escape_query(query) if opts[:escape_query] offset = opts[:offset] || 0 limit = opts[:limit] || 20 search_works(request_id, query, offset, limit, include) rescue MetatronClient::ApiError => error begin handle_response(error) rescue Talis::NotFoundError empty_result(offset, limit) end end |
.get(request_id: new_req_id, id:) ⇒ Object
Fetch a single work by id
66 67 68 69 70 71 72 73 74 |
# File 'lib/talis/bibliography/work.rb', line 66 def get(request_id: new_req_id, id:) new api_client(request_id).works_work_id_assets_get(id, token).data rescue MetatronClient::ApiError => error begin handle_response(error) rescue Talis::NotFoundError nil end end |
Instance Method Details
#hydrate_relationships(resources) ⇒ Object
By default, the metatron client returns generic ResourceLink objects as the related resources. When passed an array of Metatron::ResourceData objects, it will replace the ResourceLink objects with more appropriately typed objects
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/talis/bibliography/work.rb', line 113 def hydrate_relationships(resources) manifestations.map! do |m| resource = find_relationship_in_included m.manifestation_data.to_hash, resources return m unless resource hydrate_manifestation_assets resource, resources Manifestation.new(MetatronClient::ManifestationData.new( resource.to_hash )) end nil end |