jalc 2.1.1 → 2.2.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: eccd488a68365b574a6545965ead9f49c4f49102d4296be4d2dc01ca05201035
4
- data.tar.gz: 369a77d191d672afae36aa01d404d0bfc7b79a89ea71225c84b8754cd8e8ad3e
3
+ metadata.gz: f6ef2b1726c1a8125061c025f1a0541575a4ee32db0a3b2ea5b33f83e07a60e1
4
+ data.tar.gz: 58155b4c3b29f9e01008ef6dffe0de0d5d1ef8a01420e1ad5dbefaa2a37df595
5
5
  SHA512:
6
- metadata.gz: 8a6a6882a2855ea1887600d6980419900a329c3ee9594704ae6ab8fbac0f0e60516475fe6d994975159e440afa6e6185be4e249cc462511a3acb39471998c94c
7
- data.tar.gz: 20cc3fd0dae75d85d173b8be824421d3bf641ab154c4c7026d252380211b9b46adfb23c7e7fc23ebb24c5484d7b1dcf7cbda8dc809fe7e90c6dc4c007f0ff90b
6
+ metadata.gz: 6af032f2082c19d0db3898818198cd053264595d8cce4b56dca119a32b00879cff23fa2ff4ad0e102d6040bb2e72f2bf60fa5235eeb6aea113dfdd337b21d6e4
7
+ data.tar.gz: 172cae3930c2444266d88abc2c08528964eaee60112840951b5d3d363b0cd09fbc8bc349b8c70a2807b95234188e5afebb8dc46d4775ce8974b702d91668a219
@@ -0,0 +1,31 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "Ruby",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "image": "mcr.microsoft.com/devcontainers/ruby:0-2.7",
7
+
8
+ // Features to add to the dev container. More info: https://containers.dev/features.
9
+ // "features": {},
10
+
11
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
12
+ // "forwardPorts": [],
13
+
14
+ // Use 'postCreateCommand' to run commands after the container is created.
15
+ "postCreateCommand": "gem i bundler && bin/setup",
16
+
17
+ // Configure tool-specific properties.
18
+ "customizations": {
19
+ "vscode": {
20
+ "extensions": [
21
+ "KoichiSasada.vscode-rdbg",
22
+ "castwide.solargraph",
23
+ "soutaro.rbs-syntax",
24
+ "soutaro.steep-vscode"
25
+ ]
26
+ }
27
+ }
28
+
29
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
30
+ // "remoteUser": "root"
31
+ }
data/.rubocop.yml CHANGED
@@ -2,9 +2,15 @@ require:
2
2
  - rubocop-rake
3
3
  - rubocop-rspec
4
4
 
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
5
9
  AllCops:
6
10
  TargetRubyVersion: 2.7
7
11
  NewCops: enable
12
+ Exclude:
13
+ - gem_rbs_collection/**/*
8
14
 
9
15
  Metrics/BlockLength:
10
16
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.2.0] - 2023-02-03
4
+
5
+ - Stop using HTTP GET for Registration API
6
+ - Use `errmsg` element for error messages
7
+
8
+ ## [2.1.2] - 2022-04-13
9
+
10
+ - Fix the condition of log filtering
11
+
3
12
  ## [2.1.1] - 2022-04-08
4
13
 
5
14
  - Fix a typo of a registration API parameter
data/Gemfile CHANGED
@@ -12,4 +12,6 @@ gem 'rspec'
12
12
  gem 'rubocop'
13
13
  gem 'rubocop-rake'
14
14
  gem 'rubocop-rspec'
15
+ gem 'solargraph'
16
+ gem 'steep'
15
17
  gem 'webmock'
data/Steepfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ D = Steep::Diagnostic
4
+
5
+ target :lib do
6
+ signature 'sig', 'sig-private'
7
+ repo_path 'gem_rbs_collection/gems'
8
+
9
+ check 'lib'
10
+
11
+ library 'forwardable', 'logger', 'uri'
12
+ library 'faraday'
13
+
14
+ configure_code_diagnostics do |hash|
15
+ hash[D::Ruby::NoMethod] = :information
16
+ hash[D::Ruby::UnknownConstant] = :information
17
+
18
+ hash[D::Ruby::MethodDefinitionMissing] = nil # To supress noisy VS Code extension message.
19
+ end
20
+ end
@@ -29,12 +29,12 @@ module JaLC
29
29
  end
30
30
 
31
31
  def get_result(exec_id)
32
- response = conn.get(
32
+ response = conn.post(
33
33
  '/jalc/infoRegistry/registDataResult/index',
34
34
  {
35
- login_id: config.id,
36
- login_passwd: config.password,
37
- exec_id: exec_id,
35
+ login_id: Faraday::Multipart::ParamPart.new(config.id, 'text/plain'),
36
+ login_passwd: Faraday::Multipart::ParamPart.new(config.password, 'text/plain'),
37
+ exec_id: Faraday::Multipart::ParamPart.new(exec_id, 'text/plain'),
38
38
  },
39
39
  )
40
40
  response.body
@@ -51,11 +51,7 @@ module JaLC
51
51
  f.use Middleware::RaiseError
52
52
  f.use Middleware::ParseXML
53
53
  f.response :raise_error
54
- if config.logger
55
- f.response :logger, config.logger, { headers: false } do |logger|
56
- logger.filter(/(password=)\w+/, '\1[FILTERED]')
57
- end
58
- end
54
+ f.response :logger, config.logger, { headers: false } if config.logger
59
55
  end
60
56
  end
61
57
  end
@@ -11,18 +11,26 @@ module JaLC
11
11
  def on_complete(env)
12
12
  case env.body.root.elements['head/errcd']&.text
13
13
  when '*'
14
- raise AuthenticationError,
15
- 'IDとパスワードの組合せが間違っているか、アクセス元のIPアドレスがJaLCに登録されているIPアドレスと異なっている可能性があります (errcd=*)'
14
+ raise AuthenticationError.new(doc: env.body)
16
15
  when '#'
17
- raise InvalidXMLError, 'XMLファイルの構造に誤りがあるか、login_id、login_passwd、fnameのパラメータに未設定のものがある可能性があります (errcd=#)'
16
+ raise InvalidXMLError.new(doc: env.body)
18
17
  when '+'
19
- raise RegistrationError, 'fnameで指定したファイルがXMLファイルでないか、XMLファイルの文字コードがUTF-8でない可能性があります (errcd=+)'
18
+ raise RegistrationError.new(doc: env.body)
20
19
  end
21
20
  end
22
21
  end
23
22
  end
24
23
 
25
- class RegistrationError < Error; end
24
+ class RegistrationError < Error
25
+ attr_reader :doc
26
+
27
+ def initialize(msg = nil, doc:)
28
+ @doc = doc
29
+ msg ||= "#{doc.root.elements['head/errmsg']&.text} (errcd=#{doc.root.elements['head/errcd']&.text})"
30
+ super(msg)
31
+ end
32
+ end
33
+
26
34
  class AuthenticationError < RegistrationError; end
27
35
  class InvalidXMLError < RegistrationError; end
28
36
  end
@@ -66,8 +66,8 @@ module JaLC
66
66
  begin
67
67
  require 'faraday_middleware'
68
68
  rescue LoadError
69
- raise LoadError, 'faraday_middleware gem is required when using Faraday v1.' \
70
- " Please add `gem 'faraday_middleware'` to your Gemfile."
69
+ raise LoadError, 'faraday_middleware gem is required when using Faraday v1. ' \
70
+ "Please add `gem 'faraday_middleware'` to your Gemfile."
71
71
  end
72
72
 
73
73
  retry
@@ -44,7 +44,7 @@ module JaLC
44
44
 
45
45
  def initialize(msg = nil, response: nil)
46
46
  @response = response
47
- msg ||= response[:body].dig('message', 'errors', 'message') if response && response[:body].respond_to?(:dig)
47
+ msg ||= response[:body].dig('message', 'errors', 'message') if response && response[:body].is_a?(Hash)
48
48
  msg ||= "the server responded with status #{response[:status]}" if response
49
49
 
50
50
  super(msg)
data/lib/jalc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JaLC
4
- VERSION = '2.1.1'
4
+ VERSION = '2.2.0'
5
5
  end
data/sig/jalc.rbs CHANGED
@@ -1,11 +1,9 @@
1
1
  module JaLC
2
- interface _Logger
3
- end
4
-
5
2
  VERSION: String
6
3
 
7
4
  module Registration
8
- BASE_URL: String
5
+ self.@config: Config
6
+ self.@client: Client
9
7
 
10
8
  def self.configure: { (Config) -> void } -> void
11
9
  def self.config: -> Config
@@ -14,6 +12,9 @@ module JaLC
14
12
  end
15
13
 
16
14
  class RegistrationError < Error
15
+ def initialize: (?String? msg, doc: untyped) -> void
16
+
17
+ attr_reader doc: untyped # REXML::Document
17
18
  end
18
19
 
19
20
  class AuthenticationError < RegistrationError
@@ -23,28 +24,52 @@ module JaLC
23
24
  end
24
25
 
25
26
  class Client
26
- interface _IO
27
- end
28
- type rexml_document = untyped
29
-
30
27
  def initialize: (Config config) -> void
31
- def post: (_IO xml_file) -> rexml_document
32
- def get_result: (Integer | String exec_id) -> rexml_document
28
+
29
+ attr_reader config: Config
30
+ @conn: Faraday::Connection
31
+
32
+ def post: (IO | StringIO xml_file) -> untyped # REXML::Document
33
+ def get_result: (Integer | String exec_id) -> untyped # REXML::Document
34
+
35
+ private
36
+
37
+ def conn: -> Faraday::Connection
33
38
  end
34
39
 
35
40
  class Config
36
- attr_accessor id: String?
37
- attr_accessor password: String?
38
- attr_accessor logger: _Logger?
41
+ DEFAULT_BASE_URL: String
39
42
 
40
43
  def initialize: -> void
44
+
45
+ attr_accessor base_url: String
46
+ attr_accessor id: String?
47
+ attr_accessor password: String?
48
+ attr_accessor logger: Logger?
49
+ end
50
+
51
+ module Middleware
52
+ class ParseXML < Faraday::Middleware
53
+ def on_complete: (untyped env) -> void
54
+ end
55
+
56
+ class RaiseError < Faraday::Middleware
57
+ def on_complete: (untyped env) -> void
58
+ end
41
59
  end
42
60
  end
43
61
 
44
62
  module REST
45
- type response_body = Hash[String, untyped] | String | nil
46
-
47
- BASE_URL: String
63
+ type response_body = (Hash[String, untyped] | String)?
64
+ type response_hash = {
65
+ status: Integer,
66
+ headers: Hash[String, String],
67
+ body: response_body,
68
+ request: { method: Symbol, url: URI, headers: Hash[String, String], body: String? }
69
+ }
70
+
71
+ self.@config: Config
72
+ self.@client: Client
48
73
 
49
74
  def self.configure: { (Config) -> void } -> void
50
75
  def self.config: -> Config
@@ -53,11 +78,10 @@ module JaLC
53
78
  end
54
79
 
55
80
  class HTTPError < Error
56
- type response_hash = {status: Integer, headers: Hash[String, String], body: response_body, request: {method: Symbol, url: URI, headers: Hash[String, String], body: String?}}
81
+ def initialize: (?String? msg, ?response: response_hash?) -> void
57
82
 
58
83
  attr_reader response: response_hash?
59
84
 
60
- def initialize: (?String? msg, ?response: response_hash?) -> void
61
85
  def inspect: -> String
62
86
  end
63
87
 
@@ -75,15 +99,36 @@ module JaLC
75
99
 
76
100
  class Client
77
101
  def initialize: (Config config) -> void
102
+
103
+ attr_reader config: Config
104
+ @conn: Faraday::Connection
105
+
78
106
  def prefixes: (?ra: String?, ?sort: String?, ?order: String?) -> response_body
79
107
  def doilist: (String prefix, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
80
108
  def doi: (String doi) -> response_body
109
+
110
+ private
111
+
112
+ def conn: -> Faraday::Connection
81
113
  end
82
114
 
83
115
  class Config
84
- attr_accessor logger: _Logger?
116
+ DEFAULT_BASE_URL: String
85
117
 
86
118
  def initialize: -> void
119
+
120
+ attr_accessor base_url: String
121
+ attr_accessor logger: Logger?
122
+ end
123
+
124
+ module Middleware
125
+ class RaiseError < Faraday::Middleware
126
+ def on_complete: (untyped env) -> void
127
+
128
+ private
129
+
130
+ def response_values: (untyped env) -> response_hash
131
+ end
87
132
  end
88
133
  end
89
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Miyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -65,6 +65,7 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
+ - ".devcontainer/devcontainer.json"
68
69
  - ".rspec"
69
70
  - ".rubocop.yml"
70
71
  - CHANGELOG.md
@@ -73,6 +74,7 @@ files:
73
74
  - LICENSE.txt
74
75
  - README.md
75
76
  - Rakefile
77
+ - Steepfile
76
78
  - bin/console
77
79
  - bin/setup
78
80
  - jalc.gemspec
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  - !ruby/object:Gem::Version
115
117
  version: '0'
116
118
  requirements: []
117
- rubygems_version: 3.3.7
119
+ rubygems_version: 3.4.1
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: JaLC (Japan Link Center) API Client