nypl_repo 0.0.0 → 0.0.1

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 +4 -4
  2. data/lib/nypl_repo.rb +72 -67
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb5500a147b503fcd04cfe129916f6ce70f616c6
4
- data.tar.gz: efa364343b41711e6e1c2cb0eb361495b097398d
3
+ metadata.gz: d14fbf5c39bae47ed8819cda82047823410882f4
4
+ data.tar.gz: 1e3ec66444af00d0c32473c758d2a3348d1455b5
5
5
  SHA512:
6
- metadata.gz: 74bcee588e53749dfa5029255495bad0969176cabfdc7b81b67f3ff36d679db0cf6efa5023c107cdf2f3a7fab413f26bf40628743a73b5d7c594f612052122bb
7
- data.tar.gz: 345fc3e9449700dfbfbd4e0d0ad3f279a706af65aefc7d13f85e2bad9cc5c0c0fdbd2b1fdb791ea5721de312428554a83f5a609b4b8b2850d39bfe50c5a6550e
6
+ metadata.gz: 310aa5eff1ca34c92562a4522044bfe0bb4e45cfcded0c4addc8bb5008ab21b364d4b68d51127c91943dcf2bf2cd7fc6ee6579c55f8e219a00f379977a605922
7
+ data.tar.gz: e251ed77ae2f7f9b372530e023748c91636deb06296be0c49b5a26c79f2f16f68c263ff493aa1a33c579931b865b65979aa307a6e6896c4f9873fc40270fdd06
data/lib/nypl_repo.rb CHANGED
@@ -1,85 +1,90 @@
1
- class NyplRepo
1
+ module NyplRepo
2
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"]
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
- 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
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
- # 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"]
40
+ return mods_uuid
42
41
  end
43
-
44
- return bibl_uuid
45
- end
46
42
 
47
43
 
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
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
- return highreslink
64
- end
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
- def self.get_token
67
- return REPO_CONFIG[:token]
68
- end
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
- 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)
76
+ def get_json(url)
77
+ uri = URI.parse(url)
78
+ http = Net::HTTP.new(uri.host, uri.port)
80
79
 
81
- return json
82
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nypl_repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Waters