jalc 2.0.0 → 2.1.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: 6906443971313b98068ef7816cfde731a473da34698637fafdaeeb99c2409150
4
- data.tar.gz: 35272d82457609a1cb8238bbceb7b69b0b5bcfddb9b1d92a8cbc145459ca3ada
3
+ metadata.gz: eccd488a68365b574a6545965ead9f49c4f49102d4296be4d2dc01ca05201035
4
+ data.tar.gz: 369a77d191d672afae36aa01d404d0bfc7b79a89ea71225c84b8754cd8e8ad3e
5
5
  SHA512:
6
- metadata.gz: 2b50fda5332b2cca03aeb53954f45cd734ed6122377b5fe363370948729e5023133203178e63b5f37723b352a778af5c5e302a3e487c668e37c77edf30a3156f
7
- data.tar.gz: c87b1536b93b0766312f228425da6c97339a86f8b90eea24ea38ee7118bb796c40872bf22f67d738f9503187ec35634a64f70dcac9c4a01dcfef06e6c8d7a865
6
+ metadata.gz: 8a6a6882a2855ea1887600d6980419900a329c3ee9594704ae6ab8fbac0f0e60516475fe6d994975159e440afa6e6185be4e249cc462511a3acb39471998c94c
7
+ data.tar.gz: 20cc3fd0dae75d85d173b8be824421d3bf641ab154c4c7026d252380211b9b46adfb23c7e7fc23ebb24c5484d7b1dcf7cbda8dc809fe7e90c6dc4c007f0ff90b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.1.1] - 2022-04-08
4
+
5
+ - Fix a typo of a registration API parameter
6
+
7
+ ## [2.1.0] - 2022-04-07
8
+
9
+ - Update the constructor arguments of REST::Client and Registration::Client
10
+
11
+ ## [2.0.1] - 2022-03-06
12
+
13
+ - Make the registration error messages Japanese
14
+
3
15
  ## [2.0.0] - 2022-01-10
4
16
 
5
17
  - Change the return values from `Faraday::Response` to its `#body`
data/README.md CHANGED
@@ -50,6 +50,7 @@ See https://japanlinkcenter.org/top/doc/JaLC_tech_interface_doc.pdf for API deta
50
50
  require 'jalc'
51
51
 
52
52
  JaLC::Registration.configure do |config|
53
+ config.base_url = 'https://japanlinkcenter.org' # default
53
54
  config.id = 'sankichi92'
54
55
  config.password = ENV['JALC_PASSWORD']
55
56
  config.logger = nil
@@ -9,22 +9,19 @@ require_relative 'middleware/raise_error'
9
9
 
10
10
  module JaLC
11
11
  module Registration
12
- BASE_URL = 'https://japanlinkcenter.org'
13
-
14
12
  class Client
15
- def initialize(id:, password:, logger: nil, base_url: BASE_URL)
16
- @id = id
17
- @password = password
18
- @logger = logger
19
- @base_url = base_url
13
+ attr_reader :config
14
+
15
+ def initialize(config)
16
+ @config = config
20
17
  end
21
18
 
22
19
  def post(xml_file)
23
20
  response = conn.post(
24
21
  '/jalc/infoRegistry/registDataReceive/index',
25
22
  {
26
- login_id: Faraday::Multipart::ParamPart.new(@id, 'text/plain'),
27
- login_password: Faraday::Multipart::ParamPart.new(@password, 'text/plain'),
23
+ login_id: Faraday::Multipart::ParamPart.new(config.id, 'text/plain'),
24
+ login_passwd: Faraday::Multipart::ParamPart.new(config.password, 'text/plain'),
28
25
  fname: Faraday::Multipart::FilePart.new(xml_file, 'text/xml'),
29
26
  },
30
27
  )
@@ -35,8 +32,8 @@ module JaLC
35
32
  response = conn.get(
36
33
  '/jalc/infoRegistry/registDataResult/index',
37
34
  {
38
- login_id: @id,
39
- login_password: @password,
35
+ login_id: config.id,
36
+ login_passwd: config.password,
40
37
  exec_id: exec_id,
41
38
  },
42
39
  )
@@ -47,15 +44,15 @@ module JaLC
47
44
 
48
45
  def conn
49
46
  @conn ||= Faraday.new(
50
- url: @base_url,
47
+ url: config.base_url,
51
48
  headers: { 'User-Agent' => "jalc-ruby v#{VERSION}" },
52
49
  ) do |f|
53
50
  f.request :multipart
54
51
  f.use Middleware::RaiseError
55
52
  f.use Middleware::ParseXML
56
53
  f.response :raise_error
57
- if @logger
58
- f.response :logger, @logger, { headers: false } do |logger|
54
+ if config.logger
55
+ f.response :logger, config.logger, { headers: false } do |logger|
59
56
  logger.filter(/(password=)\w+/, '\1[FILTERED]')
60
57
  end
61
58
  end
@@ -5,9 +5,12 @@ require 'logger'
5
5
  module JaLC
6
6
  module Registration
7
7
  class Config
8
- attr_accessor :id, :password, :logger
8
+ DEFAULT_BASE_URL = 'https://japanlinkcenter.org'
9
+
10
+ attr_accessor :base_url, :id, :password, :logger
9
11
 
10
12
  def initialize
13
+ @base_url = DEFAULT_BASE_URL
11
14
  @id = nil
12
15
  @password = nil
13
16
  @logger = ::Logger.new($stdout)
@@ -12,11 +12,11 @@ module JaLC
12
12
  case env.body.root.elements['head/errcd']&.text
13
13
  when '*'
14
14
  raise AuthenticationError,
15
- 'Wrong login_id/login_password or non-registered IP address request (errcd=*)'
15
+ 'IDとパスワードの組合せが間違っているか、アクセス元のIPアドレスがJaLCに登録されているIPアドレスと異なっている可能性があります (errcd=*)'
16
16
  when '#'
17
- raise InvalidXMLError, 'XML format is invalid or any required params are blank (errcd=#)'
17
+ raise InvalidXMLError, 'XMLファイルの構造に誤りがあるか、login_id、login_passwd、fnameのパラメータに未設定のものがある可能性があります (errcd=#)'
18
18
  when '+'
19
- raise RegistrationError, 'Non-XML file, non UTF-8 encoding or other error (errcd=+)'
19
+ raise RegistrationError, 'fnameで指定したファイルがXMLファイルでないか、XMLファイルの文字コードがUTF-8でない可能性があります (errcd=+)'
20
20
  end
21
21
  end
22
22
  end
@@ -23,11 +23,7 @@ module JaLC
23
23
  private
24
24
 
25
25
  def client
26
- @client ||= Client.new(
27
- id: config.id,
28
- password: config.password,
29
- logger: config.logger,
30
- )
26
+ @client ||= Client.new(config)
31
27
  end
32
28
  end
33
29
  end
@@ -9,12 +9,11 @@ require_relative '../version'
9
9
 
10
10
  module JaLC
11
11
  module REST
12
- BASE_URL = 'https://api.japanlinkcenter.org'
13
-
14
12
  class Client
15
- def initialize(logger: nil, base_url: BASE_URL)
16
- @logger = logger
17
- @base_url = base_url
13
+ attr_reader :config
14
+
15
+ def initialize(config)
16
+ @config = config
18
17
  end
19
18
 
20
19
  def prefixes(ra: nil, sort: nil, order: nil)
@@ -54,12 +53,12 @@ module JaLC
54
53
 
55
54
  def conn
56
55
  @conn ||= Faraday.new(
57
- url: @base_url,
56
+ url: config.base_url,
58
57
  headers: { 'User-Agent' => "jalc-ruby v#{VERSION}" },
59
58
  ) do |f|
60
59
  f.use Middleware::RaiseError
61
60
  f.response :json
62
- f.response :logger, @logger, { headers: false } if @logger
61
+ f.response :logger, config.logger, { headers: false } if config.logger
63
62
  end
64
63
  rescue Faraday::Error => e
65
64
  raise e unless e.message.match?(/is not registered/)
@@ -5,9 +5,12 @@ require 'logger'
5
5
  module JaLC
6
6
  module REST
7
7
  class Config
8
- attr_accessor :logger
8
+ DEFAULT_BASE_URL = 'https://api.japanlinkcenter.org'
9
+
10
+ attr_accessor :base_url, :logger
9
11
 
10
12
  def initialize
13
+ @base_url = DEFAULT_BASE_URL
11
14
  @logger = ::Logger.new($stdout)
12
15
  end
13
16
  end
data/lib/jalc/rest.rb CHANGED
@@ -23,7 +23,7 @@ module JaLC
23
23
  private
24
24
 
25
25
  def client
26
- @client ||= Client.new(logger: config.logger)
26
+ @client ||= Client.new(config)
27
27
  end
28
28
  end
29
29
  end
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.0.0'
4
+ VERSION = '2.1.1'
5
5
  end
data/sig/jalc.rbs CHANGED
@@ -27,7 +27,7 @@ module JaLC
27
27
  end
28
28
  type rexml_document = untyped
29
29
 
30
- def initialize: (id: String, password: String, ?logger: _Logger?, ?base_url: String) -> void
30
+ def initialize: (Config config) -> void
31
31
  def post: (_IO xml_file) -> rexml_document
32
32
  def get_result: (Integer | String exec_id) -> rexml_document
33
33
  end
@@ -74,10 +74,10 @@ module JaLC
74
74
  end
75
75
 
76
76
  class Client
77
- def initialize: (?logger: _Logger?, ?base_url: String) -> void
77
+ def initialize: (Config config) -> void
78
78
  def prefixes: (?ra: String?, ?sort: String?, ?order: String?) -> response_body
79
- def doilist: (String, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
80
- def doi: (String) -> response_body
79
+ def doilist: (String prefix, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
80
+ def doi: (String doi) -> response_body
81
81
  end
82
82
 
83
83
  class Config
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.0.0
4
+ version: 2.1.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-01-10 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.3.3
117
+ rubygems_version: 3.3.7
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: JaLC (Japan Link Center) API Client