met_museum 1.3.6 → 1.4.1
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 +33 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +26 -3
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/met_museum/collection.rb +34 -62
- data/lib/met_museum/http_status_code.rb +23 -6
- data/lib/met_museum/version.rb +1 -1
- data/lib/met_museum.rb +0 -3
- data/met_museum.gemspec +5 -5
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 747d015331b55f840aa0065fbfc3e2822fda2f2f52a5a6ddede4b7f62ade5735
|
4
|
+
data.tar.gz: ac3158ff771e89fc1fb3d563920b02797c97c15be9dbd8a1ed5618649b53194b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c02a1a47672656535464183e79b4129b0d4b12632b48382afe8a3aff36d24af355620b51097324157f04342c361dcf62d74396916b52edf05359de6a011a37b1
|
7
|
+
data.tar.gz: 33eedda5f92fe536476dd03c0ba50aad36610f09440fcf15317b905baeac576108d3ac7993269a2619ed403c3ab5883a21193d87da2f72c3fb9e5358a67dd58f
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on: [push, pull_request]
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby: [ '2.6', '2.7', '3.0', '3.1' ]
|
19
|
+
name: Ruby ${{ matrix.ruby }} spec
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby
|
23
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
24
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
# uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
29
|
+
bundler-cache: true
|
30
|
+
- name: Install dependencies
|
31
|
+
run: bundle install
|
32
|
+
- name: Run spec
|
33
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,24 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
met_museum (1.
|
4
|
+
met_museum (1.4.1)
|
5
5
|
faraday
|
6
6
|
oj
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
ast (2.4.1)
|
11
12
|
coderay (1.1.2)
|
12
13
|
diff-lcs (1.3)
|
13
|
-
faraday (
|
14
|
+
faraday (1.2.0)
|
14
15
|
multipart-post (>= 1.2, < 3)
|
16
|
+
ruby2_keywords
|
15
17
|
method_source (0.9.2)
|
16
18
|
multipart-post (2.1.1)
|
17
|
-
oj (3.10.
|
19
|
+
oj (3.10.6)
|
20
|
+
parallel (1.19.2)
|
21
|
+
parser (2.7.1.4)
|
22
|
+
ast (~> 2.4.1)
|
18
23
|
pry (0.12.2)
|
19
24
|
coderay (~> 1.1.0)
|
20
25
|
method_source (~> 0.9.0)
|
26
|
+
rainbow (3.0.0)
|
21
27
|
rake (13.0.1)
|
28
|
+
regexp_parser (1.7.1)
|
29
|
+
rexml (3.2.5)
|
22
30
|
rspec (3.8.0)
|
23
31
|
rspec-core (~> 3.8.0)
|
24
32
|
rspec-expectations (~> 3.8.0)
|
@@ -34,6 +42,20 @@ GEM
|
|
34
42
|
rspec-retry (0.6.1)
|
35
43
|
rspec-core (> 3.3)
|
36
44
|
rspec-support (3.8.0)
|
45
|
+
rubocop (0.86.0)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 2.7.0.1)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.7)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
54
|
+
rubocop-ast (0.1.0)
|
55
|
+
parser (>= 2.7.0.1)
|
56
|
+
ruby-progressbar (1.10.1)
|
57
|
+
ruby2_keywords (0.0.5)
|
58
|
+
unicode-display_width (1.7.0)
|
37
59
|
|
38
60
|
PLATFORMS
|
39
61
|
ruby
|
@@ -45,6 +67,7 @@ DEPENDENCIES
|
|
45
67
|
rake (~> 13.0)
|
46
68
|
rspec (~> 3.0)
|
47
69
|
rspec-retry
|
70
|
+
rubocop
|
48
71
|
|
49
72
|
BUNDLED WITH
|
50
73
|
2.0.2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -322,4 +322,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
322
322
|
|
323
323
|
## Code of Conduct
|
324
324
|
|
325
|
-
Everyone interacting in the MetMuseum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
325
|
+
Everyone interacting in the MetMuseum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hyuraku/met_museum/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -2,6 +2,9 @@ require "met_museum/api_expections"
|
|
2
2
|
require "met_museum/endpoint"
|
3
3
|
require "met_museum/http_status_code"
|
4
4
|
|
5
|
+
require "faraday"
|
6
|
+
require "oj"
|
7
|
+
|
5
8
|
module MetMuseum
|
6
9
|
class Collection
|
7
10
|
# Return a listing of all valid Object IDs available to use
|
@@ -10,14 +13,16 @@ module MetMuseum
|
|
10
13
|
# @params [Integer] departmentIds Returns any objects in a specific department
|
11
14
|
# @return [Hash<total, Integer>] The total number of publicly-available objects
|
12
15
|
# @return [Hash<objectIDs, Array<Integer>>] An array containing the object ID of publicly-available object
|
13
|
-
def objects(
|
16
|
+
def objects(**args)
|
14
17
|
options = {
|
15
18
|
metadataDate: nil,
|
16
19
|
departmentIds: nil
|
17
|
-
}.merge(
|
20
|
+
}.merge(args)
|
21
|
+
|
18
22
|
options[:metadataDate] = check_date(options[:metadataDate])
|
19
|
-
|
20
|
-
|
23
|
+
query = { metadataDate: options[:metadataDate], departmentIds: options[:departmentIds] }
|
24
|
+
response = create_request(API_ENDPOINT, PUBLIC_URI, query)
|
25
|
+
arrange_response(response)
|
21
26
|
end
|
22
27
|
|
23
28
|
# 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)
|
@@ -53,6 +58,8 @@ module MetMuseum
|
|
53
58
|
# @return [Hash<objectEndDate, string>] Machine readable date indicating the year the artwork was completed (may be the same year or different year than the objectBeginDate)
|
54
59
|
# @return [Hash<medium, string>] Refers to the materials that were used to create the artwork
|
55
60
|
# @return [Hash<dimensions, string>] Size of the artwork or object
|
61
|
+
# @return [Hash<dimensionsParsed, Array<Hash>>] Size of the artwork or object in centimeters, parsed
|
62
|
+
# @return [Hash<measurements, Array<Hash>>] Array of elements, each with a name, description, and set of measurements. Spatial measurements are in centimeters; weights are in kg.
|
56
63
|
# @return [Hash<creditLine, String>] Text acknowledging the source or origin of the artwork and the year the object was acquired by the museum.
|
57
64
|
# @return [Hash<geographyType, String>] Qualifying information that describes the relationship of the place catalogued in the geography fields to the object that is being catalogued
|
58
65
|
# @return [Hash<city, String>] City where the artwork was created
|
@@ -74,10 +81,11 @@ module MetMuseum
|
|
74
81
|
# @return [Hash<tags, Array<String>>] An array of subject keyword tags associated with the object
|
75
82
|
# @return [Hash<objectWikidata_URL, string>] Wikidata URL for the object
|
76
83
|
# @return [Hash<isTimelineWork, boolean>] Whether the object is on the Timeline of Art History website
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
# @return [Hash<GalleryNumber, string>] Gallery number, where available
|
85
|
+
|
86
|
+
def object(object_id)
|
87
|
+
response = create_request(API_ENDPOINT, "#{PUBLIC_URI}/#{object_id}")
|
88
|
+
arrange_response(response)
|
81
89
|
end
|
82
90
|
|
83
91
|
# returns a listing of all departments
|
@@ -85,8 +93,8 @@ module MetMuseum
|
|
85
93
|
# @return [Integer] departments Department ID as an integer. The departmentId is to be used as a query parameter on the `/objects` endpoint
|
86
94
|
# @return [String] departments Display name for a department
|
87
95
|
def department
|
88
|
-
response =
|
89
|
-
|
96
|
+
response = create_request(API_ENDPOINT, DEPARTMENTS_URI)
|
97
|
+
arrange_response(response)
|
90
98
|
end
|
91
99
|
|
92
100
|
# returns a listing of all Object IDs for objects that contain the search query within the object’s data
|
@@ -96,57 +104,20 @@ module MetMuseum
|
|
96
104
|
# @return [Integer] total The total number of publicly-available objects
|
97
105
|
# @return [Array<Integer>] objectIDs An array containing the object ID of publicly-available object
|
98
106
|
# @return [Array<Object>] objects An array containing the objects that contain the search query within the object’s data
|
99
|
-
def search(query,
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
hasImages: nil,
|
108
|
-
geoLocation: nil,
|
109
|
-
dateBegin: 0,
|
110
|
-
dateEnd: 2000
|
111
|
-
}.merge(options)
|
112
|
-
response = new_faraday(API_ENDPOINT, SEARCH_URI, {
|
113
|
-
:q => query,
|
114
|
-
:isHighlight => options[:isHighlight],
|
115
|
-
:departmentId => options[:departmentId],
|
116
|
-
:isOnView => options[:isOnView],
|
117
|
-
:artistOrCulture => options[:artistOrCulture],
|
118
|
-
:medium => options[:medium]&.multi_option,
|
119
|
-
:hasImages => options[:hasImages],
|
120
|
-
:geoLocation => options[:geoLocation]&.multi_option,
|
121
|
-
:dateBegin => options[:dateBegin],
|
122
|
-
:dateEnd => options[:dateEnd]
|
123
|
-
})
|
124
|
-
origin_response = return_response(response)
|
125
|
-
return origin_response if options[:limit] <= 0
|
126
|
-
origin_response["objectIDs"][0..options[:limit] - 1].map{|id| MetMuseum::Collection.new.object(id)}
|
107
|
+
def search(query, **args)
|
108
|
+
args.merge!({q: query})
|
109
|
+
response = create_request(API_ENDPOINT, SEARCH_URI, args)
|
110
|
+
origin_response = arrange_response(response)
|
111
|
+
limit = args[:limit].to_i
|
112
|
+
return origin_response if limit <= 0
|
113
|
+
|
114
|
+
origin_response["objectIDs"].lazy.map { |id| MetMuseum::Collection.new.object(id) }.first(limit)
|
127
115
|
end
|
128
116
|
|
129
117
|
private
|
130
118
|
|
131
|
-
def
|
132
|
-
Faraday.new(:
|
133
|
-
end
|
134
|
-
|
135
|
-
def error_class(response)
|
136
|
-
case response.status
|
137
|
-
when HTTP_BAD_REQUEST_CODE
|
138
|
-
BadRequestError
|
139
|
-
when HTTP_UNAUTHORIZED_CODE
|
140
|
-
UnauthorizedError
|
141
|
-
when HTTP_FORBIDDEN_CODE
|
142
|
-
ForbiddenError
|
143
|
-
when HTTP_NOT_FOUND_CODE
|
144
|
-
NotFoundError
|
145
|
-
when HTTP_UNPROCESSABLE_ENTITY_CODE
|
146
|
-
UnprocessableEntityError
|
147
|
-
else
|
148
|
-
ApiError
|
149
|
-
end
|
119
|
+
def create_request(url, dir, params = nil)
|
120
|
+
Faraday.new(url: url).get dir, params
|
150
121
|
end
|
151
122
|
|
152
123
|
def response_successful?(response)
|
@@ -155,20 +126,21 @@ module MetMuseum
|
|
155
126
|
|
156
127
|
def check_date(date)
|
157
128
|
return nil if date.nil?
|
158
|
-
return date.to_date.to_s if date.
|
129
|
+
return date.to_date.to_s if date.is_a? Date
|
159
130
|
|
160
131
|
raise TypeError, "Write certain date"
|
161
132
|
end
|
162
133
|
|
163
|
-
def
|
134
|
+
def arrange_response(response)
|
164
135
|
return Oj.load(response.body) if response_successful?(response)
|
165
136
|
|
166
|
-
raise error_class(response), "Code: #{response.status}, response: #{response.body}"
|
137
|
+
raise MetMuseum.error_class(response), "Code: #{response.status}, response: #{response.body}"
|
167
138
|
end
|
168
139
|
|
169
140
|
def multi_option
|
170
|
-
return self if
|
171
|
-
return
|
141
|
+
return self if is_a? String
|
142
|
+
return join("|") if is_a? Array
|
143
|
+
|
172
144
|
raise TypeError, "Write String or Array type"
|
173
145
|
end
|
174
146
|
end
|
@@ -1,8 +1,25 @@
|
|
1
1
|
module MetMuseum
|
2
|
-
HTTP_OK_CODE = 200
|
3
|
-
HTTP_BAD_REQUEST_CODE = 400
|
4
|
-
HTTP_UNAUTHORIZED_CODE = 401
|
5
|
-
HTTP_FORBIDDEN_CODE = 403
|
6
|
-
HTTP_NOT_FOUND_CODE = 404
|
7
|
-
HTTP_UNPROCESSABLE_ENTITY_CODE = 429
|
2
|
+
HTTP_OK_CODE = 200
|
3
|
+
HTTP_BAD_REQUEST_CODE = 400
|
4
|
+
HTTP_UNAUTHORIZED_CODE = 401
|
5
|
+
HTTP_FORBIDDEN_CODE = 403
|
6
|
+
HTTP_NOT_FOUND_CODE = 404
|
7
|
+
HTTP_UNPROCESSABLE_ENTITY_CODE = 429
|
8
|
+
|
9
|
+
def self.error_class(response)
|
10
|
+
case response.status
|
11
|
+
when HTTP_BAD_REQUEST_CODE
|
12
|
+
BadRequestError
|
13
|
+
when HTTP_UNAUTHORIZED_CODE
|
14
|
+
UnauthorizedError
|
15
|
+
when HTTP_FORBIDDEN_CODE
|
16
|
+
ForbiddenError
|
17
|
+
when HTTP_NOT_FOUND_CODE
|
18
|
+
NotFoundError
|
19
|
+
when HTTP_UNPROCESSABLE_ENTITY_CODE
|
20
|
+
UnprocessableEntityError
|
21
|
+
else
|
22
|
+
ApiError
|
23
|
+
end
|
24
|
+
end
|
8
25
|
end
|
data/lib/met_museum/version.rb
CHANGED
data/lib/met_museum.rb
CHANGED
data/met_museum.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "met_museum/version"
|
5
4
|
|
@@ -9,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ["hyuraku"]
|
10
9
|
spec.email = ["calenthird@gamil.com"]
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = "MET museum api wrapper"
|
12
|
+
spec.description = "The Metropolitan Museum of Art Collection API wrapper "
|
14
13
|
spec.homepage = "https://github.com/hyuraku/met_museum"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -27,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
27
26
|
|
28
27
|
# Specify which files should be added to the gem when it is released.
|
29
28
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
-
spec.files
|
29
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
31
30
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
31
|
end
|
33
32
|
spec.bindir = "exe"
|
@@ -38,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
38
37
|
spec.add_development_dependency "rake", "~> 13.0"
|
39
38
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
39
|
spec.add_development_dependency "rspec-retry"
|
40
|
+
spec.add_development_dependency "rubocop"
|
41
41
|
|
42
42
|
spec.add_dependency "faraday"
|
43
43
|
spec.add_dependency "oj"
|
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
|
+
version: 1.4.1
|
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-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: faraday
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,8 +115,10 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
118
|
+
- ".github/workflows/ruby.yml"
|
104
119
|
- ".gitignore"
|
105
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
106
122
|
- ".travis.yml"
|
107
123
|
- CODE_OF_CONDUCT.md
|
108
124
|
- Gemfile
|
@@ -124,7 +140,7 @@ licenses:
|
|
124
140
|
- MIT
|
125
141
|
metadata:
|
126
142
|
homepage_uri: https://github.com/hyuraku/met_museum
|
127
|
-
post_install_message:
|
143
|
+
post_install_message:
|
128
144
|
rdoc_options: []
|
129
145
|
require_paths:
|
130
146
|
- lib
|
@@ -139,8 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
- !ruby/object:Gem::Version
|
140
156
|
version: '0'
|
141
157
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
143
|
-
signing_key:
|
158
|
+
rubygems_version: 3.3.3
|
159
|
+
signing_key:
|
144
160
|
specification_version: 4
|
145
161
|
summary: MET museum api wrapper
|
146
162
|
test_files: []
|