met_museum 1.3.4 → 1.4.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: f318ac9ca9aedae15b10e0202143b88719a0df5324a8057f33dda6ea52e59909
4
- data.tar.gz: 1fb234a9ebbfd1f6bcd39f4626446a0fabaae0f10e7a98a9b41e0bb69c3783df
3
+ metadata.gz: a79a7c355d8200cfccab7fdb7fbd01f37a74ee82a555de9a4697a6800616d2e4
4
+ data.tar.gz: 647315d7446816af5ce68035edcbedf32593a89aad70c511632f8ce3abe652c5
5
5
  SHA512:
6
- metadata.gz: c88e7b0f617dd49b90f05d6d78e5e0d0172dab5465b765adf747258d012b10879206e8a5065bfde771f140bb69b9c8ec3065332172af0bcab12467e4215ae9eb
7
- data.tar.gz: d972b17a10bc8042d5663a361e4c8da5d611a7dcd0d7eef887c6e95ac274eb94adc608e5ef548ca9a9c9976dcafaae1674ff1dbd821e1d22be5e812a62dfd2f4
6
+ metadata.gz: e31f31134b22d04612fdc5ef4f303cbfe2f25a1da5b9e0b2784b0fc3415daa8b876afba041f1747dd407dbab0cf57ca29e0a7350c6dfb0c0c0215b1fca655816
7
+ data.tar.gz: 28828344996f33389508a8664939a18fd3f182800dfe81bb3bf14d7b68864ecaa56d94698d73c93df6592af98be7f631d896aaf648b9d10b730fa9f3eb864fc5
@@ -0,0 +1,32 @@
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.5', '2.6', '2.7', '3.0' ]
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
+ - name: Install dependencies
30
+ run: bundle install
31
+ - name: Run spec
32
+ run: bundle exec rake
@@ -0,0 +1,13 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ Metrics/AbcSize:
12
+ Enabled: true
13
+ Max: 20
@@ -3,9 +3,9 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
+ - 2.7.1
6
7
  - 2.6.0
7
8
  - 2.5.0
8
- - 2.4.2
9
9
  script:
10
10
  - bundle exec rspec spec/
11
11
  before_install:
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem 'pry'
4
+ gem "pry"
5
5
  end
6
6
 
7
7
  # Specify your gem's dependencies in met_museum.gemspec
@@ -1,24 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- met_museum (1.3.3)
4
+ met_museum (1.4.0)
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 (0.15.4)
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.9.0)
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)
21
- rake (10.5.0)
26
+ rainbow (3.0.0)
27
+ rake (13.0.1)
28
+ regexp_parser (1.7.1)
29
+ rexml (3.2.4)
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.2)
58
+ unicode-display_width (1.7.0)
37
59
 
38
60
  PLATFORMS
39
61
  ruby
@@ -42,9 +64,10 @@ DEPENDENCIES
42
64
  bundler (~> 2.0)
43
65
  met_museum!
44
66
  pry
45
- rake (~> 10.0)
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 hyuraku
3
+ Copyright (c) 2020 hyuraku
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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/[USERNAME]/met_museum/blob/master/CODE_OF_CONDUCT.md).
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
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -3,7 +3,6 @@ module MetMuseum
3
3
  BadRequestError = Class.new(MetMuseumError)
4
4
  UnauthorizedError = Class.new(MetMuseumError)
5
5
  ForbiddenError = Class.new(MetMuseumError)
6
- ApiRequestsQuotaReachedError = Class.new(MetMuseumError)
7
6
  NotFoundError = Class.new(MetMuseumError)
8
7
  UnprocessableEntityError = Class.new(MetMuseumError)
9
8
  ApiError = Class.new(MetMuseumError)
@@ -6,16 +6,18 @@ module MetMuseum
6
6
  class Collection
7
7
  # Return a listing of all valid Object IDs available to use
8
8
  # @param [Date] metadataDate Returns any objects with updated data after this date
9
+ # @param [DateTime] metadataDate Returns any objects with updated data after this date
9
10
  # @params [Integer] departmentIds Returns any objects in a specific department
10
11
  # @return [Hash<total, Integer>] The total number of publicly-available objects
11
12
  # @return [Hash<objectIDs, Array<Integer>>] An array containing the object ID of publicly-available object
12
- def objects(options = {})
13
+ def objects(**args)
13
14
  options = {
14
15
  metadataDate: nil,
15
16
  departmentIds: nil
16
- }.merge(options)
17
+ }.merge(args)
17
18
  options[:metadataDate] = check_date(options[:metadataDate])
18
- response = Faraday.new(:url => API_ENDPOINT).get PUBLIC_URI, {:metadataDate => options[:metadataDate], :departmentIds => options[:departmentIds]}
19
+ query = { metadataDate: options[:metadataDate], departmentIds: options[:departmentIds] }
20
+ response = new_faraday(API_ENDPOINT, PUBLIC_URI, query)
19
21
  return_response(response)
20
22
  end
21
23
 
@@ -52,6 +54,8 @@ module MetMuseum
52
54
  # @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)
53
55
  # @return [Hash<medium, string>] Refers to the materials that were used to create the artwork
54
56
  # @return [Hash<dimensions, string>] Size of the artwork or object
57
+ # @return [Hash<dimensionsParsed, Array<Hash>>] Size of the artwork or object in centimeters, parsed
58
+ # @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.
55
59
  # @return [Hash<creditLine, String>] Text acknowledging the source or origin of the artwork and the year the object was acquired by the museum.
56
60
  # @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
57
61
  # @return [Hash<city, String>] City where the artwork was created
@@ -71,8 +75,12 @@ module MetMuseum
71
75
  # @return [Hash<repository, String>]
72
76
  # @return [Hash<objectURL, String>] URL to object's page on metmuseum.org
73
77
  # @return [Hash<tags, Array<String>>] An array of subject keyword tags associated with the object
74
- def object(objectID)
75
- response = Faraday.get "#{API_ENDPOINT}#{PUBLIC_URI}/#{objectID}"
78
+ # @return [Hash<objectWikidata_URL, string>] Wikidata URL for the object
79
+ # @return [Hash<isTimelineWork, boolean>] Whether the object is on the Timeline of Art History website
80
+ # @return [Hash<GalleryNumber, string>] Gallery number, where available
81
+
82
+ def object(object_id)
83
+ response = new_faraday(API_ENDPOINT, "#{PUBLIC_URI}/#{object_id}")
76
84
  return_response(response)
77
85
  end
78
86
 
@@ -81,7 +89,7 @@ module MetMuseum
81
89
  # @return [Integer] departments Department ID as an integer. The departmentId is to be used as a query parameter on the `/objects` endpoint
82
90
  # @return [String] departments Display name for a department
83
91
  def department
84
- response = Faraday.get "#{API_ENDPOINT}#{DEPARTMENTS_URI}"
92
+ response = new_faraday(API_ENDPOINT, DEPARTMENTS_URI)
85
93
  return_response(response)
86
94
  end
87
95
 
@@ -92,54 +100,20 @@ module MetMuseum
92
100
  # @return [Integer] total The total number of publicly-available objects
93
101
  # @return [Array<Integer>] objectIDs An array containing the object ID of publicly-available object
94
102
  # @return [Array<Object>] objects An array containing the objects that contain the search query within the object’s data
95
- def search(query, options = {})
96
- options = {
97
- limit: 0,
98
- isHighlight: false,
99
- departmentId: nil,
100
- isOnView: nil,
101
- artistOrCulture: nil,
102
- medium: nil,
103
- hasImages: nil,
104
- geoLocation: nil,
105
- dateBegin: 0,
106
- dateEnd: 2000
107
- }.merge(options)
108
- response = Faraday.new(:url => API_ENDPOINT).get SEARCH_URI, {
109
- :q => query,
110
- :isHighlight => options[:isHighlight],
111
- :departmentId => options[:departmentId],
112
- :isOnView => options[:isOnView],
113
- :artistOrCulture => options[:artistOrCulture],
114
- :medium => options[:medium],
115
- :hasImages => options[:hasImages],
116
- :geoLocation => options[:geoLocation],
117
- :dateBegin => options[:dateBegin],
118
- :dateEnd => options[:dateEnd]
119
- }
103
+ def search(query, **args)
104
+ args.merge!({q: query})
105
+ response = new_faraday(API_ENDPOINT, SEARCH_URI, args)
120
106
  origin_response = return_response(response)
121
- return origin_response if options[:limit] <= 0
122
- origin_response["objectIDs"][0..options[:limit] - 1].map{|id| MetMuseum::Collection.new.object(id)}
107
+ limit = args[:limit].to_i
108
+ return origin_response if limit <= 0
109
+
110
+ origin_response["objectIDs"][0..limit - 1].map { |id| MetMuseum::Collection.new.object(id) }
123
111
  end
124
112
 
125
113
  private
126
114
 
127
- def error_class(response)
128
- case response.status
129
- when HTTP_BAD_REQUEST_CODE
130
- BadRequestError
131
- when HTTP_UNAUTHORIZED_CODE
132
- UnauthorizedError
133
- when HTTP_FORBIDDEN_CODE
134
- return ApiRequestsQuotaReachedError if api_requests_quota_reached?
135
- ForbiddenError
136
- when HTTP_NOT_FOUND_CODE
137
- NotFoundError
138
- when HTTP_UNPROCESSABLE_ENTITY_CODE
139
- UnprocessableEntityError
140
- else
141
- ApiError
142
- end
115
+ def new_faraday(url, dir, params = nil)
116
+ Faraday.new(url: url).get dir, params
143
117
  end
144
118
 
145
119
  def response_successful?(response)
@@ -148,7 +122,7 @@ module MetMuseum
148
122
 
149
123
  def check_date(date)
150
124
  return nil if date.nil?
151
- return date.to_s if date.class == Date
125
+ return date.to_date.to_s if date.is_a? Date
152
126
 
153
127
  raise TypeError, "Write certain date"
154
128
  end
@@ -156,7 +130,14 @@ module MetMuseum
156
130
  def return_response(response)
157
131
  return Oj.load(response.body) if response_successful?(response)
158
132
 
159
- raise error_class(response), "Code: #{response.status}, response: #{response.body}"
133
+ raise MetMuseum.error_class(response), "Code: #{response.status}, response: #{response.body}"
134
+ end
135
+
136
+ def multi_option
137
+ return self if is_a? String
138
+ return join("|") if is_a? Array
139
+
140
+ raise TypeError, "Write String or Array type"
160
141
  end
161
142
  end
162
143
  end
@@ -1,8 +1,25 @@
1
1
  module MetMuseum
2
- HTTP_OK_CODE = 200.freeze
3
- HTTP_BAD_REQUEST_CODE = 400.freeze
4
- HTTP_UNAUTHORIZED_CODE = 401.freeze
5
- HTTP_FORBIDDEN_CODE = 403.freeze
6
- HTTP_NOT_FOUND_CODE = 404.freeze
7
- HTTP_UNPROCESSABLE_ENTITY_CODE = 429.freeze
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
@@ -1,3 +1,3 @@
1
1
  module MetMuseum
2
- VERSION = "1.3.4"
2
+ VERSION = "1.4.0".freeze
3
3
  end
@@ -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 = %q{MET museum api wrapper}
13
- spec.description = %q{The Metropolitan Museum of Art Collection API wrapper }
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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"
@@ -35,9 +34,10 @@ Gem::Specification.new do |spec|
35
34
  spec.require_paths = ["lib"]
36
35
 
37
36
  spec.add_development_dependency "bundler", "~> 2.0"
38
- spec.add_development_dependency "rake", "~> 10.0"
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.3.4
4
+ version: 1.4.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-10-08 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
155
  - !ruby/object:Gem::Version
140
156
  version: '0'
141
157
  requirements: []
142
- rubygems_version: 3.0.2
158
+ rubygems_version: 3.0.3
143
159
  signing_key:
144
160
  specification_version: 4
145
161
  summary: MET museum api wrapper