Class: CONTENTdmAPI::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/contentdm_api/item.rb

Overview

A convenience method to retrive a Ruby hash of Item data from the CONTENTdm API along with an optional call to fetch Compound Object Info

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: '', collection: '', id: 0, with_compound: true, requester: RequestBatch, response: Response) ⇒ Void

compound?

Parameters:

  • base_url (String) (defaults to: '')

    URL to the CONTENTdm API “CdmServer.com:port/dmwebservices/index.php

  • collection (String) (defaults to: '')

    The CONTENTdm API calls this an “alias”

  • id (Integer) (defaults to: 0)

    The CONTENTdm API calls this a “pointer”. It is the identifier for a a given CONTENTdm item.

  • with_compound (Boolean) (defaults to: true)

    Include compound object info?

  • enrich_compount (Boolean)

    Fetch and merge full item info for each

  • requester (Object) (defaults to: RequestBatch)

    A class to make requests of the API.

  • response (Object) (defaults to: Response)

    A class to parse API responses.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/contentdm_api/item.rb', line 25

def initialize(base_url: '',
               collection: '',
               id: 0,
               with_compound: true,
               requester: RequestBatch,
               response: Response)
  @collection       = collection
  @id               = id
  @with_compound    = with_compound
  @requester        = requester
  @base_url         = base_url
  @response         = response
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def base_url
  @base_url
end

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def collection
  @collection
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def id
  @id
end

#requesterObject (readonly)

Returns the value of attribute requester.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def requester
  @requester
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def response
  @response
end

#with_compoundObject (readonly)

Returns the value of attribute with_compound.



5
6
7
# File 'lib/contentdm_api/item.rb', line 5

def with_compound
  @with_compound
end

Instance Method Details

#compounds_to_hObject



51
52
53
54
55
# File 'lib/contentdm_api/item.rb', line 51

def compounds_to_h
  [page].flatten.map do |compound|
    block_given? ? yield(compound(compound)) : compound(compound)
  end
end

#metadataHash

A hash of item metadata with optional compound data for the given item

dmGetCompoundObjectInfo functions

Returns:

  • (Hash)

    Merged responses from the dmGetItemInfo and



43
44
45
46
47
48
49
# File 'lib/contentdm_api/item.rb', line 43

def 
  if with_compound
    result_with_id.merge('page' => compounds_to_h)
  else
    result_with_id.merge('page' => [])
  end
end