jalc 1.1.0 → 1.2.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: 0dc45fa2ad1bb26e588c4b99dcd4b79ce9ef6eb1b1ce758fc241b1aefcf553a1
4
- data.tar.gz: 4ab4bd89829b7ad3af731359e9bf0424585e2991255e4a6e29564991937d94d5
3
+ metadata.gz: 96ec63df2a4d939e8eb433fff06fe70d84536174ab759755314dbf67fd21c900
4
+ data.tar.gz: 25288558d0cfb086f73d72634051892d48bf9a21e64de7aa9bb06a72b44dc153
5
5
  SHA512:
6
- metadata.gz: b105bfbf4b983932942144f965d45016ed7d64df42448d425ac94d53479f030f9ddd9bbbc3bdfcb5951fc13365233cdb888fe04478a377caba897d9f5f5e6feb
7
- data.tar.gz: 3465ba5121e720647d40f0dca8b8060990736ea0d712a06b0d6f926a5700966a731f28a1382c84562246498c188b0c22b9ba5d0c01384d27bb2a225e94735bfd
6
+ metadata.gz: 286ab06114bd1b84518239c7b4e801f67a1a275d9e8b9f11e379df59dd66aaa319743849735495c5420f2811f8d5dba879ed162a00a15f805403ab26fd71ca05
7
+ data.tar.gz: b1fbb0ebed28715ea7dfaee774652eef36ccef399c2bc89c2fbe1d260e9a08d84937720fc144665afca3d8799ce325491ede9ce835701b27241e24623fdeec71
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.1.0] - 2022-01-10
3
+ ## [1.2.0] - 2022-01-10
4
4
 
5
- - Add JaLC::Registration for the registration API
5
+ - Filter password on logs
6
+ - Remove `NilStatusError`
7
+ - Create `jalc.rbs`
8
+
9
+ ## [1.1.0] - 2022-01-09
10
+
11
+ - Add `JaLC::Registration` for the registration API
6
12
 
7
13
  ## [1.0.0] - 2022-01-09
8
14
 
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
 
8
8
  gem 'debug'
9
9
  gem 'rake'
10
+ gem 'rbs'
10
11
  gem 'rspec'
11
12
  gem 'rubocop'
12
13
  gem 'rubocop-rake'
data/README.md CHANGED
@@ -31,11 +31,11 @@ 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.body['data']['items'].first['prefix'] #=> 10.123
34
+ prefix = prefixes_res.body['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.body['data']['items'].last['dois']['doi'] #=> 10.123/abc
38
+ doi = doilist_res.body['data']['items'].last['dois']['doi'] #=> "10.123/abc"
39
39
 
40
40
  # GET /dois/:doi
41
41
  doi_res = JaLC::REST.doi(doi)
@@ -52,28 +52,31 @@ 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
58
  res = JaLC::Registration.post(File.open('/path/to/xml'))
58
- # response.body is an instance of REXML::Document
59
- res.body.root.elements['head/okcnt'].text #=> 1
60
59
 
61
- # With XML head/result_method=2 (Async)
60
+ # body is an REXML::Document
61
+ res.body.root.elements['head/okcnt'].text #=> "1"
62
+
63
+ # async registration (result_method=2)
62
64
  async_res = JaLC::Registration.post(StringIO.new(<<~XML))
63
65
  <?xml version="1.0" encoding="UTF-8"?>
64
66
  <root>
65
67
  <head>
66
68
  <result_method>2</result_method>
69
+ <!-- ... -->
67
70
  </head>
68
71
  <body>
69
- ...
72
+ <!-- ... -->
70
73
  </body
71
74
  </root>
72
75
  XML
73
- exec_id = async_res.body.root.elements['head/exec_id'].text #=> 12345
76
+ exec_id = async_res.body.root.elements['head/exec_id'].text #=> "12345"
74
77
 
75
78
  result_res = JaLC::Registration.get_result(exec_id)
76
- res.body.root.elements['head/status'].text
79
+ result_res.body.root.elements['head/status'].text #=> "2"
77
80
  ```
78
81
 
79
82
  ## 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
@@ -52,7 +52,11 @@ module JaLC
52
52
  f.use Middleware::RaiseError
53
53
  f.use Middleware::ParseXML
54
54
  f.response :raise_error
55
- f.response :logger, @logger, { headers: false } if @logger
55
+ if @logger
56
+ f.response :logger, @logger, { headers: false } do |logger|
57
+ logger.filter(/(password=)\w+/, '\1[FILTERED]')
58
+ end
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -7,7 +7,7 @@ module JaLC
7
7
  module Middleware
8
8
  class ParseXML < Faraday::Middleware
9
9
  def on_complete(env)
10
- env[:body] = REXML::Document.new(env[:body].to_s)
10
+ env.body = REXML::Document.new(env.body.to_s)
11
11
  end
12
12
  end
13
13
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JaLC
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
data/sig/jalc.rbs ADDED
@@ -0,0 +1,86 @@
1
+ type faraday_response = untyped
2
+
3
+ module JaLC
4
+ VERSION: String
5
+
6
+ module Registration
7
+ BASE_URL: String
8
+
9
+ def self.configure: { (Config) -> void } -> void
10
+ def self.config: -> Config
11
+
12
+ class Error < StandardError
13
+ end
14
+
15
+ class RegistrationError < Error
16
+ end
17
+
18
+ class AuthenticationError < RegistrationError
19
+ end
20
+
21
+ class InvalidXMLError < RegistrationError
22
+ end
23
+
24
+ class Client
25
+ interface _IO
26
+ end
27
+
28
+ def initialize: (id: String, password: String, ?logger: Logger?, ?base_url: String) -> void
29
+ def post: (_IO xml_file) -> faraday_response
30
+ def get_result: (Integer | String exec_id) -> faraday_response
31
+ end
32
+
33
+ class Config
34
+ attr_accessor id: String?
35
+ attr_accessor password: String?
36
+ attr_accessor logger: Logger?
37
+
38
+ def initialize: -> void
39
+ end
40
+ end
41
+
42
+ module REST
43
+ BASE_URL: String
44
+
45
+ def self.configure: { (Config) -> void } -> void
46
+ def self.config: -> Config
47
+
48
+ class Error < StandardError
49
+ end
50
+
51
+ class HTTPError < Error
52
+ type faraday_header = untyped
53
+ type response_hash = {status: Integer, headers: faraday_header, body: untyped, request: {method: Symbol, url: URI, headers: faraday_header, body: String?}}
54
+
55
+ attr_reader response: response_hash?
56
+
57
+ def initialize: (?String? msg, ?response: response_hash?) -> void
58
+ def inspect: -> String
59
+ end
60
+
61
+ class ClientError < HTTPError
62
+ end
63
+
64
+ class BadRequestError < ClientError
65
+ end
66
+
67
+ class ResourceNotFound < ClientError
68
+ end
69
+
70
+ class ServerError < HTTPError
71
+ end
72
+
73
+ class Client
74
+ def initialize: (?logger: Logger?, ?base_url: String) -> void
75
+ def prefixes: (?ra: String?, ?sort: String?, ?order: String?) -> faraday_response
76
+ def doilist: (String, ?from: String?, ?to: String?, ?rows: Integer? | String?, ?page: Integer? | String?, ?sort: String?, ?order: String?) -> faraday_response
77
+ def doi: (String) -> faraday_response
78
+ end
79
+
80
+ class Config
81
+ attr_accessor logger: Logger?
82
+
83
+ def initialize: -> void
84
+ end
85
+ end
86
+ 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.1.0
4
+ version: 1.2.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-01-09 00:00:00.000000000 Z
11
+ date: 2022-01-10 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/rest.rbs
92
+ - sig/jalc.rbs
79
93
  homepage: https://github.com/sankichi92/jalc-ruby
80
94
  licenses:
81
95
  - MIT
data/sig/jalc/rest.rbs DELETED
@@ -1,6 +0,0 @@
1
- module JaLC
2
- module REST
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end