jalc 2.0.1 → 2.1.2

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: 2407227918e30a52acb05438fbb3b1713ee9cb2206000204d795030b78d7f265
4
+ data.tar.gz: 390b6c7e439ef7f487af098808cc717411610d1c07aeafe15b95404eeed7d954
5
5
  SHA512:
6
- metadata.gz: 164852ecb1e72be40a39e609a055de250a3d69446a317ca71a76ae9895c7003c2215b1bdd3a65b1c9a72faffe91247cfdb160e640acce4cf2de5d43a4d5056dd
7
- data.tar.gz: 6ef81e529ec75c794a66605698a5aadb2c632fe2149df97d7b1f237c488bf9348e09c7757af376c17a4348bd2c95004fd7c5556c484e6985ef035b31faf8b165
6
+ metadata.gz: 275263f97587d4258f29d850d19378cdcfedf3ac502b3d13d52cb72b5c259e0f87159cb1a9d136c9fbb9d6c0b4a58b3f2d36ebb2007fe8fe6ca3af38793196ff
7
+ data.tar.gz: d09786ab3e4a994020e6e1f52d575e4bd18f57ce2728944bd8987682c93ec0104150d1a5133fbe3251acb05b55f1984731de23c0aabd313c5e6821a33dc12458
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.1.2] - 2022-04-13
4
+
5
+ - Fix the condition of log filtering
6
+
7
+ ## [2.1.1] - 2022-04-08
8
+
9
+ - Fix a typo of a registration API parameter
10
+
11
+ ## [2.1.0] - 2022-04-07
12
+
13
+ - Update the constructor arguments of REST::Client and Registration::Client
14
+
3
15
  ## [2.0.1] - 2022-03-06
4
16
 
5
17
  - 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_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,16 +44,16 @@ 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|
59
- logger.filter(/(password=)\w+/, '\1[FILTERED]')
54
+ if config.logger
55
+ f.response :logger, config.logger, { headers: false } do |logger|
56
+ logger.filter(/(passwd=)([^&]+)/, '\1[REMOVED]')
60
57
  end
61
58
  end
62
59
  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.2'
5
5
  end
data/sig/jalc.rbs CHANGED
@@ -5,8 +5,6 @@ module JaLC
5
5
  VERSION: String
6
6
 
7
7
  module Registration
8
- BASE_URL: String
9
-
10
8
  def self.configure: { (Config) -> void } -> void
11
9
  def self.config: -> Config
12
10
 
@@ -27,12 +25,14 @@ module JaLC
27
25
  end
28
26
  type rexml_document = untyped
29
27
 
30
- def initialize: (id: String, password: String, ?logger: _Logger?, ?base_url: String) -> void
28
+ def initialize: (Config config) -> void
31
29
  def post: (_IO xml_file) -> rexml_document
32
30
  def get_result: (Integer | String exec_id) -> rexml_document
33
31
  end
34
32
 
35
33
  class Config
34
+ DEFAULT_BASE_URL: String
35
+
36
36
  attr_accessor id: String?
37
37
  attr_accessor password: String?
38
38
  attr_accessor logger: _Logger?
@@ -44,8 +44,6 @@ module JaLC
44
44
  module REST
45
45
  type response_body = Hash[String, untyped] | String | nil
46
46
 
47
- BASE_URL: String
48
-
49
47
  def self.configure: { (Config) -> void } -> void
50
48
  def self.config: -> Config
51
49
 
@@ -74,13 +72,15 @@ module JaLC
74
72
  end
75
73
 
76
74
  class Client
77
- def initialize: (?logger: _Logger?, ?base_url: String) -> void
75
+ def initialize: (Config config) -> void
78
76
  def prefixes: (?ra: String?, ?sort: String?, ?order: String?) -> response_body
79
77
  def doilist: (String prefix, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> response_body
80
78
  def doi: (String doi) -> response_body
81
79
  end
82
80
 
83
81
  class Config
82
+ DEFAULT_BASE_URL: String
83
+
84
84
  attr_accessor logger: _Logger?
85
85
 
86
86
  def initialize: -> void
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.2
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-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday