class Collections::Client

Constants

BASE_URL

Public Class Methods

new() click to toggle source
# File lib/nypl_collections/client.rb, line 16
def initialize
  reset
end

Public Instance Methods

return_captures_for_uuid(uuid, options= {}) click to toggle source

Return all capture UUIDs, imageIDs, itemLinks and titles (optional) for any UUID

# File lib/nypl_collections/client.rb, line 27
def return_captures_for_uuid(uuid, options= {})
  url = BASE_URL.clone
  token = auth_token
  uuid = uuid

  url << uuid + "?"

  if options[:withTitles]
    title = options[:withTitles]
    url << "withTitles=#{title}"
  end

  [:per_page, :page].each do |thing|
    set_urlparam(url, thing, options)
  end

  HTTParty.get(url,
    :headers => {
      "Authorization" => "Token token=#{token}"
    })
end
return_mods_record_for_capture_uuid(uuid) click to toggle source
# File lib/nypl_collections/client.rb, line 99
def return_mods_record_for_capture_uuid(uuid)
  url = BASE_URL.clone
  token = auth_token
  uuid = uuid

  url << "mods/#{uuid}"

  HTTParty.get(url,
    :headers => {
      "Authorization" => "Token token=#{token}"
    })

end
return_uuid_for_local_identifier(local_id_name, local_id_value) click to toggle source

Return uuid for a local identifier. Local_identifier field names can be found in the “type” attribute of the MODS <identifier> element

# File lib/nypl_collections/client.rb, line 52
def return_uuid_for_local_identifier(local_id_name, local_id_value)
  url = BASE_URL.clone
  token = auth_token
  local_id_name = local_id_name
  local_id_value = local_id_value

  url << "#{local_id_name}/#{local_id_value}"

  HTTParty.get(url,
    :headers => {
      "Authorization" => "Token token=#{token}"
    })
end
search_all_mods_fields(search_terms) click to toggle source

same as search_in_mods_fields but don’t need to specify a field

# File lib/nypl_collections/client.rb, line 86
def search_all_mods_fields(search_terms)
  url = BASE_URL.clone
  token = auth_token
  search_terms = search_terms.gsub(/ /, "-").gsub(/_/, "-")

  url << "search?q=#{search_terms}"

  HTTParty.get(url,
    :headers => {
      "Authorization" => "Token token=#{token}"
    })
end
search_in_mods_field(search_terms, field) click to toggle source

search in fields: identifier, typeOfResource, note title, namePart, place, publisher, topic, geographic, temporal, genre, physicalLocation, and shelfLocator enter search_terms

# File lib/nypl_collections/client.rb, line 71
def search_in_mods_field(search_terms, field)
  url = BASE_URL.clone
  token = auth_token
  search_terms = search_terms.gsub(/ /, "-").gsub(/_/, "-")
  field = field

  url << "search?q=#{search_terms}&field=#{field}"

  HTTParty.get(url,
    :headers => {
      "Authorization" => "Token token=#{token}"
    })
end
set_urlparam(url, name, options) click to toggle source
# File lib/nypl_collections/client.rb, line 20
def set_urlparam(url, name, options)
  return unless options[name]
  url << "&#{name.to_s.gsub(/ /,'_')}=#{options[name]}"
end