karaden-prg-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/devcontainer.json +45 -0
  3. data/.devcontainer/docker/ruby/Dockerfile +30 -0
  4. data/.devcontainer/docker-compose.yml +16 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +29 -0
  7. data/.vscode/launch.json +32 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +44 -0
  11. data/Rakefile +8 -0
  12. data/lib/karaden/config.rb +78 -0
  13. data/lib/karaden/exception/bad_request_exception.rb +10 -0
  14. data/lib/karaden/exception/forbidden_exception.rb +10 -0
  15. data/lib/karaden/exception/invalid_params_exception.rb +9 -0
  16. data/lib/karaden/exception/invalid_request_options_exception.rb +9 -0
  17. data/lib/karaden/exception/karaden_exception.rb +15 -0
  18. data/lib/karaden/exception/not_found_exception.rb +10 -0
  19. data/lib/karaden/exception/too_many_requests_exception.rb +10 -0
  20. data/lib/karaden/exception/unauthorized_exception.rb +10 -0
  21. data/lib/karaden/exception/unexpected_value_exception.rb +9 -0
  22. data/lib/karaden/exception/unknown_error_exception.rb +9 -0
  23. data/lib/karaden/exception/unprocessable_entity_exception.rb +10 -0
  24. data/lib/karaden/model/collection.rb +15 -0
  25. data/lib/karaden/model/error.rb +19 -0
  26. data/lib/karaden/model/karaden_object.rb +31 -0
  27. data/lib/karaden/model/message.rb +130 -0
  28. data/lib/karaden/model/requestable.rb +22 -0
  29. data/lib/karaden/net/requestor.rb +55 -0
  30. data/lib/karaden/net/requestor_interface.rb +9 -0
  31. data/lib/karaden/net/response.rb +71 -0
  32. data/lib/karaden/net/response_interface.rb +17 -0
  33. data/lib/karaden/param/message/message_cancel_params.rb +70 -0
  34. data/lib/karaden/param/message/message_create_params.rb +152 -0
  35. data/lib/karaden/param/message/message_detail_params.rb +70 -0
  36. data/lib/karaden/param/message/message_list_params.rb +106 -0
  37. data/lib/karaden/param/message/message_params.rb +12 -0
  38. data/lib/karaden/request_options.rb +153 -0
  39. data/lib/karaden/utility.rb +35 -0
  40. data/lib/karaden.rb +36 -0
  41. data/mock/2023-01-01.yaml +776 -0
  42. data/mock/latest +1 -0
  43. data/package-lock.json +3474 -0
  44. data/package.json +21 -0
  45. data/sig/karaden.rbs +0 -0
  46. metadata +178 -0
@@ -0,0 +1,153 @@
1
+ module Karaden
2
+ class RequestOptions
3
+ attr_accessor :api_base, :api_key, :api_version, :tenant_id, :user_agent, :connection_timeout, :read_timeout
4
+
5
+ def initialize
6
+ @api_base = nil
7
+ @api_key = nil
8
+ @api_version = nil
9
+ @tenant_id = nil
10
+ @user_agent = nil
11
+ @connection_timeout = nil
12
+ @read_timeout = nil
13
+ end
14
+
15
+ def base_uri
16
+ "#{@api_base}/#{@tenant_id}"
17
+ end
18
+
19
+ def merge(source)
20
+ clone.tap do |obj|
21
+ %i[api_base api_key api_version tenant_id user_agent].each do |prop|
22
+ val = source.send(prop)
23
+ obj.send("#{prop}=", val) unless val.nil?
24
+ end
25
+ end
26
+ end
27
+
28
+ def validate
29
+ errors = Karaden::Model::KaradenObject.new
30
+ has_error = false
31
+
32
+ messages = validate_api_base
33
+ unless messages.empty?
34
+ errors.set_property('api_base', messages)
35
+ has_error = true
36
+ end
37
+
38
+ messages = validate_api_key
39
+ unless messages.empty?
40
+ errors.set_property('api_key', messages)
41
+ has_error = true
42
+ end
43
+
44
+ messages = validate_api_version
45
+ unless messages.empty?
46
+ errors.set_property('api_version', messages)
47
+ has_error = true
48
+ end
49
+
50
+ messages = validate_tenant_id
51
+ unless messages.empty?
52
+ errors.set_property('tenant_id', messages)
53
+ has_error = true
54
+ end
55
+
56
+ if has_error
57
+ e = Karaden::Exception::InvalidRequestOptionsException.new
58
+ error = Karaden::Model::Error.new
59
+ error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
60
+ error.set_property('errors', errors)
61
+ e.error = error
62
+ raise e
63
+ end
64
+
65
+ self
66
+ end
67
+
68
+ def self.new_builder
69
+ RequestOptionsBuilder.new
70
+ end
71
+
72
+ protected
73
+
74
+ def validate_api_base
75
+ messages = []
76
+ if @api_base.nil? || @api_base == ''
77
+ messages << 'api_baseは必須です。'
78
+ messages << '文字列を入力してください。'
79
+ end
80
+ messages
81
+ end
82
+
83
+ def validate_api_key
84
+ messages = []
85
+ if @api_key.nil? || @api_key == ''
86
+ messages << 'api_keyは必須です。'
87
+ messages << '文字列を入力してください。'
88
+ end
89
+ messages
90
+ end
91
+
92
+ def validate_api_version
93
+ messages = []
94
+ if @api_version.nil? || @api_version == ''
95
+ messages << 'api_versionは必須です。'
96
+ messages << '文字列を入力してください。'
97
+ end
98
+ messages
99
+ end
100
+
101
+ def validate_tenant_id
102
+ messages = []
103
+ if @tenant_id.nil? || @tenant_id == ''
104
+ messages << 'tenant_idは必須です。'
105
+ messages << '文字列を入力してください。'
106
+ end
107
+ messages
108
+ end
109
+ end
110
+
111
+ class RequestOptionsBuilder
112
+ def initialize
113
+ @request_options = RequestOptions.new
114
+ end
115
+
116
+ def with_api_base(api_base)
117
+ @request_options.api_base = api_base
118
+ self
119
+ end
120
+
121
+ def with_api_key(api_key)
122
+ @request_options.api_key = api_key
123
+ self
124
+ end
125
+
126
+ def with_api_version(api_version)
127
+ @request_options.api_version = api_version
128
+ self
129
+ end
130
+
131
+ def with_tenant_id(tenant_id)
132
+ @request_options.tenant_id = tenant_id
133
+ self
134
+ end
135
+
136
+ def with_user_agent(user_agent)
137
+ @request_options.user_agent = user_agent
138
+ self
139
+ end
140
+
141
+ def with_connection_timeout(connection_timeout)
142
+ @request_options.connection_timeout = connection_timeout
143
+ end
144
+
145
+ def with_read_timeout(read_timeout)
146
+ @request_options.read_timeout = read_timeout
147
+ end
148
+
149
+ def build
150
+ @request_options.clone
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,35 @@
1
+ module Karaden
2
+ class Utility
3
+ OBJECT_TYPES = {
4
+ Karaden::Model::Error::OBJECT_NAME => Karaden::Model::Error,
5
+ Karaden::Model::Collection::OBJECT_NAME => Karaden::Model::Collection,
6
+ Karaden::Model::Message::OBJECT_NAME => Karaden::Model::Message
7
+ }.freeze
8
+
9
+ def self.convert_to_karaden_object(contents, request_options)
10
+ clazz = OBJECT_TYPES[contents['object']] || Karaden::Model::KaradenObject
11
+ construct_from(clazz, contents, request_options)
12
+ end
13
+
14
+ def self.construct_from(clazz, contents, request_options)
15
+ object = clazz.new(contents['id'], request_options)
16
+ contents.each_pair do |key, value|
17
+ v = if value.is_a?(Array)
18
+ convert_to_array(value, request_options)
19
+ elsif value.is_a?(Hash)
20
+ convert_to_karaden_object(value, request_options)
21
+ else
22
+ value
23
+ end
24
+ object.set_property(key, v)
25
+ end
26
+ object
27
+ end
28
+
29
+ def self.convert_to_array(contents, request_options)
30
+ contents.map do |v|
31
+ v.is_a?(Hash) ? convert_to_karaden_object(v, request_options) : v
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/karaden.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'etc'
8
+
9
+ require_relative 'karaden/config'
10
+ require_relative 'karaden/request_options'
11
+ require_relative 'karaden/exception/karaden_exception'
12
+ require_relative 'karaden/exception/bad_request_exception'
13
+ require_relative 'karaden/exception/forbidden_exception'
14
+ require_relative 'karaden/exception/not_found_exception'
15
+ require_relative 'karaden/exception/invalid_request_options_exception'
16
+ require_relative 'karaden/exception/invalid_params_exception'
17
+ require_relative 'karaden/exception/too_many_requests_exception'
18
+ require_relative 'karaden/exception/unexpected_value_exception'
19
+ require_relative 'karaden/exception/unauthorized_exception'
20
+ require_relative 'karaden/exception/unknown_error_exception'
21
+ require_relative 'karaden/exception/unprocessable_entity_exception'
22
+ require_relative 'karaden/net/requestor_interface'
23
+ require_relative 'karaden/net/requestor'
24
+ require_relative 'karaden/net/response_interface'
25
+ require_relative 'karaden/net/response'
26
+ require_relative 'karaden/model/karaden_object'
27
+ require_relative 'karaden/model/requestable'
28
+ require_relative 'karaden/model/message'
29
+ require_relative 'karaden/model/error'
30
+ require_relative 'karaden/model/collection'
31
+ require_relative 'karaden/param/message/message_params'
32
+ require_relative 'karaden/param/message/message_create_params'
33
+ require_relative 'karaden/param/message/message_cancel_params'
34
+ require_relative 'karaden/param/message/message_detail_params'
35
+ require_relative 'karaden/param/message/message_list_params'
36
+ require_relative 'karaden/utility'