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)

    Recursively request and in clude full compound item data? If false, basic compound data will STILL be included in the array value of the item hash key 'page'. 'page' is the term CONTENTdm uses to signify a list of child pages for an item.

  • 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.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/contentdm_api/item.rb', line 28

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



54
55
56
57
58
# File 'lib/contentdm_api/item.rb', line 54

def compounds_to_h
  page.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



46
47
48
49
50
51
52
# File 'lib/contentdm_api/item.rb', line 46

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