karaden-prg-ruby 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -1
  3. data/lib/karaden/config.rb +2 -2
  4. data/lib/karaden/exception/bulk_message_create_failed_exception.rb +9 -0
  5. data/lib/karaden/exception/bulk_message_list_message_retry_limit_exceed_exception.rb +9 -0
  6. data/lib/karaden/exception/bulk_message_show_retry_limit_exceed_exception.rb +9 -0
  7. data/lib/karaden/exception/file_download_failed_exception.rb +9 -0
  8. data/lib/karaden/exception/file_not_found_exception.rb +9 -0
  9. data/lib/karaden/exception/file_upload_failed_exception.rb +9 -0
  10. data/lib/karaden/model/bulk_file.rb +34 -0
  11. data/lib/karaden/model/bulk_message.rb +53 -0
  12. data/lib/karaden/model/requestable.rb +7 -0
  13. data/lib/karaden/net/no_contents_response.rb +80 -0
  14. data/lib/karaden/net/requestor.rb +2 -2
  15. data/lib/karaden/net/requestor_interface.rb +1 -1
  16. data/lib/karaden/net/response.rb +8 -0
  17. data/lib/karaden/net/response_interface.rb +8 -0
  18. data/lib/karaden/param/message/bulk/bulk_message_create_params.rb +79 -0
  19. data/lib/karaden/param/message/bulk/bulk_message_download_params.rb +139 -0
  20. data/lib/karaden/param/message/bulk/bulk_message_list_message_params.rb +72 -0
  21. data/lib/karaden/param/message/bulk/bulk_message_params.rb +15 -0
  22. data/lib/karaden/param/message/bulk/bulk_message_show_params.rb +72 -0
  23. data/lib/karaden/request_options.rb +2 -0
  24. data/lib/karaden/service/bulk_message_service.rb +90 -0
  25. data/lib/karaden/utility.rb +31 -1
  26. data/lib/karaden.rb +15 -0
  27. data/mock/2024-03-01.yaml +1061 -0
  28. data/mock/latest +1 -1
  29. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ffd0accbb63a2bda3b6275e836415138b90a7c585ccc33ec9928699c69ddaac
4
- data.tar.gz: be9870652cadd3be803410e11e0345a7472765b28b6bd2e82e7f0c1ad8169a63
3
+ metadata.gz: cfe820d3c3ca917f78dba55fb51e0b3d04bcc9e6e133bde0d18927aeb10ec72b
4
+ data.tar.gz: e88f8c518f8ac08582b5c4f8a946eb04eaf03b2ca82e5ee05ba923d502e4ab27
5
5
  SHA512:
6
- metadata.gz: 1d6a54565616e250d833d8000fc4380304975586f9bdd6e588168a1ddb3f476ba30a2acb91434498986e7b04f766fd72b77286db5f2187606bc0a169bf341b92
7
- data.tar.gz: 40a0f8501895aa4a908166703e9cf9346f159b44c98387fde5d38f5b76328fc0d784fbb196f48980f1a75e898c800622300688ddd12abc9098397984384fcbf4
6
+ metadata.gz: 9bb1d1e16c9054c99f73f037551a2c474175997980bb1e4ec1868a51e889eb467b525a666d4355e4b4a543058754aa201b455b2eec7a487b4e46f007554b42bb
7
+ data.tar.gz: 0ebbe2c04fa715e0aec8a9d07fc4958e4f7915790f87a92d9ab59485764ec6e8a1c583a2d54ba5c7538baa6bbf9789925a98b522a391bbec6e872c566e66e2ff
data/README.md CHANGED
@@ -40,5 +40,18 @@ request_options = Karaden::RequestOptions.new_builder
40
40
  .with_tenant_id('<テナントID>')
41
41
  .build
42
42
 
43
- Karaden::Model::Message.detail(params, request_options);
43
+ Karaden::Model::Message.detail(params, request_options)
44
+ ```
45
+ ### タイムアウトについて
46
+ 通信をするファイルサイズや実行環境の通信速度によってはHTTP通信時にタイムアウトが発生する可能性があります。<br />
47
+ 何度も同じような現象が起こる際は、ファイルサイズの調整もしくは`RequestOptions`からタイムアウトの時間を増やして、再度実行してください。<br />
48
+ ```ruby
49
+ request_options = Karaden::RequestOptions.new_builder
50
+ .with_api_key('<トークン>')
51
+ .with_tenant_id('<テナントID>')
52
+ .with_connection_timeout(<秒>)
53
+ .with_read_timeout(<秒>)
54
+ .build
55
+
56
+ bulk_message = Karaden::Service::BulkMessageService.create('<ファイルパス>', request_options)
44
57
  ```
@@ -1,8 +1,8 @@
1
1
  module Karaden
2
2
  class Config
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  DEFAULT_API_BASE = 'https://prg.karaden.jp/api'.freeze
5
- DEFALUT_API_VERSION = '2023-12-01'.freeze
5
+ DEFALUT_API_VERSION = '2024-03-01'.freeze
6
6
 
7
7
  @@http_client = nil
8
8
  @@logger = nil
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class BulkMessageCreateFailedException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class BulkMessageListMessageRetryLimitExceedException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class BulkMessageShowRetryLimitExceedException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class FileDownloadFailedException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class FileNotFoundException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Karaden
2
+ module Exception
3
+ class FileUploadFailedException < KaradenException
4
+ def initialize(message = nil)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ module Karaden
2
+ module Model
3
+ class BulkFile < Requestable
4
+ OBJECT_NAME = 'bulk_file'.freeze
5
+
6
+ def url()
7
+ property('url')
8
+ end
9
+
10
+ def created_at()
11
+ created_at = property('created_at')
12
+ begin
13
+ Time.parse(created_at)
14
+ rescue StandardError
15
+ nil
16
+ end
17
+ end
18
+
19
+ def expires_at()
20
+ expires_at = property('expires_at')
21
+ begin
22
+ Time.parse(expires_at)
23
+ rescue StandardError
24
+ nil
25
+ end
26
+ end
27
+
28
+ def self.create(request_options = nil)
29
+ path = "#{Karaden::Param::Message::Bulk::BulkMessageParams::CONTEXT_PATH}/files"
30
+ request('POST', path, nil, nil, nil, request_options)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ module Karaden
2
+ module Model
3
+ class BulkMessage < Requestable
4
+ OBJECT_NAME = 'bulk_message'.freeze
5
+ STATUS_DONE = 'done'.freeze
6
+ STATUS_WAITING = 'waiting'.freeze
7
+ STATUS_PROCESSING = 'processing'.freeze
8
+ STATUS_ERROR = 'error'.freeze
9
+
10
+ def status()
11
+ property('status')
12
+ end
13
+
14
+ def error()
15
+ property('error')
16
+ end
17
+
18
+ def created_at()
19
+ created_at = property('created_at')
20
+ begin
21
+ Time.parse(created_at)
22
+ rescue StandardError
23
+ nil
24
+ end
25
+ end
26
+
27
+ def updated_at()
28
+ updated_at = property('updated_at')
29
+ begin
30
+ Time.parse(updated_at)
31
+ rescue StandardError
32
+ nil
33
+ end
34
+ end
35
+
36
+ def self.create(params, request_options = nil)
37
+ params.validate
38
+ request('POST', params.to_path, 'application/x-www-form-urlencoded', nil, params.to_data, request_options)
39
+ end
40
+
41
+ def self.show(params, request_options = nil)
42
+ params.validate
43
+ request('GET', params.to_path, nil, nil, nil, request_options)
44
+ end
45
+
46
+ def self.list_message(params, request_options = nil)
47
+ params.validate
48
+ response = request_and_return_response_interface('GET', params.to_path, nil, nil, nil, request_options)
49
+ response.status_code == 302 ? response.headers['location'] : nil
50
+ end
51
+ end
52
+ end
53
+ end
@@ -15,6 +15,13 @@ module Karaden
15
15
 
16
16
  response.object
17
17
  end
18
+
19
+ def self.request_and_return_response_interface(method, path, content_type = nil, params = nil, data = nil, request_options = nil)
20
+ response = @@requestor.send(method, path, content_type, params, data, request_options, true)
21
+ raise response.error if response.error?
22
+
23
+ response
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -0,0 +1,80 @@
1
+ module Karaden
2
+ module Net
3
+ class NoContentsResponse < ResponseInterface
4
+ ERRORS = {
5
+ Karaden::Exception::BadRequestException::STATUS_CODE => Karaden::Exception::BadRequestException,
6
+ Karaden::Exception::UnauthorizedException::STATUS_CODE => Karaden::Exception::UnauthorizedException,
7
+ Karaden::Exception::NotFoundException::STATUS_CODE => Karaden::Exception::NotFoundException,
8
+ Karaden::Exception::ForbiddenException::STATUS_CODE => Karaden::Exception::ForbiddenException,
9
+ Karaden::Exception::UnprocessableEntityException::STATUS_CODE => Karaden::Exception::UnprocessableEntityException,
10
+ Karaden::Exception::TooManyRequestsException::STATUS_CODE => Karaden::Exception::TooManyRequestsException
11
+ }.freeze
12
+
13
+ def initialize(response, request_options)
14
+ @error = nil
15
+ @status_code = nil
16
+ @headers = nil
17
+ super()
18
+ interpret(response, request_options)
19
+ end
20
+
21
+ def error()
22
+ @error
23
+ end
24
+
25
+ def object()
26
+ raise NotImplementedError
27
+ end
28
+
29
+ def status_code()
30
+ @status_code
31
+ end
32
+
33
+ def headers()
34
+ @headers
35
+ end
36
+
37
+ def error?()
38
+ !@error.nil?
39
+ end
40
+
41
+ protected
42
+
43
+ def handle_error(code, headers, body, error)
44
+ clazz = ERRORS[code]
45
+ object = if clazz
46
+ clazz.new
47
+ else
48
+ UnknownErrorException.new
49
+ end
50
+ object.headers = headers
51
+ object.body = body
52
+ object.error = error
53
+ object
54
+ end
55
+
56
+ def interpret(response, request_options)
57
+ @status_code = response.code.to_i
58
+ @headers = response.response.response.each_header.to_h
59
+ if @status_code >= 400
60
+ body = response.body
61
+ contents = JSON.parse(response.body)
62
+ object = Karaden::Utility.convert_to_karaden_object(contents, request_options)
63
+ @error = if object.is_a?(Karaden::Model::Error)
64
+ handle_error(code, @headers, body, object)
65
+ else
66
+ Karaden::Exception::UnexpectedValueException.new
67
+ end
68
+ @error.code = @status_code
69
+ @error.headers = @headers
70
+ @error.body = body
71
+ end
72
+ rescue StandardError => _e
73
+ @error = Karaden::Exception::UnexpectedValueException.new
74
+ @error.code = @status_code
75
+ @error.headers = @headers
76
+ @error.body = body
77
+ end
78
+ end
79
+ end
80
+ end
@@ -3,7 +3,7 @@ module Karaden
3
3
  class Requestor < RequestorInterface
4
4
  DEFAULT_USER_AGENT = 'Karaden/Ruby/'.freeze
5
5
 
6
- def send(method, path, content_type = nil, params = nil, data = nil, request_options = nil)
6
+ def send(method, path, content_type = nil, params = nil, data = nil, request_options = nil, is_no_contents = false)
7
7
  request_options = Karaden::RequestOptions.new if request_options.nil?
8
8
  options = Karaden::Config.as_request_options.merge(request_options).validate
9
9
  headers = {
@@ -23,7 +23,7 @@ module Karaden
23
23
  data = URI.encode_www_form(data) unless data.nil?
24
24
  response = http.send_request(method, uri.request_uri, data, headers)
25
25
 
26
- Karaden::Net::Response.new(response, options)
26
+ !is_no_contents ? Karaden::Net::Response.new(response, options) : Karaden::Net::NoContentsResponse.new(response, options)
27
27
  end
28
28
 
29
29
  protected
@@ -1,7 +1,7 @@
1
1
  module Karaden
2
2
  module Net
3
3
  class RequestorInterface
4
- def send(method, path, content_type = nil, params = nil, data = nil, request_options = nil)
4
+ def send(method, path, content_type = nil, params = nil, data = nil, request_options = nil, is_no_contents = false)
5
5
  raise NotImplementedError
6
6
  end
7
7
  end
@@ -25,6 +25,14 @@ module Karaden
25
25
  @object
26
26
  end
27
27
 
28
+ def status_code()
29
+ raise NotImplementedError
30
+ end
31
+
32
+ def headers()
33
+ raise NotImplementedError
34
+ end
35
+
28
36
  def error?()
29
37
  !@error.nil?
30
38
  end
@@ -9,6 +9,14 @@ module Karaden
9
9
  raise NotImplementedError
10
10
  end
11
11
 
12
+ def status_code()
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def headers()
17
+ raise NotImplementedError
18
+ end
19
+
12
20
  def error?()
13
21
  raise NotImplementedError
14
22
  end
@@ -0,0 +1,79 @@
1
+ module Karaden
2
+ module Param
3
+ module Message
4
+ module Bulk
5
+ class BulkMessageCreateParams < BulkMessageParams
6
+ attr_accessor :bulk_file_id
7
+
8
+ def initialize()
9
+ @bulk_file_id = nil
10
+ super
11
+ end
12
+
13
+ def to_path
14
+ CONTEXT_PATH
15
+ end
16
+
17
+ def to_data
18
+ {
19
+ bulk_file_id: @bulk_file_id
20
+ }.reject { |_, value| value.nil? }
21
+ end
22
+
23
+ def validate
24
+ errors = Karaden::Model::KaradenObject.new
25
+ has_error = false
26
+
27
+ messages = validate_bulk_file_id
28
+ unless messages.empty?
29
+ errors.set_property('bulk_file_id', messages)
30
+ has_error = true
31
+ end
32
+
33
+ if has_error
34
+ e = Karaden::Exception::InvalidParamsException.new
35
+ error = Karaden::Model::Error.new
36
+ error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
37
+ error.set_property('errors', errors)
38
+ e.error = error
39
+ raise e
40
+ end
41
+
42
+ self
43
+ end
44
+
45
+ def self.new_builder
46
+ BulkMessageCreateParamsBuilder.new
47
+ end
48
+
49
+ protected
50
+
51
+ def validate_bulk_file_id
52
+ messages = []
53
+ if @bulk_file_id.nil? || @bulk_file_id == ''
54
+ messages << 'bulk_file_idは必須です。'
55
+ messages << '文字列(UUID)を入力してください。'
56
+ end
57
+ messages
58
+ end
59
+ end
60
+
61
+ class BulkMessageCreateParamsBuilder
62
+ def initialize
63
+ @params = BulkMessageCreateParams.new
64
+ end
65
+
66
+ def with_bulk_file_id(bulk_file_id)
67
+ @params.bulk_file_id = bulk_file_id
68
+ self
69
+ end
70
+
71
+ def build
72
+ @params.clone
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,139 @@
1
+ module Karaden
2
+ module Param
3
+ module Message
4
+ module Bulk
5
+ class BulkMessageDownloadParams < BulkMessageParams
6
+ attr_accessor :id, :directory_path, :max_retries, :retry_interval
7
+
8
+ DEFAULT_MAX_RETRIES = 2
9
+ MAX_MAX_RETRIES = 5
10
+ MIN_MAX_RETRIES = 1
11
+ DEFAULT_RETRY_INTERVAL = 20
12
+ MAX_RETRY_INTERVAL = 60
13
+ MIN_RETRY_INTERVAL = 10
14
+
15
+ def initialize()
16
+ @id = nil
17
+ @directory_path = nil
18
+ @max_retries = DEFAULT_MAX_RETRIES
19
+ @retry_interval = DEFAULT_RETRY_INTERVAL
20
+ super
21
+ end
22
+
23
+ def validate
24
+ errors = Karaden::Model::KaradenObject.new
25
+ has_error = false
26
+
27
+ messages = validate_id
28
+ unless messages.empty?
29
+ errors.set_property('id', messages)
30
+ has_error = true
31
+ end
32
+
33
+ messages = validate_directory_path
34
+ unless messages.empty?
35
+ errors.set_property('directory_path', messages)
36
+ has_error = true
37
+ end
38
+
39
+ messages = validate_max_retries
40
+ unless messages.empty?
41
+ errors.set_property('max_retries', messages)
42
+ has_error = true
43
+ end
44
+
45
+ messages = validate_retry_interval
46
+ unless messages.empty?
47
+ errors.set_property('retry_interval', messages)
48
+ has_error = true
49
+ end
50
+
51
+ if has_error
52
+ e = Karaden::Exception::InvalidParamsException.new
53
+ error = Karaden::Model::Error.new
54
+ error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
55
+ error.set_property('errors', errors)
56
+ e.error = error
57
+ raise e
58
+ end
59
+
60
+ self
61
+ end
62
+
63
+ def self.new_builder
64
+ BulkMessageDownloadParamsBuilder.new
65
+ end
66
+
67
+ protected
68
+
69
+ def validate_id
70
+ messages = []
71
+ if @id.nil? || @id == ''
72
+ messages << 'idは必須です。'
73
+ messages << '文字列(UUID)を入力してください。'
74
+ end
75
+ messages
76
+ end
77
+
78
+ def validate_directory_path
79
+ messages = []
80
+ if @directory_path.nil? || @directory_path == ''
81
+ messages << 'directory_pathは必須です。'
82
+ messages << '文字列を入力してください。'
83
+ else
84
+ messages << '指定されたディレクトリパスが存在しません。' unless Dir.exist?(@directory_path)
85
+ messages << '指定されたパスはディレクトリではありません。' unless File.directory?(@directory_path)
86
+ messages << '指定されたディレクトリには読み取り権限がありません。' unless File.readable?(@directory_path)
87
+ messages << '指定されたディレクトリには書き込み権限がありません。' unless File.writable?(@directory_path)
88
+ end
89
+ messages
90
+ end
91
+
92
+ def validate_max_retries
93
+ messages = []
94
+ messages << "max_retriesには#{MIN_MAX_RETRIES}以上の整数を入力してください。" if @max_retries.nil? || !@max_retries.is_a?(Integer) || @max_retries < MIN_MAX_RETRIES
95
+ messages << "max_retriesには#{MAX_MAX_RETRIES}以下の整数を入力してください。" if @max_retries.nil? || !@max_retries.is_a?(Integer) || @max_retries > MAX_MAX_RETRIES
96
+ messages
97
+ end
98
+
99
+ def validate_retry_interval
100
+ messages = []
101
+ messages << "retry_intervalには#{MIN_RETRY_INTERVAL}以上の整数を入力してください。" if @retry_interval.nil? || !@retry_interval.is_a?(Integer) || @retry_interval < MIN_RETRY_INTERVAL
102
+ messages << "retry_intervalには#{MAX_RETRY_INTERVAL}以下の整数を入力してください。" if @retry_interval.nil? || !@retry_interval.is_a?(Integer) || @retry_interval > MAX_RETRY_INTERVAL
103
+ messages
104
+ end
105
+ end
106
+
107
+ class BulkMessageDownloadParamsBuilder
108
+ def initialize
109
+ @params = BulkMessageDownloadParams.new
110
+ end
111
+
112
+ def with_id(id)
113
+ @params.id = id
114
+ self
115
+ end
116
+
117
+ def with_directory_path(directory_path)
118
+ @params.directory_path = directory_path
119
+ self
120
+ end
121
+
122
+ def with_max_retries(max_retries)
123
+ @params.max_retries = max_retries
124
+ self
125
+ end
126
+
127
+ def with_retry_interval(retry_interval)
128
+ @params.retry_interval = retry_interval
129
+ self
130
+ end
131
+
132
+ def build
133
+ @params.clone
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,72 @@
1
+ module Karaden
2
+ module Param
3
+ module Message
4
+ module Bulk
5
+ class BulkMessageListMessageParams < BulkMessageParams
6
+ attr_accessor :id
7
+
8
+ def initialize()
9
+ @id = nil
10
+ super
11
+ end
12
+
13
+ def to_path
14
+ "#{CONTEXT_PATH}/#{@id}/messages"
15
+ end
16
+
17
+ def validate
18
+ errors = Karaden::Model::KaradenObject.new
19
+ has_error = false
20
+
21
+ messages = validate_id
22
+ unless messages.empty?
23
+ errors.set_property('id', messages)
24
+ has_error = true
25
+ end
26
+
27
+ if has_error
28
+ e = Karaden::Exception::InvalidParamsException.new
29
+ error = Karaden::Model::Error.new
30
+ error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
31
+ error.set_property('errors', errors)
32
+ e.error = error
33
+ raise e
34
+ end
35
+
36
+ self
37
+ end
38
+
39
+ def self.new_builder
40
+ BulkMessageListMessageParamsBuilder.new
41
+ end
42
+
43
+ protected
44
+
45
+ def validate_id
46
+ messages = []
47
+ if @id.nil? || @id == ''
48
+ messages << 'idは必須です。'
49
+ messages << '文字列(UUID)を入力してください。'
50
+ end
51
+ messages
52
+ end
53
+ end
54
+
55
+ class BulkMessageListMessageParamsBuilder
56
+ def initialize
57
+ @params = BulkMessageListMessageParams.new
58
+ end
59
+
60
+ def with_id(id)
61
+ @params.id = id
62
+ self
63
+ end
64
+
65
+ def build
66
+ @params.clone
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ module Karaden
2
+ module Param
3
+ module Message
4
+ module Bulk
5
+ class BulkMessageParams
6
+ CONTEXT_PATH = '/messages/bulks'.freeze
7
+
8
+ def validate()
9
+ self
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end