jalc 2.1.2 → 2.2.1

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: 2407227918e30a52acb05438fbb3b1713ee9cb2206000204d795030b78d7f265
4
- data.tar.gz: 390b6c7e439ef7f487af098808cc717411610d1c07aeafe15b95404eeed7d954
3
+ metadata.gz: 55ff4fb23821eddb0698085a58a54bec6663c30e19504fb5e25a0369972e7d57
4
+ data.tar.gz: cffd65412e172347f271f668eab81a40602cf624815ad670ba5ea61c291f5f1a
5
5
  SHA512:
6
- metadata.gz: 275263f97587d4258f29d850d19378cdcfedf3ac502b3d13d52cb72b5c259e0f87159cb1a9d136c9fbb9d6c0b4a58b3f2d36ebb2007fe8fe6ca3af38793196ff
7
- data.tar.gz: d09786ab3e4a994020e6e1f52d575e4bd18f57ce2728944bd8987682c93ec0104150d1a5133fbe3251acb05b55f1984731de23c0aabd313c5e6821a33dc12458
6
+ metadata.gz: 5e31213e71eb257b29b3ccb5ecb61ae681f1a4a1a5ab19b0518644217a22646251bd63b5feef0d150215f44aafd48b1d92fd63ec9a8999a01042a8b31e3e4fc3
7
+ data.tar.gz: 2c3aa1cc1445bfbb2f1a3e20da84bbff7cae9990a06c6553e1c5aada559f1888abd11391485d8f818ee7aec74d2506ce2e04cd57891f7ee70f4259250b8043d6
@@ -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-3-bullseye",
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": "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.1] - 2023-02-03
4
+
5
+ - Fix the constructor args of `Registration::RegistrationError`
6
+
7
+ ## [2.2.0] - 2023-02-03
8
+
9
+ - Stop using HTTP GET for Registration API
10
+ - Use `errmsg` element for error messages
11
+
3
12
  ## [2.1.2] - 2022-04-13
4
13
 
5
14
  - Fix the condition of log filtering
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(/(passwd=)([^&]+)/, '\1[REMOVED]')
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,28 @@ 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: nil)
28
+ @doc = doc
29
+ if msg.nil? && doc
30
+ msg = "#{doc.root.elements['head/errmsg']&.text} (errcd=#{doc.root.elements['head/errcd']&.text})"
31
+ end
32
+ super(msg)
33
+ end
34
+ end
35
+
26
36
  class AuthenticationError < RegistrationError; end
27
37
  class InvalidXMLError < RegistrationError; end
28
38
  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.2'
4
+ VERSION = '2.2.1'
5
5
  end
data/sig/jalc.rbs CHANGED
@@ -1,10 +1,10 @@
1
1
  module JaLC
2
- interface _Logger
3
- end
4
-
5
2
  VERSION: String
6
3
 
7
4
  module Registration
5
+ self.@config: Config
6
+ self.@client: Client
7
+
8
8
  def self.configure: { (Config) -> void } -> void
9
9
  def self.config: -> Config
10
10
 
@@ -12,6 +12,9 @@ module JaLC
12
12
  end
13
13
 
14
14
  class RegistrationError < Error
15
+ def initialize: (?untyped msg, ?doc: untyped) -> void
16
+
17
+ attr_reader doc: untyped # REXML::Document
15
18
  end
16
19
 
17
20
  class AuthenticationError < RegistrationError
@@ -21,28 +24,52 @@ module JaLC
21
24
  end
22
25
 
23
26
  class Client
24
- interface _IO
25
- end
26
- type rexml_document = untyped
27
-
28
27
  def initialize: (Config config) -> void
29
- def post: (_IO xml_file) -> rexml_document
30
- 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
31
38
  end
32
39
 
33
40
  class Config
34
41
  DEFAULT_BASE_URL: String
35
42
 
43
+ def initialize: -> void
44
+
45
+ attr_accessor base_url: String
36
46
  attr_accessor id: String?
37
47
  attr_accessor password: String?
38
- attr_accessor logger: _Logger?
39
-
40
- def initialize: -> void
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
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
46
73
 
47
74
  def self.configure: { (Config) -> void } -> void
48
75
  def self.config: -> Config
@@ -51,11 +78,10 @@ module JaLC
51
78
  end
52
79
 
53
80
  class HTTPError < Error
54
- 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
55
82
 
56
83
  attr_reader response: response_hash?
57
84
 
58
- def initialize: (?String? msg, ?response: response_hash?) -> void
59
85
  def inspect: -> String
60
86
  end
61
87
 
@@ -73,17 +99,36 @@ module JaLC
73
99
 
74
100
  class Client
75
101
  def initialize: (Config config) -> void
102
+
103
+ attr_reader config: Config
104
+ @conn: Faraday::Connection
105
+
76
106
  def prefixes: (?ra: String?, ?sort: String?, ?order: String?) -> response_body
77
107
  def doilist: (String prefix, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
78
108
  def doi: (String doi) -> response_body
109
+
110
+ private
111
+
112
+ def conn: -> Faraday::Connection
79
113
  end
80
114
 
81
115
  class Config
82
116
  DEFAULT_BASE_URL: String
83
117
 
84
- attr_accessor logger: _Logger?
85
-
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.2
4
+ version: 2.2.1
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-13 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