met_museum 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -1
- data/.rbgithook/pre-commit +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -44
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/met_museum/collection.rb +24 -17
- data/lib/met_museum/http_status_code.rb +4 -2
- data/lib/met_museum/version.rb +1 -1
- data/lib/met_museum.rb +0 -3
- data/met_museum.gemspec +0 -3
- metadata +8 -35
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f5c8d43daa6e64da5cb3c6788ee090c82070d84d9dbca31afb0bb3463dfcdc
|
4
|
+
data.tar.gz: 2bbbf5262f1bef794f6af6b7656903d17b1b9b11b5b37679a49a6abb852a6818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03053e41e8aa40ab045f480a7bfbe0bfb38a2a909d5776f937938acec59afc3d964cb508e5756de2e11ae123059718659a8e4bcd74247e3eb84837c6ba9d9b9b
|
7
|
+
data.tar.gz: 214a6dd1cbeb31b8aa221fe794c7f3bcda4af5ef6ab41498830c8e4cd0582c2d7ea30178eff241f0c177ee618ab40dc577e1fbaa7492a2ecbadc0378bcffa13b
|
data/.github/workflows/ruby.yml
CHANGED
@@ -15,7 +15,7 @@ jobs:
|
|
15
15
|
runs-on: ubuntu-latest
|
16
16
|
strategy:
|
17
17
|
matrix:
|
18
|
-
ruby: [ '2.
|
18
|
+
ruby: [ '2.7', '3.0', '3.1' ]
|
19
19
|
name: Ruby ${{ matrix.ruby }} spec
|
20
20
|
steps:
|
21
21
|
- uses: actions/checkout@v2
|
@@ -26,6 +26,7 @@ jobs:
|
|
26
26
|
# uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
27
27
|
with:
|
28
28
|
ruby-version: ${{ matrix.ruby }}
|
29
|
+
bundler-cache: true
|
29
30
|
- name: Install dependencies
|
30
31
|
run: bundle install
|
31
32
|
- name: Run spec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,61 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
met_museum (1.4.
|
5
|
-
faraday
|
6
|
-
oj
|
4
|
+
met_museum (1.4.2)
|
7
5
|
|
8
6
|
GEM
|
9
7
|
remote: https://rubygems.org/
|
10
8
|
specs:
|
11
|
-
ast (2.4.
|
12
|
-
coderay (1.1.
|
13
|
-
diff-lcs (1.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
method_source (0.9.2)
|
18
|
-
multipart-post (2.1.1)
|
19
|
-
oj (3.10.6)
|
20
|
-
parallel (1.19.2)
|
21
|
-
parser (2.7.1.4)
|
9
|
+
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
method_source (1.0.0)
|
13
|
+
parallel (1.22.1)
|
14
|
+
parser (3.1.2.0)
|
22
15
|
ast (~> 2.4.1)
|
23
|
-
pry (0.
|
24
|
-
coderay (~> 1.1
|
25
|
-
method_source (~>
|
26
|
-
rainbow (3.
|
27
|
-
rake (13.0.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
rspec-
|
33
|
-
rspec-
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
pry (0.14.1)
|
17
|
+
coderay (~> 1.1)
|
18
|
+
method_source (~> 1.0)
|
19
|
+
rainbow (3.1.1)
|
20
|
+
rake (13.0.6)
|
21
|
+
rbgithook (0.1.2)
|
22
|
+
regexp_parser (2.5.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.11.0)
|
25
|
+
rspec-core (~> 3.11.0)
|
26
|
+
rspec-expectations (~> 3.11.0)
|
27
|
+
rspec-mocks (~> 3.11.0)
|
28
|
+
rspec-core (3.11.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-expectations (3.11.0)
|
37
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-mocks (3.
|
32
|
+
rspec-support (~> 3.11.0)
|
33
|
+
rspec-mocks (3.11.1)
|
40
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-retry (0.6.
|
35
|
+
rspec-support (~> 3.11.0)
|
36
|
+
rspec-retry (0.6.2)
|
43
37
|
rspec-core (> 3.3)
|
44
|
-
rspec-support (3.
|
45
|
-
rubocop (
|
38
|
+
rspec-support (3.11.0)
|
39
|
+
rubocop (1.30.1)
|
46
40
|
parallel (~> 1.10)
|
47
|
-
parser (>=
|
41
|
+
parser (>= 3.1.0.0)
|
48
42
|
rainbow (>= 2.2.2, < 4.0)
|
49
|
-
regexp_parser (>= 1.
|
50
|
-
rexml
|
51
|
-
rubocop-ast (>=
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
52
46
|
ruby-progressbar (~> 1.7)
|
53
|
-
unicode-display_width (>= 1.4.0, <
|
54
|
-
rubocop-ast (
|
55
|
-
parser (>=
|
56
|
-
ruby-progressbar (1.
|
57
|
-
|
58
|
-
unicode-display_width (1.7.0)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.18.0)
|
49
|
+
parser (>= 3.1.1.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
unicode-display_width (2.1.0)
|
59
52
|
|
60
53
|
PLATFORMS
|
61
54
|
ruby
|
@@ -65,6 +58,7 @@ DEPENDENCIES
|
|
65
58
|
met_museum!
|
66
59
|
pry
|
67
60
|
rake (~> 13.0)
|
61
|
+
rbgithook (~> 0.1.2)
|
68
62
|
rspec (~> 3.0)
|
69
63
|
rspec-retry
|
70
64
|
rubocop
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<img src="https://img.shields.io/
|
1
|
+
<img src="https://img.shields.io/github/workflow/status/hyuraku/rbgithook/Ruby"> <img src="https://img.shields.io/github/license/hyuraku/met_museum.svg">
|
2
2
|
<img src="https://img.shields.io/gem/v/met_museum.svg">
|
3
3
|
# MetMuseum
|
4
4
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "met_museum/api_expections"
|
2
1
|
require "met_museum/endpoint"
|
3
2
|
require "met_museum/http_status_code"
|
4
3
|
|
@@ -15,10 +14,11 @@ module MetMuseum
|
|
15
14
|
metadataDate: nil,
|
16
15
|
departmentIds: nil
|
17
16
|
}.merge(args)
|
17
|
+
|
18
18
|
options[:metadataDate] = check_date(options[:metadataDate])
|
19
19
|
query = { metadataDate: options[:metadataDate], departmentIds: options[:departmentIds] }
|
20
|
-
response =
|
21
|
-
|
20
|
+
response = create_request(API_ENDPOINT, PUBLIC_URI, query)
|
21
|
+
arrange_response(response)
|
22
22
|
end
|
23
23
|
|
24
24
|
# 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)
|
@@ -80,8 +80,8 @@ module MetMuseum
|
|
80
80
|
# @return [Hash<GalleryNumber, string>] Gallery number, where available
|
81
81
|
|
82
82
|
def object(object_id)
|
83
|
-
response =
|
84
|
-
|
83
|
+
response = create_request(API_ENDPOINT, "#{PUBLIC_URI}/#{object_id}")
|
84
|
+
arrange_response(response)
|
85
85
|
end
|
86
86
|
|
87
87
|
# returns a listing of all departments
|
@@ -89,8 +89,8 @@ module MetMuseum
|
|
89
89
|
# @return [Integer] departments Department ID as an integer. The departmentId is to be used as a query parameter on the `/objects` endpoint
|
90
90
|
# @return [String] departments Display name for a department
|
91
91
|
def department
|
92
|
-
response =
|
93
|
-
|
92
|
+
response = create_request(API_ENDPOINT, DEPARTMENTS_URI)
|
93
|
+
arrange_response(response)
|
94
94
|
end
|
95
95
|
|
96
96
|
# returns a listing of all Object IDs for objects that contain the search query within the object’s data
|
@@ -102,22 +102,27 @@ module MetMuseum
|
|
102
102
|
# @return [Array<Object>] objects An array containing the objects that contain the search query within the object’s data
|
103
103
|
def search(query, **args)
|
104
104
|
args.merge!({q: query})
|
105
|
-
response =
|
106
|
-
origin_response =
|
105
|
+
response = create_request(API_ENDPOINT, SEARCH_URI, args)
|
106
|
+
origin_response = arrange_response(response)
|
107
107
|
limit = args[:limit].to_i
|
108
108
|
return origin_response if limit <= 0
|
109
109
|
|
110
|
-
origin_response["objectIDs"]
|
110
|
+
origin_response["objectIDs"].lazy.map { |id| MetMuseum::Collection.new.object(id) }.first(limit)
|
111
111
|
end
|
112
112
|
|
113
113
|
private
|
114
114
|
|
115
|
-
def
|
116
|
-
|
115
|
+
def create_request(url, dir, params = {})
|
116
|
+
require 'uri'
|
117
|
+
require 'net/http'
|
118
|
+
|
119
|
+
uri = URI.join(url, dir)
|
120
|
+
uri.query = URI.encode_www_form(params)
|
121
|
+
Net::HTTP.get_response(uri)
|
117
122
|
end
|
118
123
|
|
119
|
-
def response_successful?(
|
120
|
-
|
124
|
+
def response_successful?(response_code)
|
125
|
+
response_code == HTTP_OK_CODE
|
121
126
|
end
|
122
127
|
|
123
128
|
def check_date(date)
|
@@ -127,10 +132,12 @@ module MetMuseum
|
|
127
132
|
raise TypeError, "Write certain date"
|
128
133
|
end
|
129
134
|
|
130
|
-
def
|
131
|
-
|
135
|
+
def arrange_response(response)
|
136
|
+
response_code = response.code.to_i
|
137
|
+
require 'json'
|
138
|
+
return JSON.parse(response.body) if response_successful?(response_code)
|
132
139
|
|
133
|
-
raise MetMuseum.error_class(
|
140
|
+
raise MetMuseum.error_class(response_code), "Code: #{response_code}, response: #{response.body}"
|
134
141
|
end
|
135
142
|
|
136
143
|
def multi_option
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "met_museum/api_expections"
|
2
|
+
|
1
3
|
module MetMuseum
|
2
4
|
HTTP_OK_CODE = 200
|
3
5
|
HTTP_BAD_REQUEST_CODE = 400
|
@@ -6,8 +8,8 @@ module MetMuseum
|
|
6
8
|
HTTP_NOT_FOUND_CODE = 404
|
7
9
|
HTTP_UNPROCESSABLE_ENTITY_CODE = 429
|
8
10
|
|
9
|
-
def self.error_class(
|
10
|
-
case
|
11
|
+
def self.error_class(response_code)
|
12
|
+
case response_code
|
11
13
|
when HTTP_BAD_REQUEST_CODE
|
12
14
|
BadRequestError
|
13
15
|
when HTTP_UNAUTHORIZED_CODE
|
data/lib/met_museum/version.rb
CHANGED
data/lib/met_museum.rb
CHANGED
data/met_museum.gemspec
CHANGED
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: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hyuraku
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,34 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: faraday
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: oj
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
83
|
description: 'The Metropolitan Museum of Art Collection API wrapper '
|
112
84
|
email:
|
113
85
|
- calenthird@gamil.com
|
@@ -117,9 +89,10 @@ extra_rdoc_files: []
|
|
117
89
|
files:
|
118
90
|
- ".github/workflows/ruby.yml"
|
119
91
|
- ".gitignore"
|
92
|
+
- ".rbgithook/pre-commit"
|
120
93
|
- ".rspec"
|
121
94
|
- ".rubocop.yml"
|
122
|
-
- ".
|
95
|
+
- ".ruby-version"
|
123
96
|
- CODE_OF_CONDUCT.md
|
124
97
|
- Gemfile
|
125
98
|
- Gemfile.lock
|
@@ -140,7 +113,7 @@ licenses:
|
|
140
113
|
- MIT
|
141
114
|
metadata:
|
142
115
|
homepage_uri: https://github.com/hyuraku/met_museum
|
143
|
-
post_install_message:
|
116
|
+
post_install_message:
|
144
117
|
rdoc_options: []
|
145
118
|
require_paths:
|
146
119
|
- lib
|
@@ -155,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
128
|
- !ruby/object:Gem::Version
|
156
129
|
version: '0'
|
157
130
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
131
|
+
rubygems_version: 3.3.8
|
132
|
+
signing_key:
|
160
133
|
specification_version: 4
|
161
134
|
summary: MET museum api wrapper
|
162
135
|
test_files: []
|