nypl_repo 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nypl_repo.rb +72 -67
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d14fbf5c39bae47ed8819cda82047823410882f4
|
4
|
+
data.tar.gz: 1e3ec66444af00d0c32473c758d2a3348d1455b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310aa5eff1ca34c92562a4522044bfe0bb4e45cfcded0c4addc8bb5008ab21b364d4b68d51127c91943dcf2bf2cd7fc6ee6579c55f8e219a00f379977a605922
|
7
|
+
data.tar.gz: e251ed77ae2f7f9b372530e023748c91636deb06296be0c49b5a26c79f2f16f68c263ff493aa1a33c579931b865b65979aa307a6e6896c4f9873fc40270fdd06
|
data/lib/nypl_repo.rb
CHANGED
@@ -1,85 +1,90 @@
|
|
1
|
-
|
1
|
+
module NyplRepo
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
class Client
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
def initialize(token)
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
#get the item detail from a uuid
|
13
|
+
def get_mods_item(mods_uuid)
|
14
|
+
url = "http://api.repo.nypl.org/api/v1/items/mods/#{mods_uuid}.json"
|
15
|
+
json = self.get_json(url)
|
16
|
+
|
17
|
+
item = nil
|
18
|
+
if json["nyplAPI"]["response"]["mods"]
|
19
|
+
item = json["nyplAPI"]["response"]["mods"]
|
20
|
+
end
|
21
|
+
|
22
|
+
return item
|
11
23
|
end
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
break
|
27
|
-
end #if
|
28
|
-
end if json["nyplAPI"]["response"]["numResults"].to_i > 0
|
29
|
-
|
30
|
-
|
31
|
-
return mods_uuid
|
32
|
-
end
|
25
|
+
#gets the mods uuid of the item, passing in the bibliographic uuid and image_id
|
26
|
+
#since there could be many maps for the same item
|
27
|
+
def get_mods_uuid(bibl_uuid, image_id)
|
28
|
+
url = "http://api.repo.nypl.org/api/v1/items/#{bibl_uuid}.json?per_page=500"
|
29
|
+
json = self.get_json(url)
|
30
|
+
mods_uuid = nil
|
31
|
+
|
32
|
+
json["nyplAPI"]["response"]["capture"].each do | capture|
|
33
|
+
if capture["imageID"] == image_id
|
34
|
+
mods_uuid = capture["uuid"]
|
35
|
+
break
|
36
|
+
end #if
|
37
|
+
end if json["nyplAPI"]["response"]["numResults"].to_i > 0
|
33
38
|
|
34
39
|
|
35
|
-
|
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"]
|
40
|
+
return mods_uuid
|
42
41
|
end
|
43
|
-
|
44
|
-
return bibl_uuid
|
45
|
-
end
|
46
42
|
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
# get bibliographic container uuid from an image_id
|
45
|
+
def get_bibl_uuid(image_id)
|
46
|
+
url = "http://api.repo.nypl.org/api/v1/items/local_image_id/#{image_id}.json"
|
47
|
+
json = self.get_json(url)
|
48
|
+
bibl_uuid = nil
|
49
|
+
if json["nyplAPI"]["response"]["numResults"].to_i > 0
|
50
|
+
bibl_uuid = json["nyplAPI"]["response"]["uuid"]
|
51
|
+
end
|
52
|
+
|
53
|
+
return bibl_uuid
|
54
|
+
end
|
55
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
56
|
|
63
|
-
|
64
|
-
|
57
|
+
#get highreslink from an item, matching up the image idi
|
58
|
+
#since some bibliographic items may have many maps under them
|
59
|
+
def get_highreslink(bibl_uuid, image_id)
|
60
|
+
url = "http://api.repo.nypl.org/api/v1/items/#{bibl_uuid}.json?per_page=500"
|
61
|
+
json = self.get_json(url)
|
62
|
+
|
63
|
+
highreslink = nil
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
json["nyplAPI"]["response"]["capture"].each do | capture|
|
66
|
+
if capture["imageID"] == image_id
|
67
|
+
highreslink = capture["highResLink"]
|
68
|
+
break
|
69
|
+
end #if
|
70
|
+
end if json["nyplAPI"]["response"]["numResults"].to_i > 0
|
69
71
|
|
72
|
+
return highreslink
|
73
|
+
end
|
70
74
|
|
71
|
-
def self.get_json(url)
|
72
|
-
uri = URI.parse(url)
|
73
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
body = response.body
|
79
|
-
json = JSON.parse(body)
|
76
|
+
def get_json(url)
|
77
|
+
uri = URI.parse(url)
|
78
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
80
79
|
|
81
|
-
|
82
|
-
|
80
|
+
headers = { "Authorization" => "Token token=#{@token}" }
|
81
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
82
|
+
response = http.request(request)
|
83
|
+
body = response.body
|
84
|
+
json = JSON.parse(body)
|
83
85
|
|
86
|
+
return json
|
87
|
+
end
|
84
88
|
|
85
89
|
end
|
90
|
+
end
|