jalc 1.2.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +8 -9
- data/lib/jalc/registration/client.rb +15 -16
- data/lib/jalc/registration/config.rb +4 -1
- data/lib/jalc/registration/middleware/raise_error.rb +3 -3
- data/lib/jalc/registration.rb +1 -5
- data/lib/jalc/rest/client.rb +12 -10
- data/lib/jalc/rest/config.rb +4 -1
- data/lib/jalc/rest.rb +1 -1
- data/lib/jalc/version.rb +1 -1
- data/sig/jalc.rbs +16 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5925914098939b17ec3a6743ea89d5c4ffd2d0eee02a6953f82154b2c16f5fe
|
4
|
+
data.tar.gz: 4cd2066ea1a7c87959bb69ac6daa04dee66eaec8510a496630b06f4b33f4f55b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef5428a39e9a9164678f47f53ec0db79c15523f8f09d6f0e066f24d0071655834adb68476c120a262f2a9f24424235b03bce0462ab28193f7484f04aac91c77a
|
7
|
+
data.tar.gz: 907e630e36856c8624da546b67971c9e37937b68b560415dfb2309efb448de5ab7376b41d61ed82f97b25bdce4bf152a1cb9175dd3bd5526573409b038f3a81f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
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
|
+
|
7
|
+
## [2.0.1] - 2022-03-06
|
8
|
+
|
9
|
+
- Make the registration error messages Japanese
|
10
|
+
|
11
|
+
## [2.0.0] - 2022-01-10
|
12
|
+
|
13
|
+
- Change the return values from `Faraday::Response` to its `#body`
|
14
|
+
|
3
15
|
## [1.2.0] - 2022-01-10
|
4
16
|
|
5
17
|
- Filter password on logs
|
data/README.md
CHANGED
@@ -31,15 +31,15 @@ JaLC::REST.config.logger = MyLogger.new
|
|
31
31
|
|
32
32
|
# GET /prefixes
|
33
33
|
prefixes_res = JaLC::REST.prefixes(ra: 'JaLC', sort: 'siteId', order: 'desc')
|
34
|
-
prefix = prefixes_res
|
34
|
+
prefix = prefixes_res['data']['items'].first['prefix'] #=> "10.123"
|
35
35
|
|
36
36
|
# GET /doilist/:prefix
|
37
37
|
doilist_res = JaLC::REST.doilist(prefix, rows: 100)
|
38
|
-
doi = doilist_res
|
38
|
+
doi = doilist_res['data']['items'].last['dois']['doi'] #=> "10.123/abc"
|
39
39
|
|
40
40
|
# GET /dois/:doi
|
41
41
|
doi_res = JaLC::REST.doi(doi)
|
42
|
-
doi_res
|
42
|
+
doi_res['data']
|
43
43
|
```
|
44
44
|
|
45
45
|
### JaLC Registration API
|
@@ -50,15 +50,14 @@ 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
|
56
57
|
end
|
57
58
|
|
58
|
-
res = JaLC::Registration.post(File.open('/path/to/xml'))
|
59
|
-
|
60
|
-
# body is an REXML::Document
|
61
|
-
res.body.root.elements['head/okcnt'].text #=> "1"
|
59
|
+
res = JaLC::Registration.post(File.open('/path/to/xml')) # returns a REXML::Document
|
60
|
+
res.root.elements['head/okcnt'].text #=> "1"
|
62
61
|
|
63
62
|
# async registration (result_method=2)
|
64
63
|
async_res = JaLC::Registration.post(StringIO.new(<<~XML))
|
@@ -73,10 +72,10 @@ async_res = JaLC::Registration.post(StringIO.new(<<~XML))
|
|
73
72
|
</body
|
74
73
|
</root>
|
75
74
|
XML
|
76
|
-
exec_id = async_res.
|
75
|
+
exec_id = async_res.root.elements['head/exec_id'].text #=> "12345"
|
77
76
|
|
78
77
|
result_res = JaLC::Registration.get_result(exec_id)
|
79
|
-
result_res.
|
78
|
+
result_res.root.elements['head/status'].text #=> "2"
|
80
79
|
```
|
81
80
|
|
82
81
|
## Development
|
@@ -9,51 +9,50 @@ 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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
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
|
-
conn.post(
|
20
|
+
response = conn.post(
|
24
21
|
'/jalc/infoRegistry/registDataReceive/index',
|
25
22
|
{
|
26
|
-
login_id: Faraday::Multipart::ParamPart.new(
|
27
|
-
login_password: Faraday::Multipart::ParamPart.new(
|
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
|
)
|
28
|
+
response.body
|
31
29
|
end
|
32
30
|
|
33
31
|
def get_result(exec_id)
|
34
|
-
conn.get(
|
32
|
+
response = conn.get(
|
35
33
|
'/jalc/infoRegistry/registDataResult/index',
|
36
34
|
{
|
37
|
-
login_id:
|
38
|
-
login_password:
|
35
|
+
login_id: config.id,
|
36
|
+
login_password: config.password,
|
39
37
|
exec_id: exec_id,
|
40
38
|
},
|
41
39
|
)
|
40
|
+
response.body
|
42
41
|
end
|
43
42
|
|
44
43
|
private
|
45
44
|
|
46
45
|
def conn
|
47
46
|
@conn ||= Faraday.new(
|
48
|
-
url:
|
47
|
+
url: config.base_url,
|
49
48
|
headers: { 'User-Agent' => "jalc-ruby v#{VERSION}" },
|
50
49
|
) do |f|
|
51
50
|
f.request :multipart
|
52
51
|
f.use Middleware::RaiseError
|
53
52
|
f.use Middleware::ParseXML
|
54
53
|
f.response :raise_error
|
55
|
-
if
|
56
|
-
f.response :logger,
|
54
|
+
if config.logger
|
55
|
+
f.response :logger, config.logger, { headers: false } do |logger|
|
57
56
|
logger.filter(/(password=)\w+/, '\1[FILTERED]')
|
58
57
|
end
|
59
58
|
end
|
@@ -5,9 +5,12 @@ require 'logger'
|
|
5
5
|
module JaLC
|
6
6
|
module Registration
|
7
7
|
class Config
|
8
|
-
|
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
|
-
'
|
15
|
+
'IDとパスワードの組合せが間違っているか、アクセス元のIPアドレスがJaLCに登録されているIPアドレスと異なっている可能性があります (errcd=*)'
|
16
16
|
when '#'
|
17
|
-
raise InvalidXMLError, 'XML
|
17
|
+
raise InvalidXMLError, 'XMLファイルの構造に誤りがあるか、login_id、login_passwd、fnameのパラメータに未設定のものがある可能性があります (errcd=#)'
|
18
18
|
when '+'
|
19
|
-
raise RegistrationError, '
|
19
|
+
raise RegistrationError, 'fnameで指定したファイルがXMLファイルでないか、XMLファイルの文字コードがUTF-8でない可能性があります (errcd=+)'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/jalc/registration.rb
CHANGED
data/lib/jalc/rest/client.rb
CHANGED
@@ -9,16 +9,15 @@ 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
|
-
|
16
|
-
|
17
|
-
|
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)
|
21
|
-
conn.get(
|
20
|
+
response = conn.get(
|
22
21
|
'/prefixes',
|
23
22
|
{
|
24
23
|
ra: ra,
|
@@ -26,10 +25,11 @@ module JaLC
|
|
26
25
|
order: order,
|
27
26
|
}.compact,
|
28
27
|
)
|
28
|
+
response.body
|
29
29
|
end
|
30
30
|
|
31
31
|
def doilist(prefix, from: nil, to: nil, rows: nil, page: nil, sort: nil, order: nil)
|
32
|
-
conn.get(
|
32
|
+
response = conn.get(
|
33
33
|
"/doilist/#{prefix}",
|
34
34
|
{
|
35
35
|
from: from,
|
@@ -40,23 +40,25 @@ module JaLC
|
|
40
40
|
order: order,
|
41
41
|
}.compact,
|
42
42
|
)
|
43
|
+
response.body
|
43
44
|
end
|
44
45
|
|
45
46
|
def doi(doi)
|
46
47
|
encoded_doi = URI.encode_www_form_component(URI.encode_www_form_component(doi))
|
47
|
-
conn.get("/dois/#{encoded_doi}")
|
48
|
+
response = conn.get("/dois/#{encoded_doi}")
|
49
|
+
response.body
|
48
50
|
end
|
49
51
|
|
50
52
|
private
|
51
53
|
|
52
54
|
def conn
|
53
55
|
@conn ||= Faraday.new(
|
54
|
-
url:
|
56
|
+
url: config.base_url,
|
55
57
|
headers: { 'User-Agent' => "jalc-ruby v#{VERSION}" },
|
56
58
|
) do |f|
|
57
59
|
f.use Middleware::RaiseError
|
58
60
|
f.response :json
|
59
|
-
f.response :logger,
|
61
|
+
f.response :logger, config.logger, { headers: false } if config.logger
|
60
62
|
end
|
61
63
|
rescue Faraday::Error => e
|
62
64
|
raise e unless e.message.match?(/is not registered/)
|
data/lib/jalc/rest/config.rb
CHANGED
@@ -5,9 +5,12 @@ require 'logger'
|
|
5
5
|
module JaLC
|
6
6
|
module REST
|
7
7
|
class Config
|
8
|
-
|
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
data/lib/jalc/version.rb
CHANGED
data/sig/jalc.rbs
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
type faraday_response = untyped
|
2
|
-
|
3
1
|
module JaLC
|
2
|
+
interface _Logger
|
3
|
+
end
|
4
|
+
|
4
5
|
VERSION: String
|
5
6
|
|
6
7
|
module Registration
|
@@ -24,22 +25,25 @@ module JaLC
|
|
24
25
|
class Client
|
25
26
|
interface _IO
|
26
27
|
end
|
28
|
+
type rexml_document = untyped
|
27
29
|
|
28
|
-
def initialize: (
|
29
|
-
def post: (_IO xml_file) ->
|
30
|
-
def get_result: (Integer | String exec_id) ->
|
30
|
+
def initialize: (Config config) -> void
|
31
|
+
def post: (_IO xml_file) -> rexml_document
|
32
|
+
def get_result: (Integer | String exec_id) -> rexml_document
|
31
33
|
end
|
32
34
|
|
33
35
|
class Config
|
34
36
|
attr_accessor id: String?
|
35
37
|
attr_accessor password: String?
|
36
|
-
attr_accessor logger:
|
38
|
+
attr_accessor logger: _Logger?
|
37
39
|
|
38
40
|
def initialize: -> void
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
module REST
|
45
|
+
type response_body = Hash[String, untyped] | String | nil
|
46
|
+
|
43
47
|
BASE_URL: String
|
44
48
|
|
45
49
|
def self.configure: { (Config) -> void } -> void
|
@@ -49,8 +53,7 @@ module JaLC
|
|
49
53
|
end
|
50
54
|
|
51
55
|
class HTTPError < Error
|
52
|
-
type
|
53
|
-
type response_hash = {status: Integer, headers: faraday_header, body: untyped, request: {method: Symbol, url: URI, headers: faraday_header, body: String?}}
|
56
|
+
type response_hash = {status: Integer, headers: Hash[String, String], body: response_body, request: {method: Symbol, url: URI, headers: Hash[String, String], body: String?}}
|
54
57
|
|
55
58
|
attr_reader response: response_hash?
|
56
59
|
|
@@ -71,14 +74,14 @@ module JaLC
|
|
71
74
|
end
|
72
75
|
|
73
76
|
class Client
|
74
|
-
def initialize: (
|
75
|
-
def prefixes: (?ra: String?, ?sort: String?, ?order: String?) ->
|
76
|
-
def doilist: (String, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) ->
|
77
|
-
def doi: (String) ->
|
77
|
+
def initialize: (Config config) -> void
|
78
|
+
def prefixes: (?ra: String?, ?sort: String?, ?order: 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
|
78
81
|
end
|
79
82
|
|
80
83
|
class Config
|
81
|
-
attr_accessor logger:
|
84
|
+
attr_accessor logger: _Logger?
|
82
85
|
|
83
86
|
def initialize: -> void
|
84
87
|
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: 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-
|
11
|
+
date: 2022-04-07 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.
|
117
|
+
rubygems_version: 3.3.7
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: JaLC (Japan Link Center) API Client
|