jalc 2.0.1 → 2.1.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: b5112d02828c77713d27f6f817b8360b2ba4d7f494116e6e29c7c838a467f612
4
- data.tar.gz: c2e4c484221e81cbcc41538a7773a61aab622ce9c463a5887897f71fafc92373
3
+ metadata.gz: a5925914098939b17ec3a6743ea89d5c4ffd2d0eee02a6953f82154b2c16f5fe
4
+ data.tar.gz: 4cd2066ea1a7c87959bb69ac6daa04dee66eaec8510a496630b06f4b33f4f55b
5
5
  SHA512:
6
- metadata.gz: 164852ecb1e72be40a39e609a055de250a3d69446a317ca71a76ae9895c7003c2215b1bdd3a65b1c9a72faffe91247cfdb160e640acce4cf2de5d43a4d5056dd
7
- data.tar.gz: 6ef81e529ec75c794a66605698a5aadb2c632fe2149df97d7b1f237c488bf9348e09c7757af376c17a4348bd2c95004fd7c5556c484e6985ef035b31faf8b165
6
+ metadata.gz: ef5428a39e9a9164678f47f53ec0db79c15523f8f09d6f0e066f24d0071655834adb68476c120a262f2a9f24424235b03bce0462ab28193f7484f04aac91c77a
7
+ data.tar.gz: 907e630e36856c8624da546b67971c9e37937b68b560415dfb2309efb448de5ab7376b41d61ed82f97b25bdce4bf152a1cb9175dd3bd5526573409b038f3a81f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.1.0] - 2022-04-07
4
+
5
+ - Update the constructor arguments of REST::Client and Registration::Client
6
+
3
7
  ## [2.0.1] - 2022-03-06
4
8
 
5
9
  - Make the registration error messages Japanese
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_password: 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_password: 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)
@@ -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.1'
4
+ VERSION = '2.1.0'
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,7 +74,7 @@ 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
79
  def doilist: (String prefix, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
80
80
  def doi: (String doi) -> response_body
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.1
4
+ version: 2.1.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-03-06 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday