nypl_repo 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/nypl_repo.rb +85 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb5500a147b503fcd04cfe129916f6ce70f616c6
4
+ data.tar.gz: efa364343b41711e6e1c2cb0eb361495b097398d
5
+ SHA512:
6
+ metadata.gz: 74bcee588e53749dfa5029255495bad0969176cabfdc7b81b67f3ff36d679db0cf6efa5023c107cdf2f3a7fab413f26bf40628743a73b5d7c594f612052122bb
7
+ data.tar.gz: 345fc3e9449700dfbfbd4e0d0ad3f279a706af65aefc7d13f85e2bad9cc5c0c0fdbd2b1fdb791ea5721de312428554a83f5a609b4b8b2850d39bfe50c5a6550e
data/lib/nypl_repo.rb ADDED
@@ -0,0 +1,85 @@
1
+ class NyplRepo
2
+
3
+ #get the item detail from a uuid
4
+ def self.get_mods_item(mods_uuid)
5
+ url = "http://api.repo.nypl.org/api/v1/items/mods/#{mods_uuid}.json"
6
+ json = self.get_json(url)
7
+
8
+ item = nil
9
+ if json["nyplAPI"]["response"]["mods"]
10
+ item = json["nyplAPI"]["response"]["mods"]
11
+ end
12
+
13
+ return item
14
+ end
15
+
16
+ #gets the mods uuid of the item, passing in the bibliographic uuid and image_id
17
+ #since there could be many maps for the same item
18
+ def self.get_mods_uuid(bibl_uuid, image_id)
19
+ url = "http://api.repo.nypl.org/api/v1/items/#{bibl_uuid}.json?per_page=500"
20
+ json = self.get_json(url)
21
+ mods_uuid = nil
22
+ puts url
23
+ json["nyplAPI"]["response"]["capture"].each do | capture|
24
+ if capture["imageID"] == image_id
25
+ mods_uuid = capture["uuid"]
26
+ break
27
+ end #if
28
+ end if json["nyplAPI"]["response"]["numResults"].to_i > 0
29
+
30
+
31
+ return mods_uuid
32
+ end
33
+
34
+
35
+ # get bibliographic container uuid from an image_id
36
+ def self.get_bibl_uuid(image_id)
37
+ url = "http://api.repo.nypl.org/api/v1/items/local_image_id/#{image_id}.json"
38
+ json = self.get_json(url)
39
+ bibl_uuid = nil
40
+ if json["nyplAPI"]["response"]["numResults"].to_i > 0
41
+ bibl_uuid = json["nyplAPI"]["response"]["uuid"]
42
+ end
43
+
44
+ return bibl_uuid
45
+ end
46
+
47
+
48
+ #get highreslink from an item, matching up the image idi
49
+ #since some bibliographic items may have many maps under them
50
+ def self.get_highreslink(bibl_uuid, image_id)
51
+ url = "http://api.repo.nypl.org/api/v1/items/#{bibl_uuid}.json?per_page=500"
52
+ json = self.get_json(url)
53
+
54
+ highreslink = nil
55
+
56
+ json["nyplAPI"]["response"]["capture"].each do | capture|
57
+ if capture["imageID"] == image_id
58
+ highreslink = capture["highResLink"]
59
+ break
60
+ end #if
61
+ end if json["nyplAPI"]["response"]["numResults"].to_i > 0
62
+
63
+ return highreslink
64
+ end
65
+
66
+ def self.get_token
67
+ return REPO_CONFIG[:token]
68
+ end
69
+
70
+
71
+ def self.get_json(url)
72
+ uri = URI.parse(url)
73
+ http = Net::HTTP.new(uri.host, uri.port)
74
+
75
+ headers = { "Authorization" => "Token token=#{REPO_CONFIG[:token]}" }
76
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
77
+ response = http.request(request)
78
+ body = response.body
79
+ json = JSON.parse(body)
80
+
81
+ return json
82
+ end
83
+
84
+
85
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nypl_repo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Waters
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A basic library for interacting with the NYPL Digital Collections Repo
14
+ API
15
+ email: chippy2005@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/nypl_repo.rb
21
+ homepage: http://rubygems.org/gems/nypl_repo
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: NYPL Repo API Library
45
+ test_files: []