met_museum 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 900cb94a372a90f0d57977e7f6ac59288016387db01674fb8ad8289781674fc1
4
- data.tar.gz: 4872ea946934abcd6f33e774940ea913f26f5bd322e8de0f3e9a07be270cb9de
3
+ metadata.gz: e3ac1a24a596274e2252ecc37f739f06e0e2ed55aa98e3cc12d16adac23f97c0
4
+ data.tar.gz: 0f8e891db7317c98f83ed46c81eac19e380aed302a22caacefc243582fb191b2
5
5
  SHA512:
6
- metadata.gz: 51254a6caafca44ad8a797a10ce992a71ccfaa9b1069c87644fbc269489dd991f059b7a66a0cdf05aab4d555e14ef7728367a86f9c037a148ec2fe53e5abbf3a
7
- data.tar.gz: 38c930bd7f2ebbf65d3bd4232608060c4c71634a6aeaedb6166467bf9f5ea1157910efb717c19c7cf079e6194aa40bfb9a25340ce94ac67e7dc58a550d44c562
6
+ metadata.gz: 91b57da1c9bdcee4674f558e6bc89f0f01b9d60b9f353df2e6a1f8cd6a81bd48c690d821cd786b88827bc811ad8a55b58e40570d758e932491ec6e75534b83ac
7
+ data.tar.gz: e5242fd7a3f2a39b569b1e828e99b0767007b2c2693f5c153cb832445d1705ff5b7db6e3aa0c5617154b200caf3aa4bff7583be8c00448015d0740f8052f9870
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- met_museum (0.1.2)
4
+ met_museum (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -32,7 +32,9 @@ The description of the method is as follows
32
32
  </summary>
33
33
  <pre>
34
34
  ```
35
- MetMuseum::Collection.objects
35
+ collection = MetMuseum::Collection.new()
36
+
37
+ collection.objects
36
38
  => {"total"=>490607,
37
39
  "objectIDs"=>
38
40
  [1,
@@ -45,7 +47,8 @@ MetMuseum::Collection.objects
45
47
  8,
46
48
  --< omit >--
47
49
  820613]}
48
- MetMuseum::Collection.objects('2018-10-10')
50
+
51
+ collection.objects('2018-10-10')
49
52
  =>{"total"=>88232,
50
53
  "objectIDs"=>
51
54
  [33,
@@ -65,7 +68,9 @@ MetMuseum::Collection.objects('2018-10-10')
65
68
  </summary>
66
69
  <pre>
67
70
  ```
68
- MetMuseum::Collection.object(1000)
71
+ collection = MetMuseum::Collection.new()
72
+
73
+ collection.object(1000)
69
74
  => {"objectID"=>1000,
70
75
  "isHighlight"=>false,
71
76
  "accessionNumber"=>"10.149.99",
@@ -1,16 +1,36 @@
1
1
  module MetMuseum
2
2
  class Collection
3
+ MetMuseumError = Class.new(StandardError)
4
+ BadRequestError = Class.new(MetMuseumError)
5
+ UnauthorizedError = Class.new(MetMuseumError)
6
+ ForbiddenError = Class.new(MetMuseumError)
7
+ ApiRequestsQuotaReachedError = Class.new(MetMuseumError)
8
+ NotFoundError = Class.new(MetMuseumError)
9
+ UnprocessableEntityError = Class.new(MetMuseumError)
10
+ ApiError = Class.new(MetMuseumError)
11
+
3
12
  API_ENDPOINT = "https://collectionapi.metmuseum.org".freeze
4
13
  PUBLIC_URI = "/public/collection/v1/objects".freeze
5
14
 
15
+ HTTP_OK_CODE = 200.freeze
16
+
17
+ HTTP_BAD_REQUEST_CODE = 400.freeze
18
+ HTTP_UNAUTHORIZED_CODE = 401.freeze
19
+ HTTP_FORBIDDEN_CODE = 403.freeze
20
+ HTTP_NOT_FOUND_CODE = 404.freeze
21
+ HTTP_UNPROCESSABLE_ENTITY_CODE = 429.freeze
22
+
23
+
6
24
  # Return a listing of all valid Object IDs available to use
7
25
  # @param [String] metadataDate Returns any objects with updated data after this date
8
26
  # @return [Hash<total, Integer>] The total number of publicly-available objects
9
27
  # @return [Hash<objectIDs, Array<Integer>>] An array containing the object ID of publicly-available object
10
- def self.objects(metadataDate = nil)
28
+ def objects(metadataDate = nil)
11
29
  conn = Faraday.new(:url => API_ENDPOINT)
12
30
  response = conn.get PUBLIC_URI, {:metadataDate => metadataDate}
13
- Oj.load(response.body)
31
+ Oj.load(response.body) if response_successful?(response)
32
+
33
+ raise error_class(response), "Code: #{response.status}, response: #{response.body}"
14
34
  end
15
35
 
16
36
  # returns a record for an object, containing all open access data about that object, including its image (if the image is available under Open Access)
@@ -65,9 +85,33 @@ module MetMuseum
65
85
  # @return [Hash<repository, String>]
66
86
  # @return [Hash<objectURL, String>] URL to object's page on metmuseum.org
67
87
  # @return [Hash<total, String>] The total number of publicly-available objects
68
- def self.object(objectID)
88
+ def object(objectID)
69
89
  response = Faraday.get "#{API_ENDPOINT}#{PUBLIC_URI}/#{objectID}"
70
- Oj.load(response.body)
90
+ Oj.load(response.body)if response_successful?(response)
91
+
92
+ raise error_class(response), "Code: #{response.status}, response: #{response.body}"
93
+ end
94
+
95
+ def error_class(response)
96
+ case response.status
97
+ when HTTP_BAD_REQUEST_CODE
98
+ BadRequestError
99
+ when HTTP_UNAUTHORIZED_CODE
100
+ UnauthorizedError
101
+ when HTTP_FORBIDDEN_CODE
102
+ return ApiRequestsQuotaReachedError if api_requests_quota_reached?
103
+ ForbiddenError
104
+ when HTTP_NOT_FOUND_CODE
105
+ NotFoundError
106
+ when HTTP_UNPROCESSABLE_ENTITY_CODE
107
+ UnprocessableEntityError
108
+ else
109
+ ApiError
110
+ end
111
+ end
112
+
113
+ def response_successful?(response)
114
+ response.status == HTTP_OK_CODE
71
115
  end
72
116
  end
73
117
  end
@@ -1,3 +1,3 @@
1
1
  module MetMuseum
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: met_museum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hyuraku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-31 00:00:00.000000000 Z
11
+ date: 2019-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler