Class: Collections::Client

Inherits:
Object
  • Object
show all
Includes:
Configuration, HTTParty
Defined in:
lib/nypl_collections/client.rb

Constant Summary collapse

BASE_URL =
"http://api.repo.nypl.org/api/v1/items/"

Instance Attribute Summary

Attributes included from Configuration

#auth_token

Instance Method Summary collapse

Methods included from Configuration

#configure, #reset

Constructor Details

#initializeClient

Returns a new instance of Client.



16
17
18
# File 'lib/nypl_collections/client.rb', line 16

def initialize
  reset
end

Instance Method Details

#return_captures_for_uuid(uuid, options = {}) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# 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) ⇒ Object

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



52
53
54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object

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



86
87
88
89
90
91
92
93
94
95
96
97
# 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) ⇒ Object

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



71
72
73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



20
21
22
23
# 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