cpaas_test_ruby 0.1.0
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 +7 -0
- data/.devcontainer/devcontainer.json +38 -0
- data/.devcontainer/docker/ruby/Dockerfile +39 -0
- data/.devcontainer/docker-compose.yml +17 -0
- data/.devcontainer/lifecycle/initialize-command.sh +6 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/.vscode/launch.json +32 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/lib/cpaas_test_ruby/config.rb +78 -0
- data/lib/cpaas_test_ruby/exception/bad_request_exception.rb +10 -0
- data/lib/cpaas_test_ruby/exception/bulk_message_create_failed_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/bulk_message_list_message_retry_limit_exceed_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/bulk_message_show_retry_limit_exceed_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/file_download_failed_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/file_not_found_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/file_upload_failed_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/forbidden_exception.rb +10 -0
- data/lib/cpaas_test_ruby/exception/invalid_params_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/invalid_request_options_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/karaden_exception.rb +15 -0
- data/lib/cpaas_test_ruby/exception/not_found_exception.rb +10 -0
- data/lib/cpaas_test_ruby/exception/too_many_requests_exception.rb +10 -0
- data/lib/cpaas_test_ruby/exception/unauthorized_exception.rb +10 -0
- data/lib/cpaas_test_ruby/exception/unexpected_value_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/unknown_error_exception.rb +9 -0
- data/lib/cpaas_test_ruby/exception/unprocessable_entity_exception.rb +10 -0
- data/lib/cpaas_test_ruby/model/bulk_file.rb +34 -0
- data/lib/cpaas_test_ruby/model/bulk_message.rb +53 -0
- data/lib/cpaas_test_ruby/model/collection.rb +15 -0
- data/lib/cpaas_test_ruby/model/error.rb +19 -0
- data/lib/cpaas_test_ruby/model/karaden_object.rb +31 -0
- data/lib/cpaas_test_ruby/model/message.rb +134 -0
- data/lib/cpaas_test_ruby/model/requestable.rb +29 -0
- data/lib/cpaas_test_ruby/net/no_contents_response.rb +80 -0
- data/lib/cpaas_test_ruby/net/requestor.rb +55 -0
- data/lib/cpaas_test_ruby/net/requestor_interface.rb +9 -0
- data/lib/cpaas_test_ruby/net/response.rb +79 -0
- data/lib/cpaas_test_ruby/net/response_interface.rb +25 -0
- data/lib/cpaas_test_ruby/param/message/bulk/bulk_message_create_params.rb +78 -0
- data/lib/cpaas_test_ruby/param/message/bulk/bulk_message_download_params.rb +126 -0
- data/lib/cpaas_test_ruby/param/message/bulk/bulk_message_list_message_params.rb +72 -0
- data/lib/cpaas_test_ruby/param/message/bulk/bulk_message_params.rb +15 -0
- data/lib/cpaas_test_ruby/param/message/bulk/bulk_message_show_params.rb +72 -0
- data/lib/cpaas_test_ruby/param/message/message_cancel_params.rb +70 -0
- data/lib/cpaas_test_ruby/param/message/message_create_params.rb +152 -0
- data/lib/cpaas_test_ruby/param/message/message_detail_params.rb +70 -0
- data/lib/cpaas_test_ruby/param/message/message_list_params.rb +106 -0
- data/lib/cpaas_test_ruby/param/message/message_params.rb +12 -0
- data/lib/cpaas_test_ruby/request_options.rb +142 -0
- data/lib/cpaas_test_ruby/service/bulk_message_service.rb +90 -0
- data/lib/cpaas_test_ruby/utility.rb +65 -0
- data/lib/cpaas_test_ruby.rb +51 -0
- data/mock/2023-01-01.yaml +776 -0
- data/mock/2023-12-01.yaml +783 -0
- data/mock/2024-03-01.yaml +1061 -0
- data/mock/latest +1 -0
- data/package-lock.json +3474 -0
- data/package.json +21 -0
- data/sig/karaden.rbs +0 -0
- metadata +197 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
module Karaden
|
|
2
|
+
module Model
|
|
3
|
+
class Message < Requestable
|
|
4
|
+
OBJECT_NAME = 'message'.freeze
|
|
5
|
+
|
|
6
|
+
def service_id()
|
|
7
|
+
property('service_id')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def billing_address_id()
|
|
11
|
+
property('billing_address_id')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to()
|
|
15
|
+
property('to')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def body()
|
|
19
|
+
property('body')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def tags()
|
|
23
|
+
property('tags')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def shorten?()
|
|
27
|
+
property('is_shorten')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def shorten_clicked?()
|
|
31
|
+
property('is_shorten_clicked')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def result()
|
|
35
|
+
property('result')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def status()
|
|
39
|
+
property('status')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def sent_result()
|
|
43
|
+
property('sent_result')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def carrier()
|
|
47
|
+
property('carrier')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def scheduled_at()
|
|
51
|
+
scheduled_at = property('scheduled_at')
|
|
52
|
+
begin
|
|
53
|
+
Time.parse(scheduled_at)
|
|
54
|
+
rescue StandardError
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def limited_at()
|
|
60
|
+
limited_at = property('limited_at')
|
|
61
|
+
begin
|
|
62
|
+
Time.parse(limited_at)
|
|
63
|
+
rescue StandardError
|
|
64
|
+
nil
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def sent_at()
|
|
69
|
+
sent_at = property('sent_at')
|
|
70
|
+
begin
|
|
71
|
+
Time.parse(sent_at)
|
|
72
|
+
rescue StandardError
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def received_at()
|
|
78
|
+
received_at = property('received_at')
|
|
79
|
+
begin
|
|
80
|
+
Time.parse(received_at)
|
|
81
|
+
rescue StandardError
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def charged_at()
|
|
87
|
+
charged_at = property('charged_at')
|
|
88
|
+
begin
|
|
89
|
+
Time.parse(charged_at)
|
|
90
|
+
rescue StandardError
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def created_at()
|
|
96
|
+
created_at = property('created_at')
|
|
97
|
+
begin
|
|
98
|
+
Time.parse(created_at)
|
|
99
|
+
rescue StandardError
|
|
100
|
+
nil
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def updated_at()
|
|
105
|
+
updated_at = property('updated_at')
|
|
106
|
+
begin
|
|
107
|
+
Time.parse(updated_at)
|
|
108
|
+
rescue StandardError
|
|
109
|
+
nil
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.create(params, request_options = nil)
|
|
114
|
+
params.validate
|
|
115
|
+
request('POST', params.to_path, 'application/x-www-form-urlencoded', nil, params.to_data, request_options)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.list(params, request_options = nil)
|
|
119
|
+
params.validate
|
|
120
|
+
request('GET', params.to_path, nil, params.to_params, nil, request_options)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.detail(params, request_options = nil)
|
|
124
|
+
params.validate
|
|
125
|
+
request('GET', params.to_path, nil, nil, nil, request_options)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.cancel(params, request_options = nil)
|
|
129
|
+
params.validate
|
|
130
|
+
request('POST', params.to_path, nil, nil, nil, request_options)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Karaden
|
|
2
|
+
module Model
|
|
3
|
+
class Requestable < KaradenObject
|
|
4
|
+
def self.requestor
|
|
5
|
+
@@requestor
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.requestor=(val)
|
|
9
|
+
@@requestor = val
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.request(method, path, content_type = nil, params = nil, data = nil, request_options = nil)
|
|
13
|
+
response = @@requestor.send(method, path, content_type, params, data, request_options)
|
|
14
|
+
raise response.error if response.error?
|
|
15
|
+
|
|
16
|
+
response.object
|
|
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
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Karaden::Model::Requestable.requestor = Karaden::Net::Requestor.new
|
|
@@ -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
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Karaden
|
|
2
|
+
module Net
|
|
3
|
+
class Requestor < RequestorInterface
|
|
4
|
+
DEFAULT_USER_AGENT = 'Karaden/Ruby/'.freeze
|
|
5
|
+
|
|
6
|
+
def send(method, path, content_type = nil, params = nil, data = nil, request_options = nil, is_no_contents: false)
|
|
7
|
+
request_options = Karaden::RequestOptions.new if request_options.nil?
|
|
8
|
+
options = Karaden::Config.as_request_options.merge(request_options).validate
|
|
9
|
+
headers = {
|
|
10
|
+
'User-Agent': build_user_agent(options),
|
|
11
|
+
'Karaden-Client-User-Agent': build_client_user_agent,
|
|
12
|
+
'Karaden-Version' => options.api_version,
|
|
13
|
+
'Content-Type': content_type,
|
|
14
|
+
'Authorization': build_authorization(options)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
uri = URI.parse(build_http_url(path, params, options))
|
|
18
|
+
http = ::Net::HTTP.new(uri.host, uri.port)
|
|
19
|
+
http.use_ssl = uri.scheme == 'https'
|
|
20
|
+
http.open_timeout = options.connection_timeout
|
|
21
|
+
http.read_timeout = options.read_timeout
|
|
22
|
+
|
|
23
|
+
data = URI.encode_www_form(data) unless data.nil?
|
|
24
|
+
response = http.send_request(method, uri.request_uri, data, headers)
|
|
25
|
+
|
|
26
|
+
!is_no_contents ? Karaden::Net::Response.new(response, options) : Karaden::Net::NoContentsResponse.new(response, options)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
protected
|
|
30
|
+
|
|
31
|
+
def build_authorization(request_options)
|
|
32
|
+
"Bearer #{request_options.api_key}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def build_http_url(path, params, request_options)
|
|
36
|
+
uri = URI(request_options.base_uri + path)
|
|
37
|
+
uri.query = URI.encode_www_form(params) unless params.nil?
|
|
38
|
+
uri.to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def build_user_agent(request_options)
|
|
42
|
+
request_options.user_agent || DEFAULT_USER_AGENT + Karaden::Config::VERSION
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def build_client_user_agent
|
|
46
|
+
JSON.generate({
|
|
47
|
+
'bindings_version': Karaden::Config::VERSION,
|
|
48
|
+
'language': 'Ruby',
|
|
49
|
+
'language_version': Object::RUBY_VERSION,
|
|
50
|
+
'uname': Etc.uname.to_s
|
|
51
|
+
})
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Karaden
|
|
2
|
+
module Net
|
|
3
|
+
class Response < 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
|
+
@object = nil
|
|
16
|
+
super()
|
|
17
|
+
interpret(response, request_options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def error()
|
|
21
|
+
@error
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def object()
|
|
25
|
+
@object
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def status_code()
|
|
29
|
+
raise NotImplementedError
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def headers()
|
|
33
|
+
raise NotImplementedError
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def error?()
|
|
37
|
+
!@error.nil?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
|
|
42
|
+
def handle_error(code, headers, body, error)
|
|
43
|
+
clazz = ERRORS[code]
|
|
44
|
+
object = if clazz
|
|
45
|
+
clazz.new
|
|
46
|
+
else
|
|
47
|
+
UnknownErrorException.new
|
|
48
|
+
end
|
|
49
|
+
object.headers = headers
|
|
50
|
+
object.body = body
|
|
51
|
+
object.error = error
|
|
52
|
+
object
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def interpret(response, request_options)
|
|
56
|
+
code = response.code.to_i
|
|
57
|
+
body = response.body
|
|
58
|
+
headers = response.response.each_header.to_h
|
|
59
|
+
contents = JSON.parse(response.body)
|
|
60
|
+
@object = Karaden::Utility.convert_to_karaden_object(contents, request_options)
|
|
61
|
+
if code < 200 || code >= 400
|
|
62
|
+
@error = if @object.is_a?(Karaden::Model::Error)
|
|
63
|
+
handle_error(code, headers, body, @object)
|
|
64
|
+
else
|
|
65
|
+
Karaden::Exception::UnexpectedValueException.new
|
|
66
|
+
end
|
|
67
|
+
@error.code = code
|
|
68
|
+
@error.headers = headers
|
|
69
|
+
@error.body = body
|
|
70
|
+
end
|
|
71
|
+
rescue StandardError => _e
|
|
72
|
+
@error = Karaden::Exception::UnexpectedValueException.new
|
|
73
|
+
@error.code = code
|
|
74
|
+
@error.headers = headers
|
|
75
|
+
@error.body = body
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Karaden
|
|
2
|
+
module Net
|
|
3
|
+
class ResponseInterface
|
|
4
|
+
def error()
|
|
5
|
+
raise NotImplementedError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def object()
|
|
9
|
+
raise NotImplementedError
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def status_code()
|
|
13
|
+
raise NotImplementedError
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def headers()
|
|
17
|
+
raise NotImplementedError
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def error?()
|
|
21
|
+
raise NotImplementedError
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
|
|
26
|
+
messages = validate_id
|
|
27
|
+
errors.set_property('id', messages) unless messages.empty?
|
|
28
|
+
|
|
29
|
+
messages = validate_directory_path
|
|
30
|
+
errors.set_property('directory_path', messages) unless messages.empty?
|
|
31
|
+
|
|
32
|
+
messages = validate_max_retries
|
|
33
|
+
errors.set_property('max_retries', messages) unless messages.empty?
|
|
34
|
+
|
|
35
|
+
messages = validate_retry_interval
|
|
36
|
+
errors.set_property('retry_interval', messages) unless messages.empty?
|
|
37
|
+
|
|
38
|
+
unless errors.property_keys.filter { |key| !errors.property(key).nil? }.empty?
|
|
39
|
+
e = Karaden::Exception::InvalidParamsException.new
|
|
40
|
+
error = Karaden::Model::Error.new
|
|
41
|
+
error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
|
|
42
|
+
error.set_property('errors', errors)
|
|
43
|
+
e.error = error
|
|
44
|
+
raise e
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.new_builder
|
|
51
|
+
BulkMessageDownloadParamsBuilder.new
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
protected
|
|
55
|
+
|
|
56
|
+
def validate_id
|
|
57
|
+
messages = []
|
|
58
|
+
if @id.nil? || @id == ''
|
|
59
|
+
messages << 'idは必須です。'
|
|
60
|
+
messages << '文字列(UUID)を入力してください。'
|
|
61
|
+
end
|
|
62
|
+
messages
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def validate_directory_path
|
|
66
|
+
messages = []
|
|
67
|
+
if @directory_path.nil? || @directory_path == ''
|
|
68
|
+
messages << 'directory_pathは必須です。'
|
|
69
|
+
messages << '文字列を入力してください。'
|
|
70
|
+
else
|
|
71
|
+
messages << '指定されたディレクトリパスが存在しません。' unless Dir.exist?(@directory_path)
|
|
72
|
+
messages << '指定されたパスはディレクトリではありません。' unless File.directory?(@directory_path)
|
|
73
|
+
messages << '指定されたディレクトリには読み取り権限がありません。' unless File.readable?(@directory_path)
|
|
74
|
+
messages << '指定されたディレクトリには書き込み権限がありません。' unless File.writable?(@directory_path)
|
|
75
|
+
end
|
|
76
|
+
messages
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def validate_max_retries
|
|
80
|
+
messages = []
|
|
81
|
+
messages << "max_retriesには#{MIN_MAX_RETRIES}以上の整数を入力してください。" if @max_retries.nil? || !@max_retries.is_a?(Integer) || @max_retries < MIN_MAX_RETRIES
|
|
82
|
+
messages << "max_retriesには#{MAX_MAX_RETRIES}以下の整数を入力してください。" if @max_retries.nil? || !@max_retries.is_a?(Integer) || @max_retries > MAX_MAX_RETRIES
|
|
83
|
+
messages
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def validate_retry_interval
|
|
87
|
+
messages = []
|
|
88
|
+
messages << "retry_intervalには#{MIN_RETRY_INTERVAL}以上の整数を入力してください。" if @retry_interval.nil? || !@retry_interval.is_a?(Integer) || @retry_interval < MIN_RETRY_INTERVAL
|
|
89
|
+
messages << "retry_intervalには#{MAX_RETRY_INTERVAL}以下の整数を入力してください。" if @retry_interval.nil? || !@retry_interval.is_a?(Integer) || @retry_interval > MAX_RETRY_INTERVAL
|
|
90
|
+
messages
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class BulkMessageDownloadParamsBuilder
|
|
95
|
+
def initialize
|
|
96
|
+
@params = BulkMessageDownloadParams.new
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def with_id(id)
|
|
100
|
+
@params.id = id
|
|
101
|
+
self
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def with_directory_path(directory_path)
|
|
105
|
+
@params.directory_path = directory_path
|
|
106
|
+
self
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def with_max_retries(max_retries)
|
|
110
|
+
@params.max_retries = max_retries
|
|
111
|
+
self
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def with_retry_interval(retry_interval)
|
|
115
|
+
@params.retry_interval = retry_interval
|
|
116
|
+
self
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def build
|
|
120
|
+
@params.clone
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
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
|