jalc 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/Gemfile +1 -0
- data/README.md +11 -10
- data/jalc.gemspec +1 -0
- data/lib/jalc/registration/client.rb +9 -3
- data/lib/jalc/registration/middleware/parse_xml.rb +1 -1
- data/lib/jalc/registration/middleware/raise_error.rb +3 -3
- data/lib/jalc/rest/client.rb +6 -3
- data/lib/jalc/rest/middleware/raise_error.rb +1 -7
- data/lib/jalc/version.rb +1 -1
- data/sig/jalc.rbs +89 -0
- metadata +18 -4
- data/sig/jalc/rest.rbs +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5112d02828c77713d27f6f817b8360b2ba4d7f494116e6e29c7c838a467f612
|
4
|
+
data.tar.gz: c2e4c484221e81cbcc41538a7773a61aab622ce9c463a5887897f71fafc92373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 164852ecb1e72be40a39e609a055de250a3d69446a317ca71a76ae9895c7003c2215b1bdd3a65b1c9a72faffe91247cfdb160e640acce4cf2de5d43a4d5056dd
|
7
|
+
data.tar.gz: 6ef81e529ec75c794a66605698a5aadb2c632fe2149df97d7b1f237c488bf9348e09c7757af376c17a4348bd2c95004fd7c5556c484e6985ef035b31faf8b165
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [2.0.1] - 2022-03-06
|
4
4
|
|
5
|
-
-
|
5
|
+
- Make the registration error messages Japanese
|
6
|
+
|
7
|
+
## [2.0.0] - 2022-01-10
|
8
|
+
|
9
|
+
- Change the return values from `Faraday::Response` to its `#body`
|
10
|
+
|
11
|
+
## [1.2.0] - 2022-01-10
|
12
|
+
|
13
|
+
- Filter password on logs
|
14
|
+
- Remove `NilStatusError`
|
15
|
+
- Create `jalc.rbs`
|
16
|
+
|
17
|
+
## [1.1.0] - 2022-01-09
|
18
|
+
|
19
|
+
- Add `JaLC::Registration` for the registration API
|
6
20
|
|
7
21
|
## [1.0.0] - 2022-01-09
|
8
22
|
|
data/Gemfile
CHANGED
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
|
@@ -52,28 +52,29 @@ require 'jalc'
|
|
52
52
|
JaLC::Registration.configure do |config|
|
53
53
|
config.id = 'sankichi92'
|
54
54
|
config.password = ENV['JALC_PASSWORD']
|
55
|
+
config.logger = nil
|
55
56
|
end
|
56
57
|
|
57
|
-
res = JaLC::Registration.post(File.open('/path/to/xml'))
|
58
|
-
|
59
|
-
res.body.root.elements['head/okcnt'].text #=> 1
|
58
|
+
res = JaLC::Registration.post(File.open('/path/to/xml')) # returns a REXML::Document
|
59
|
+
res.root.elements['head/okcnt'].text #=> "1"
|
60
60
|
|
61
|
-
#
|
61
|
+
# async registration (result_method=2)
|
62
62
|
async_res = JaLC::Registration.post(StringIO.new(<<~XML))
|
63
63
|
<?xml version="1.0" encoding="UTF-8"?>
|
64
64
|
<root>
|
65
65
|
<head>
|
66
66
|
<result_method>2</result_method>
|
67
|
+
<!-- ... -->
|
67
68
|
</head>
|
68
69
|
<body>
|
69
|
-
...
|
70
|
+
<!-- ... -->
|
70
71
|
</body
|
71
72
|
</root>
|
72
73
|
XML
|
73
|
-
exec_id = async_res.
|
74
|
+
exec_id = async_res.root.elements['head/exec_id'].text #=> "12345"
|
74
75
|
|
75
76
|
result_res = JaLC::Registration.get_result(exec_id)
|
76
|
-
|
77
|
+
result_res.root.elements['head/status'].text #=> "2"
|
77
78
|
```
|
78
79
|
|
79
80
|
## Development
|
data/jalc.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
33
33
|
spec.add_dependency 'faraday', '>= 1.0', '< 3.0'
|
34
34
|
spec.add_dependency 'faraday-multipart', '~> 1.0'
|
35
|
+
spec.add_dependency 'rexml', '~> 3.0'
|
35
36
|
|
36
37
|
# For more information and examples about making a new gem, check out our
|
37
38
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -20,7 +20,7 @@ module JaLC
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def post(xml_file)
|
23
|
-
conn.post(
|
23
|
+
response = conn.post(
|
24
24
|
'/jalc/infoRegistry/registDataReceive/index',
|
25
25
|
{
|
26
26
|
login_id: Faraday::Multipart::ParamPart.new(@id, 'text/plain'),
|
@@ -28,10 +28,11 @@ module JaLC
|
|
28
28
|
fname: Faraday::Multipart::FilePart.new(xml_file, 'text/xml'),
|
29
29
|
},
|
30
30
|
)
|
31
|
+
response.body
|
31
32
|
end
|
32
33
|
|
33
34
|
def get_result(exec_id)
|
34
|
-
conn.get(
|
35
|
+
response = conn.get(
|
35
36
|
'/jalc/infoRegistry/registDataResult/index',
|
36
37
|
{
|
37
38
|
login_id: @id,
|
@@ -39,6 +40,7 @@ module JaLC
|
|
39
40
|
exec_id: exec_id,
|
40
41
|
},
|
41
42
|
)
|
43
|
+
response.body
|
42
44
|
end
|
43
45
|
|
44
46
|
private
|
@@ -52,7 +54,11 @@ module JaLC
|
|
52
54
|
f.use Middleware::RaiseError
|
53
55
|
f.use Middleware::ParseXML
|
54
56
|
f.response :raise_error
|
55
|
-
|
57
|
+
if @logger
|
58
|
+
f.response :logger, @logger, { headers: false } do |logger|
|
59
|
+
logger.filter(/(password=)\w+/, '\1[FILTERED]')
|
60
|
+
end
|
61
|
+
end
|
56
62
|
end
|
57
63
|
end
|
58
64
|
end
|
@@ -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/rest/client.rb
CHANGED
@@ -18,7 +18,7 @@ module JaLC
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def prefixes(ra: nil, sort: nil, order: nil)
|
21
|
-
conn.get(
|
21
|
+
response = conn.get(
|
22
22
|
'/prefixes',
|
23
23
|
{
|
24
24
|
ra: ra,
|
@@ -26,10 +26,11 @@ module JaLC
|
|
26
26
|
order: order,
|
27
27
|
}.compact,
|
28
28
|
)
|
29
|
+
response.body
|
29
30
|
end
|
30
31
|
|
31
32
|
def doilist(prefix, from: nil, to: nil, rows: nil, page: nil, sort: nil, order: nil)
|
32
|
-
conn.get(
|
33
|
+
response = conn.get(
|
33
34
|
"/doilist/#{prefix}",
|
34
35
|
{
|
35
36
|
from: from,
|
@@ -40,11 +41,13 @@ module JaLC
|
|
40
41
|
order: order,
|
41
42
|
}.compact,
|
42
43
|
)
|
44
|
+
response.body
|
43
45
|
end
|
44
46
|
|
45
47
|
def doi(doi)
|
46
48
|
encoded_doi = URI.encode_www_form_component(URI.encode_www_form_component(doi))
|
47
|
-
conn.get("/dois/#{encoded_doi}")
|
49
|
+
response = conn.get("/dois/#{encoded_doi}")
|
50
|
+
response.body
|
48
51
|
end
|
49
52
|
|
50
53
|
private
|
@@ -16,13 +16,8 @@ module JaLC
|
|
16
16
|
raise ResourceNotFound.new(response: response_values(env))
|
17
17
|
when 400...500
|
18
18
|
raise ClientError.new(response: response_values(env))
|
19
|
-
when 500...600
|
19
|
+
when 500...600, nil
|
20
20
|
raise ServerError.new(response: response_values(env))
|
21
|
-
when nil
|
22
|
-
raise NilStatusError.new(
|
23
|
-
'http status could not be derived from the server response',
|
24
|
-
response: response_values(env),
|
25
|
-
)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
@@ -68,6 +63,5 @@ module JaLC
|
|
68
63
|
class BadRequestError < ClientError; end
|
69
64
|
class ResourceNotFound < ClientError; end
|
70
65
|
class ServerError < HTTPError; end
|
71
|
-
class NilStatusError < ServerError; end
|
72
66
|
end
|
73
67
|
end
|
data/lib/jalc/version.rb
CHANGED
data/sig/jalc.rbs
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module JaLC
|
2
|
+
interface _Logger
|
3
|
+
end
|
4
|
+
|
5
|
+
VERSION: String
|
6
|
+
|
7
|
+
module Registration
|
8
|
+
BASE_URL: String
|
9
|
+
|
10
|
+
def self.configure: { (Config) -> void } -> void
|
11
|
+
def self.config: -> Config
|
12
|
+
|
13
|
+
class Error < StandardError
|
14
|
+
end
|
15
|
+
|
16
|
+
class RegistrationError < Error
|
17
|
+
end
|
18
|
+
|
19
|
+
class AuthenticationError < RegistrationError
|
20
|
+
end
|
21
|
+
|
22
|
+
class InvalidXMLError < RegistrationError
|
23
|
+
end
|
24
|
+
|
25
|
+
class Client
|
26
|
+
interface _IO
|
27
|
+
end
|
28
|
+
type rexml_document = untyped
|
29
|
+
|
30
|
+
def initialize: (id: String, password: String, ?logger: _Logger?, ?base_url: String) -> void
|
31
|
+
def post: (_IO xml_file) -> rexml_document
|
32
|
+
def get_result: (Integer | String exec_id) -> rexml_document
|
33
|
+
end
|
34
|
+
|
35
|
+
class Config
|
36
|
+
attr_accessor id: String?
|
37
|
+
attr_accessor password: String?
|
38
|
+
attr_accessor logger: _Logger?
|
39
|
+
|
40
|
+
def initialize: -> void
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module REST
|
45
|
+
type response_body = Hash[String, untyped] | String | nil
|
46
|
+
|
47
|
+
BASE_URL: String
|
48
|
+
|
49
|
+
def self.configure: { (Config) -> void } -> void
|
50
|
+
def self.config: -> Config
|
51
|
+
|
52
|
+
class Error < StandardError
|
53
|
+
end
|
54
|
+
|
55
|
+
class HTTPError < Error
|
56
|
+
type response_hash = {status: Integer, headers: Hash[String, String], body: response_body, request: {method: Symbol, url: URI, headers: Hash[String, String], body: String?}}
|
57
|
+
|
58
|
+
attr_reader response: response_hash?
|
59
|
+
|
60
|
+
def initialize: (?String? msg, ?response: response_hash?) -> void
|
61
|
+
def inspect: -> String
|
62
|
+
end
|
63
|
+
|
64
|
+
class ClientError < HTTPError
|
65
|
+
end
|
66
|
+
|
67
|
+
class BadRequestError < ClientError
|
68
|
+
end
|
69
|
+
|
70
|
+
class ResourceNotFound < ClientError
|
71
|
+
end
|
72
|
+
|
73
|
+
class ServerError < HTTPError
|
74
|
+
end
|
75
|
+
|
76
|
+
class Client
|
77
|
+
def initialize: (?logger: _Logger?, ?base_url: String) -> 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
|
81
|
+
end
|
82
|
+
|
83
|
+
class Config
|
84
|
+
attr_accessor logger: _Logger?
|
85
|
+
|
86
|
+
def initialize: -> void
|
87
|
+
end
|
88
|
+
end
|
89
|
+
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:
|
4
|
+
version: 2.0.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-
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rexml
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
47
61
|
description:
|
48
62
|
email:
|
49
63
|
- takahiro-miyoshi@sankichi.net
|
@@ -75,7 +89,7 @@ files:
|
|
75
89
|
- lib/jalc/rest/error.rb
|
76
90
|
- lib/jalc/rest/middleware/raise_error.rb
|
77
91
|
- lib/jalc/version.rb
|
78
|
-
- sig/jalc
|
92
|
+
- sig/jalc.rbs
|
79
93
|
homepage: https://github.com/sankichi92/jalc-ruby
|
80
94
|
licenses:
|
81
95
|
- MIT
|
@@ -100,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
114
|
- !ruby/object:Gem::Version
|
101
115
|
version: '0'
|
102
116
|
requirements: []
|
103
|
-
rubygems_version: 3.3.
|
117
|
+
rubygems_version: 3.3.7
|
104
118
|
signing_key:
|
105
119
|
specification_version: 4
|
106
120
|
summary: JaLC (Japan Link Center) API Client
|