met_museum 1.4.0 → 1.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a79a7c355d8200cfccab7fdb7fbd01f37a74ee82a555de9a4697a6800616d2e4
4
- data.tar.gz: 647315d7446816af5ce68035edcbedf32593a89aad70c511632f8ce3abe652c5
3
+ metadata.gz: 45f5c8d43daa6e64da5cb3c6788ee090c82070d84d9dbca31afb0bb3463dfcdc
4
+ data.tar.gz: 2bbbf5262f1bef794f6af6b7656903d17b1b9b11b5b37679a49a6abb852a6818
5
5
  SHA512:
6
- metadata.gz: e31f31134b22d04612fdc5ef4f303cbfe2f25a1da5b9e0b2784b0fc3415daa8b876afba041f1747dd407dbab0cf57ca29e0a7350c6dfb0c0c0215b1fca655816
7
- data.tar.gz: 28828344996f33389508a8664939a18fd3f182800dfe81bb3bf14d7b68864ecaa56d94698d73c93df6592af98be7f631d896aaf648b9d10b730fa9f3eb864fc5
6
+ metadata.gz: 03053e41e8aa40ab045f480a7bfbe0bfb38a2a909d5776f937938acec59afc3d964cb508e5756de2e11ae123059718659a8e4bcd74247e3eb84837c6ba9d9b9b
7
+ data.tar.gz: 214a6dd1cbeb31b8aa221fe794c7f3bcda4af5ef6ab41498830c8e4cd0582c2d7ea30178eff241f0c177ee618ab40dc577e1fbaa7492a2ecbadc0378bcffa13b
@@ -15,7 +15,7 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby: [ '2.5', '2.6', '2.7', '3.0' ]
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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env sh
2
+ bundle exec rspec spec/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/Gemfile CHANGED
@@ -6,3 +6,5 @@ end
6
6
 
7
7
  # Specify your gem's dependencies in met_museum.gemspec
8
8
  gemspec
9
+
10
+ gem "rbgithook", "~> 0.1.2"
data/Gemfile.lock CHANGED
@@ -1,61 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- met_museum (1.4.0)
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.1)
12
- coderay (1.1.2)
13
- diff-lcs (1.3)
14
- faraday (1.2.0)
15
- multipart-post (>= 1.2, < 3)
16
- ruby2_keywords
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.12.2)
24
- coderay (~> 1.1.0)
25
- method_source (~> 0.9.0)
26
- rainbow (3.0.0)
27
- rake (13.0.1)
28
- regexp_parser (1.7.1)
29
- rexml (3.2.4)
30
- rspec (3.8.0)
31
- rspec-core (~> 3.8.0)
32
- rspec-expectations (~> 3.8.0)
33
- rspec-mocks (~> 3.8.0)
34
- rspec-core (3.8.0)
35
- rspec-support (~> 3.8.0)
36
- rspec-expectations (3.8.2)
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.8.0)
39
- rspec-mocks (3.8.0)
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.8.0)
42
- rspec-retry (0.6.1)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-retry (0.6.2)
43
37
  rspec-core (> 3.3)
44
- rspec-support (3.8.0)
45
- rubocop (0.86.0)
38
+ rspec-support (3.11.0)
39
+ rubocop (1.30.1)
46
40
  parallel (~> 1.10)
47
- parser (>= 2.7.0.1)
41
+ parser (>= 3.1.0.0)
48
42
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.7)
50
- rexml
51
- rubocop-ast (>= 0.0.3, < 1.0)
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, < 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)
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 hyuraku
3
+ Copyright (c) 2021 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
@@ -1,4 +1,4 @@
1
- <img src="https://img.shields.io/travis/hyuraku/met_museum.svg"> <img src="https://img.shields.io/github/license/hyuraku/met_museum.svg">
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 = new_faraday(API_ENDPOINT, PUBLIC_URI, query)
21
- return_response(response)
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 = new_faraday(API_ENDPOINT, "#{PUBLIC_URI}/#{object_id}")
84
- return_response(response)
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 = new_faraday(API_ENDPOINT, DEPARTMENTS_URI)
93
- return_response(response)
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 = new_faraday(API_ENDPOINT, SEARCH_URI, args)
106
- origin_response = return_response(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"][0..limit - 1].map { |id| MetMuseum::Collection.new.object(id) }
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 new_faraday(url, dir, params = nil)
116
- Faraday.new(url: url).get dir, params
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?(response)
120
- response.status == HTTP_OK_CODE
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 return_response(response)
131
- return Oj.load(response.body) if response_successful?(response)
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(response), "Code: #{response.status}, response: #{response.body}"
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(response)
10
- case response.status
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
@@ -1,3 +1,3 @@
1
1
  module MetMuseum
2
- VERSION = "1.4.0".freeze
2
+ VERSION = "1.4.2".freeze
3
3
  end
data/lib/met_museum.rb CHANGED
@@ -1,6 +1,3 @@
1
- require "faraday"
2
- require "oj"
3
-
4
1
  require "met_museum/collection"
5
2
  require "met_museum/version"
6
3
 
data/met_museum.gemspec CHANGED
@@ -38,7 +38,4 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
39
  spec.add_development_dependency "rspec-retry"
40
40
  spec.add_development_dependency "rubocop"
41
-
42
- spec.add_dependency "faraday"
43
- spec.add_dependency "oj"
44
41
  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: 1.4.0
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: 2020-12-29 00:00:00.000000000 Z
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
- - ".travis.yml"
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.0.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: []
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.7.1
7
- - 2.6.0
8
- - 2.5.0
9
- script:
10
- - bundle exec rspec spec/
11
- before_install:
12
- - gem install -v 2.0.1 bundler
13
- - bundle update --bundler