messagemedia_signingkeys_sdk 1.0.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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +198 -0
  4. data/lib/message_media_signing_keys.rb +70 -0
  5. data/lib/message_media_signing_keys/api_helper.rb +273 -0
  6. data/lib/message_media_signing_keys/configuration.rb +29 -0
  7. data/lib/message_media_signing_keys/controllers/base_controller.rb +59 -0
  8. data/lib/message_media_signing_keys/controllers/signature_key_management_controller.rb +507 -0
  9. data/lib/message_media_signing_keys/exceptions/api_exception.rb +18 -0
  10. data/lib/message_media_signing_keys/exceptions/create_signature_key400_response_exception.rb +32 -0
  11. data/lib/message_media_signing_keys/exceptions/create_signature_key403_response_exception.rb +27 -0
  12. data/lib/message_media_signing_keys/exceptions/delete_signature_key403_response_exception.rb +27 -0
  13. data/lib/message_media_signing_keys/exceptions/disable_the_current_enabled_signature_key403_response_exception.rb +27 -0
  14. data/lib/message_media_signing_keys/exceptions/enable_signature_key400_response_exception.rb +32 -0
  15. data/lib/message_media_signing_keys/exceptions/enable_signature_key403_response_exception.rb +27 -0
  16. data/lib/message_media_signing_keys/exceptions/get_enabled_signature_key403_response_exception.rb +27 -0
  17. data/lib/message_media_signing_keys/exceptions/get_signature_key_detail400_response_exception.rb +32 -0
  18. data/lib/message_media_signing_keys/exceptions/get_signature_key_detail403_response_exception.rb +27 -0
  19. data/lib/message_media_signing_keys/exceptions/get_signature_key_list400_response_exception.rb +32 -0
  20. data/lib/message_media_signing_keys/exceptions/get_signature_key_list403_response_exception.rb +27 -0
  21. data/lib/message_media_signing_keys/http/auth/basic_auth.rb +20 -0
  22. data/lib/message_media_signing_keys/http/faraday_client.rb +55 -0
  23. data/lib/message_media_signing_keys/http/http_call_back.rb +22 -0
  24. data/lib/message_media_signing_keys/http/http_client.rb +102 -0
  25. data/lib/message_media_signing_keys/http/http_context.rb +18 -0
  26. data/lib/message_media_signing_keys/http/http_method_enum.rb +11 -0
  27. data/lib/message_media_signing_keys/http/http_request.rb +48 -0
  28. data/lib/message_media_signing_keys/http/http_response.rb +21 -0
  29. data/lib/message_media_signing_keys/message_media_signing_keys_client.rb +27 -0
  30. data/lib/message_media_signing_keys/models/base_model.rb +34 -0
  31. data/lib/message_media_signing_keys/models/create_signature_key_request.rb +42 -0
  32. data/lib/message_media_signing_keys/models/create_signature_key_response.rb +78 -0
  33. data/lib/message_media_signing_keys/models/enable_signature_key_request.rb +33 -0
  34. data/lib/message_media_signing_keys/models/enable_signature_key_response.rb +69 -0
  35. data/lib/message_media_signing_keys/models/get_enabled_signature_key_response.rb +69 -0
  36. data/lib/message_media_signing_keys/models/get_signature_key_detail_response.rb +69 -0
  37. data/lib/message_media_signing_keys/models/get_signature_key_list_response.rb +69 -0
  38. metadata +164 -0
@@ -0,0 +1,273 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaSigningKeys
5
+ # API utility class
6
+ class APIHelper
7
+ # Serializes an array parameter (creates key value pairs).
8
+ # @param [String] The name of the parameter.
9
+ # @param [Array] The value of the parameter.
10
+ # @param [String] The format of the serialization.
11
+ def self.serialize_array(key, array, formatting: 'indexed')
12
+ tuples = []
13
+
14
+ if formatting == 'unindexed'
15
+ tuples += array.map { |element| ["#{key}[]", element] }
16
+ elsif formatting == 'indexed'
17
+ tuples += array.map.with_index do |element, index|
18
+ ["#{key}[#{index}]", element]
19
+ end
20
+ elsif formatting == 'plain'
21
+ tuples += array.map { |element| [key, element] }
22
+ else
23
+ raise ArgumentError, 'Invalid format provided.'
24
+ end
25
+ tuples
26
+ end
27
+
28
+ # Replaces template parameters in the given url.
29
+ # @param [String] The query string builder to replace the template
30
+ # parameters.
31
+ # @param [Hash] The parameters to replace in the url.
32
+ def self.append_url_with_template_parameters(query_builder, parameters)
33
+ # perform parameter validation
34
+ unless query_builder.instance_of? String
35
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
36
+ invalid.'
37
+ end
38
+
39
+ # Return if there are no parameters to replace.
40
+ return query_builder if parameters.nil?
41
+
42
+ # Iterate and append parameters.
43
+ parameters.each do |key, value|
44
+ replace_value = ''
45
+
46
+ if value.nil?
47
+ replace_value = ''
48
+ elsif value.instance_of? Array
49
+ value.map! { |element| CGI.escape(element.to_s) }
50
+ replace_value = value.join('/')
51
+ else
52
+ replace_value = CGI.escape(value.to_s)
53
+ end
54
+
55
+ # Find the template parameter and replace it with its value.
56
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
57
+ end
58
+ query_builder
59
+ end
60
+
61
+ # Appends the given set of parameters to the given query string.
62
+ # @param [String] The query string builder to add the query parameters to.
63
+ # @param [Hash] The parameters to append.
64
+ # @param [String] The format of array parameter serialization.
65
+ def self.append_url_with_query_parameters(query_builder, parameters,
66
+ array_serialization: 'indexed')
67
+ # Perform parameter validation.
68
+ unless query_builder.instance_of? String
69
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
70
+ is invalid.'
71
+ end
72
+
73
+ # Return if there are no parameters to replace.
74
+ return query_builder if parameters.nil?
75
+
76
+ parameters.each do |key, value|
77
+ seperator = query_builder.include?('?') ? '&' : '?'
78
+ unless value.nil?
79
+ if value.instance_of? Array
80
+ value.compact!
81
+ query_builder += if array_serialization == 'csv'
82
+ "#{seperator}#{key}=#{value.map do |element|
83
+ CGI.escape(element.to_s)
84
+ end.join(',')}"
85
+ elsif array_serialization == 'psv'
86
+ "#{seperator}#{key}=#{value.map do |element|
87
+ CGI.escape(element.to_s)
88
+ end.join('|')}"
89
+ elsif array_serialization == 'tsv'
90
+ "#{seperator}#{key}=#{value.map do |element|
91
+ CGI.escape(element.to_s)
92
+ end.join("\t")}"
93
+ else
94
+ "#{seperator}#{APIHelper.serialize_array(
95
+ key, value, formatting: array_serialization
96
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
97
+ .join('&')}"
98
+ end
99
+ else
100
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
101
+ end
102
+ end
103
+ end
104
+ query_builder
105
+ end
106
+
107
+ # Validates and processes the given Url.
108
+ # @param [String] The given Url to process.
109
+ # @return [String] Pre-processed Url as string.
110
+ def self.clean_url(url)
111
+ # Perform parameter validation.
112
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
113
+
114
+ # Ensure that the urls are absolute.
115
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
116
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
117
+
118
+ # Get the http protocol match.
119
+ protocol = matches[1]
120
+
121
+ # Check if parameters exist.
122
+ index = url.index('?')
123
+
124
+ # Remove redundant forward slashes.
125
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
126
+ query.gsub!(%r{\/\/+}, '/')
127
+
128
+ # Get the parameters.
129
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
130
+
131
+ # Return processed url.
132
+ protocol + query + parameters
133
+ end
134
+
135
+ # Parses JSON string.
136
+ # @param [String] A JSON string.
137
+ def self.json_deserialize(json)
138
+ return JSON.parse(json)
139
+ rescue StandardError
140
+ raise TypeError, 'Server responded with invalid JSON.'
141
+ end
142
+
143
+ # Removes elements with empty values from a hash.
144
+ # @param [Hash] The hash to clean.
145
+ def self.clean_hash(hash)
146
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
147
+ end
148
+
149
+ # Form encodes a hash of parameters.
150
+ # @param [Hash] The hash of parameters to encode.
151
+ # @return [Hash] A hash with the same parameters form encoded.
152
+ def self.form_encode_parameters(form_parameters)
153
+ encoded = {}
154
+ form_parameters.each do |key, value|
155
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
156
+ Configuration.array_serialization))
157
+ end
158
+ encoded
159
+ end
160
+
161
+ def self.custom_merge(a, b)
162
+ x = {}
163
+ a.each do |key, value_a|
164
+ b.each do |k, value_b|
165
+ next unless key == k
166
+ x[k] = []
167
+ if value_a.instance_of? Array
168
+ value_a.each do |v|
169
+ x[k].push(v)
170
+ end
171
+ else
172
+ x[k].push(value_a)
173
+ end
174
+ if value_b.instance_of? Array
175
+ value_b.each do |v|
176
+ x[k].push(v)
177
+ end
178
+ else
179
+ x[k].push(value_b)
180
+ end
181
+ a.delete(k)
182
+ b.delete(k)
183
+ end
184
+ end
185
+ x.merge!(a)
186
+ x.merge!(b)
187
+ x
188
+ end
189
+
190
+ # Form encodes an object.
191
+ # @param [Dynamic] An object to form encode.
192
+ # @param [String] The name of the object.
193
+ # @return [Hash] A form encoded representation of the object in the form
194
+ # of a hash.
195
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
196
+ retval = {}
197
+
198
+ serializable_types = [String, Numeric, TrueClass,
199
+ FalseClass, Date, DateTime]
200
+
201
+ # If this is a structure, resolve it's field names.
202
+ obj = obj.to_hash if obj.is_a? BaseModel
203
+
204
+ # Create a form encoded hash for this object.
205
+ if obj.nil?
206
+ nil
207
+ elsif obj.instance_of? Array
208
+ if formatting == 'indexed'
209
+ obj.each_with_index do |value, index|
210
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
211
+ index.to_s + ']'))
212
+ end
213
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
214
+ obj.each do |value|
215
+ abc = if formatting == 'unindexed'
216
+ APIHelper.form_encode(value, instance_name + '[]',
217
+ formatting: formatting)
218
+ else
219
+ APIHelper.form_encode(value, instance_name,
220
+ formatting: formatting)
221
+ end
222
+ retval = APIHelper.custom_merge(retval, abc)
223
+ # print retval
224
+ end
225
+ else
226
+ obj.each_with_index do |value, index|
227
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
228
+ index.to_s + ']', formatting: formatting))
229
+ end
230
+ end
231
+ elsif obj.instance_of? Hash
232
+ obj.each do |key, value|
233
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
234
+ key + ']', formatting: formatting))
235
+ end
236
+ else
237
+ retval[instance_name] = obj
238
+ end
239
+ retval
240
+ end
241
+
242
+ # Safely converts a string into an rfc3339 DateTime object
243
+ # @param [String] The datetime string
244
+ # @return [DateTime] A DateTime object of rfc3339 format
245
+ def self.rfc3339(date_time)
246
+ # missing timezone information
247
+ if date_time.end_with?('Z') || date_time.index('+')
248
+ DateTime.rfc3339(date_time)
249
+ else
250
+ DateTime.rfc3339(date_time + 'Z')
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ # Extend types to support to_bool.
257
+ module ToBoolean
258
+ def to_bool
259
+ return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
260
+ false
261
+ end
262
+ end
263
+
264
+ # Extend NilClass type to support to_bool.
265
+ class NilClass; include ToBoolean; end
266
+ # Extend TrueClass type to support to_bool.
267
+ class TrueClass; include ToBoolean; end
268
+ # Extend FalseClass type to support to_bool.
269
+ class FalseClass; include ToBoolean; end
270
+ # Extend Numeric type to support to_bool.
271
+ class Numeric; include ToBoolean; end
272
+ # Extend String type to support to_bool.
273
+ class String; include ToBoolean; end
@@ -0,0 +1,29 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaSigningKeys
5
+
6
+ Logging.logger.root.appenders = Logging.appenders.stdout
7
+ Logging.logger.root.level = :info
8
+
9
+ # All configuration including auth info and base URI for the API access
10
+ # are configured in this class.
11
+ class Configuration
12
+ # The base Uri for API calls
13
+ @base_uri = 'https://api.messagemedia.com'
14
+
15
+ # The username to use with basic authentication
16
+ @basic_auth_user_name = 'TODO: Replace'
17
+
18
+ # The password to use with basic authentication
19
+ @basic_auth_password = 'TODO: Replace'
20
+
21
+ # The attribute accessors for public properties.
22
+ class << self
23
+ attr_accessor :array_serialization
24
+ attr_accessor :base_uri
25
+ attr_accessor :basic_auth_user_name
26
+ attr_accessor :basic_auth_password
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaSigningKeys
5
+ # Base controller.
6
+ class BaseController
7
+ attr_accessor :http_client, :http_call_back
8
+
9
+ def initialize(http_client: nil, http_call_back: nil)
10
+ @http_client = http_client || FaradayClient.new
11
+ @http_call_back = http_call_back
12
+
13
+ @global_headers = {
14
+ 'user-agent' => 'messagemedia-signingkeys-sdk-1.0.0'
15
+ }
16
+ @logger = Logging.logger[self]
17
+ @logger.info("Instantiated controller class.")
18
+ end
19
+
20
+ def validate_parameters(args)
21
+ args.each do |_name, value|
22
+ if value.nil?
23
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
+ end
25
+ end
26
+ end
27
+
28
+ def execute_request(request, binary: false, name: nil)
29
+ @logger.info("Calling the on_before_request method of http_call_back for #{name}.") if @http_call_back
30
+ @http_call_back.on_before_request(request) if @http_call_back
31
+
32
+ @logger.info("Merging global headers with endpoint headers for #{name}.")
33
+ APIHelper.clean_hash(request.headers)
34
+ request.headers = @global_headers.clone.merge(request.headers)
35
+
36
+ @logger.debug("Raw request for #{name} is: #{request.inspect}")
37
+ response = if binary
38
+ @http_client.execute_as_binary(request)
39
+ else
40
+ @http_client.execute_as_string(request)
41
+ end
42
+ @logger.debug("Raw response for #{name} is: #{response.inspect}")
43
+ @logger.info("Wrapping request and response in a context object for #{name}.")
44
+ context = HttpContext.new(request, response)
45
+
46
+ @logger.info("Calling on_after_response method of http_call_back for #{name}.") if @http_call_back
47
+ @http_call_back.on_after_response(context) if @http_call_back
48
+
49
+ context
50
+ end
51
+
52
+ def validate_response(context)
53
+ raise CreateSignatureKey403ResponseException.new 'Unexpected error in API call. See HTTP response body for details.', context if
54
+ context.response.status_code == 403
55
+ raise APIException.new 'HTTP Response Not OK', context unless
56
+ context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,507 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaSigningKeys
5
+ # SignatureKeyManagementController
6
+ class SignatureKeyManagementController < BaseController
7
+ @instance = SignatureKeyManagementController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
15
+ end
16
+
17
+ # Disable the current enabled signature key.
18
+ # A successful request for the ```disable the current enabled signature
19
+ # key.``` endpoint will return no content when successful.
20
+ # If there is an enabled key, it will be disabled; and the 204 status code
21
+ # is returned.
22
+ # If there is no key or no enabled key, the 204 status code is also
23
+ # returned.
24
+ # @param [String] content_type Required parameter: Example:
25
+ # @param [String] accept Required parameter: Example:
26
+ # @return void response from the API call
27
+ def delete_disable_the_current_enabled_signature_key(content_type,
28
+ accept)
29
+ begin
30
+ @logger.info("delete_disable_the_current_enabled_signature_key called.")
31
+ # Prepare query url.
32
+ @logger.info("Preparing query URL for delete_disable_the_current_enabled_signature_key.")
33
+ _query_builder = Configuration.base_uri.dup
34
+ _query_builder << '/v1/iam/signature_keys/enabled'
35
+ _query_url = APIHelper.clean_url _query_builder
36
+
37
+ # Prepare headers.
38
+ @logger.info("Preparing headers for delete_disable_the_current_enabled_signature_key.")
39
+ _headers = {
40
+ 'Content-Type' => content_type,
41
+ 'Accept' => accept
42
+ }
43
+
44
+ # Prepare and execute HttpRequest.
45
+ @logger.info('Preparing and executing HttpRequest for delete_disable_the_current_enabled_signature_key.')
46
+ _request = @http_client.delete(
47
+ _query_url,
48
+ headers: _headers
49
+ )
50
+ BasicAuth.apply(_request)
51
+ _context = execute_request(_request, name: 'delete_disable_the_current_enabled_signature_key')
52
+ validate_response(_context)
53
+
54
+ rescue Exception => e
55
+ @logger.error(e)
56
+ raise e
57
+ end
58
+ end
59
+
60
+ # Delete a signature key using the key_id returned in the ```create
61
+ # signature key``` endpoint.
62
+ # A successful request for the ```delete signature key``` endpoint will
63
+ # return an empty response body.
64
+ # *Note: If an invalid or non-existent key_id parameter is specified in the
65
+ # request, then an HTTP 404 Not Found response will be returned*
66
+ # @param [String] key_id Required parameter: Example:
67
+ # @param [String] content_type Required parameter: Example:
68
+ # @param [String] accept Required parameter: Example:
69
+ # @return void response from the API call
70
+ def delete_signature_key(key_id,
71
+ content_type,
72
+ accept)
73
+ begin
74
+ @logger.info("delete_signature_key called.")
75
+ # Prepare query url.
76
+ @logger.info("Preparing query URL for delete_signature_key.")
77
+ _query_builder = Configuration.base_uri.dup
78
+ _query_builder << '/v1/iam/signature_keys/{key_id}'
79
+ _query_builder = APIHelper.append_url_with_template_parameters(
80
+ _query_builder,
81
+ 'key_id' => key_id
82
+ )
83
+ _query_url = APIHelper.clean_url _query_builder
84
+
85
+ # Prepare headers.
86
+ @logger.info("Preparing headers for delete_signature_key.")
87
+ _headers = {
88
+ 'Content-Type' => content_type,
89
+ 'Accept' => accept
90
+ }
91
+
92
+ # Prepare and execute HttpRequest.
93
+ @logger.info('Preparing and executing HttpRequest for delete_signature_key.')
94
+ _request = @http_client.delete(
95
+ _query_url,
96
+ headers: _headers
97
+ )
98
+ BasicAuth.apply(_request)
99
+ _context = execute_request(_request, name: 'delete_signature_key')
100
+
101
+ # Validate response against endpoint and global error codes.
102
+ @logger.info("Validating response for delete_signature_key.")
103
+ if _context.response.status_code == 404
104
+ raise DeleteSignatureKey403ResponseException.new(
105
+ 'Unexpected error in API call. See HTTP response body for details.',
106
+ _context
107
+ )
108
+ end
109
+ validate_response(_context)
110
+
111
+ rescue Exception => e
112
+ @logger.error(e)
113
+ raise e
114
+ end
115
+ end
116
+
117
+ # Retrieve the current detail of a signature key using the key_id returned
118
+ # in the ```create signature key``` endpoint.
119
+ # A successful request for the ```get signature key detail``` endpoint will
120
+ # return a response body as follows:
121
+ # ```json
122
+ # {
123
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31",
124
+ # "cipher": "RSA",
125
+ # "digest": "SHA224",
126
+ # "created": "2018-01-18T10:16:12.364Z",
127
+ # "enabled": false
128
+ # }
129
+ # ```
130
+ # *Note: If an invalid or non-existent key_id parameter is specified in the
131
+ # request, then an HTTP 404 Not Found response will be returned*
132
+ # @param [String] key_id Required parameter: Example:
133
+ # @param [String] content_type Required parameter: Example:
134
+ # @param [String] accept Required parameter: Example:
135
+ # @return GETSignatureKeyDetailResponse response from the API call
136
+ def get_signature_key_detail(key_id,
137
+ content_type,
138
+ accept)
139
+ begin
140
+ @logger.info("get_signature_key_detail called.")
141
+ # Prepare query url.
142
+ @logger.info("Preparing query URL for get_signature_key_detail.")
143
+ _query_builder = Configuration.base_uri.dup
144
+ _query_builder << '/v1/iam/signature_keys/{key_id}'
145
+ _query_builder = APIHelper.append_url_with_template_parameters(
146
+ _query_builder,
147
+ 'key_id' => key_id
148
+ )
149
+ _query_url = APIHelper.clean_url _query_builder
150
+
151
+ # Prepare headers.
152
+ @logger.info("Preparing headers for get_signature_key_detail.")
153
+ _headers = {
154
+ 'Content-Type' => content_type,
155
+ 'Accept' => accept
156
+ }
157
+
158
+ # Prepare and execute HttpRequest.
159
+ @logger.info('Preparing and executing HttpRequest for get_signature_key_detail.')
160
+ _request = @http_client.get(
161
+ _query_url,
162
+ headers: _headers
163
+ )
164
+ BasicAuth.apply(_request)
165
+ _context = execute_request(_request, name: 'get_signature_key_detail')
166
+
167
+ # Validate response against endpoint and global error codes.
168
+ @logger.info("Validating response for get_signature_key_detail.")
169
+ if _context.response.status_code == 400
170
+ raise GETSignatureKeyDetail400ResponseException.new(
171
+ 'Unexpected error in API call. See HTTP response body for details.',
172
+ _context
173
+ )
174
+ elsif _context.response.status_code == 404
175
+ raise GETSignatureKeyDetail403ResponseException.new(
176
+ 'Unexpected error in API call. See HTTP response body for details.',
177
+ _context
178
+ )
179
+ end
180
+ validate_response(_context)
181
+
182
+ # Return appropriate response type.
183
+ @logger.info("Returning response for get_signature_key_detail.")
184
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
185
+ GETSignatureKeyDetailResponse.from_hash(decoded)
186
+
187
+ rescue Exception => e
188
+ @logger.error(e)
189
+ raise e
190
+ end
191
+ end
192
+
193
+ # This will create a key pair:
194
+ # - The ```private key``` stored in MessageMedia is used to create the
195
+ # signature.
196
+ # - The ```public key``` is returned and stored at your side to verify the
197
+ # signature in callbacks.
198
+ # You need to enable your signature key after creating.
199
+ # The most basic body has the following structure:
200
+ # ```json
201
+ # {
202
+ # "digest": "SHA224",
203
+ # "cipher": "RSA"
204
+ # }
205
+ # ```
206
+ # - ```digest``` is used to hash the message. The valid values for digest
207
+ # type are: SHA224, SHA256, SHA512
208
+ # - ```cipher``` is used to encrypt the hashed message. The valid value for
209
+ # cipher type is: RSA
210
+ # A successful request for the ```create signature key``` endpoint will
211
+ # return a response body as follows:
212
+ # ```json
213
+ # {
214
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31",
215
+ # "public_key":
216
+ # "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTIxtRyT5CuOD74r7UCT+AKzWNxvaAP9myj
217
+ # AqR7+vBnJKEvoPnmbKTnm6uLlxutnMbjKrnCCWnQ9vtBVnnd+ElhwLDPADfMcJoOqwi7mTcxuc
218
+ # ckeEbBsfsgYRfdacxgSZL8hVD1hLViQr3xwjEIkJcx1w3x8npvwMuTY0uW8+PjwIDAQAB",
219
+ # "cipher": "RSA",
220
+ # "digest": "SHA224",
221
+ # "created": "2018-01-18T10:16:12.364Z",
222
+ # "enabled": false
223
+ # }
224
+ # ```
225
+ # The response body of a successful POST request to the ```create signature
226
+ # key``` endpoint will contain six properties:
227
+ # - ```key_id``` will be a 36 character UUID which can be used to enable,
228
+ # delete or get the details.
229
+ # - ```public_key``` is used to decrypt the signature.
230
+ # - ```cipher``` same as cipher in request body.
231
+ # - ```digest``` same as digest in request body.
232
+ # - ```created``` is the created date.
233
+ # - ```enabled``` is false for the new signature key. You can use the
234
+ # ```enable signature key``` endpoint to set this field to true.
235
+ # @param [String] content_type Required parameter: Example:
236
+ # @param [String] accept Required parameter: Example:
237
+ # @param [CreateSignatureKeyRequest] body Required parameter: Example:
238
+ # @return CreateSignatureKeyResponse response from the API call
239
+ def create_signature_key(content_type,
240
+ accept,
241
+ body)
242
+ begin
243
+ @logger.info("create_signature_key called.")
244
+ # Prepare query url.
245
+ @logger.info("Preparing query URL for create_signature_key.")
246
+ _query_builder = Configuration.base_uri.dup
247
+ _query_builder << '/v1/iam/signature_keys'
248
+ _query_url = APIHelper.clean_url _query_builder
249
+
250
+ # Prepare headers.
251
+ @logger.info("Preparing headers for create_signature_key.")
252
+ _headers = {
253
+ 'Content-Type' => content_type,
254
+ 'Accept' => accept
255
+ }
256
+
257
+ # Prepare and execute HttpRequest.
258
+ @logger.info('Preparing and executing HttpRequest for create_signature_key.')
259
+ _request = @http_client.post(
260
+ _query_url,
261
+ headers: _headers,
262
+ parameters: body.to_json
263
+ )
264
+ BasicAuth.apply(_request)
265
+ _context = execute_request(_request, name: 'create_signature_key')
266
+
267
+ # Validate response against endpoint and global error codes.
268
+ @logger.info("Validating response for create_signature_key.")
269
+ if _context.response.status_code == 400
270
+ raise CreateSignatureKey400ResponseException.new(
271
+ 'Unexpected error in API call. See HTTP response body for details.',
272
+ _context
273
+ )
274
+ end
275
+ validate_response(_context)
276
+
277
+ # Return appropriate response type.
278
+ @logger.info("Returning response for create_signature_key.")
279
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
280
+ CreateSignatureKeyResponse.from_hash(decoded)
281
+
282
+ rescue Exception => e
283
+ @logger.error(e)
284
+ raise e
285
+ end
286
+ end
287
+
288
+ # Retrieve the currently enabled signature key.
289
+ # A successful request for the ```get enabled signature key``` endpoint will
290
+ # return a response body as follows:
291
+ # ```json
292
+ # {
293
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31",
294
+ # "cipher": "RSA",
295
+ # "digest": "SHA224",
296
+ # "created": "2018-01-18T10:16:12.364Z",
297
+ # "enabled": true
298
+ # }
299
+ # ```
300
+ # *Note: If there is no enabled signature key, then an HTTP 404 Not Found
301
+ # response will be returned*
302
+ # @param [String] content_type Required parameter: Example:
303
+ # @param [String] accept Required parameter: Example:
304
+ # @return GetEnabledSignatureKeyResponse response from the API call
305
+ def get_enabled_signature_key(content_type,
306
+ accept)
307
+ begin
308
+ @logger.info("get_enabled_signature_key called.")
309
+ # Prepare query url.
310
+ @logger.info("Preparing query URL for get_enabled_signature_key.")
311
+ _query_builder = Configuration.base_uri.dup
312
+ _query_builder << '/v1/iam/signature_keys/enabled'
313
+ _query_url = APIHelper.clean_url _query_builder
314
+
315
+ # Prepare headers.
316
+ @logger.info("Preparing headers for get_enabled_signature_key.")
317
+ _headers = {
318
+ 'Content-Type' => content_type,
319
+ 'Accept' => accept
320
+ }
321
+
322
+ # Prepare and execute HttpRequest.
323
+ @logger.info('Preparing and executing HttpRequest for get_enabled_signature_key.')
324
+ _request = @http_client.get(
325
+ _query_url,
326
+ headers: _headers
327
+ )
328
+ BasicAuth.apply(_request)
329
+ _context = execute_request(_request, name: 'get_enabled_signature_key')
330
+
331
+ # Validate response against endpoint and global error codes.
332
+ @logger.info("Validating response for get_enabled_signature_key.")
333
+ if _context.response.status_code == 404
334
+ raise GetEnabledSignatureKey403ResponseException.new(
335
+ 'Unexpected error in API call. See HTTP response body for details.',
336
+ _context
337
+ )
338
+ end
339
+ validate_response(_context)
340
+
341
+ # Return appropriate response type.
342
+ @logger.info("Returning response for get_enabled_signature_key.")
343
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
344
+ GetEnabledSignatureKeyResponse.from_hash(decoded)
345
+
346
+ rescue Exception => e
347
+ @logger.error(e)
348
+ raise e
349
+ end
350
+ end
351
+
352
+ # Enable a signature key using the key_id returned in the ```create
353
+ # signature key``` endpoint.
354
+ # There is only one signature key is enabled at the one moment in time. So
355
+ # if you enable the new signature key, the old one will be disabled.
356
+ # The most basic body has the following structure:
357
+ # ```json
358
+ # {
359
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31"
360
+ # }
361
+ # ```
362
+ # The response body of a successful PATCH request to ```enable signature
363
+ # key``` endpoint will contain the ```enabled``` properties with the value
364
+ # is true as follows:
365
+ # ```json
366
+ # {
367
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31",
368
+ # "cipher": "RSA",
369
+ # "digest": "SHA224",
370
+ # "created": "2018-01-18T10:16:12.364Z",
371
+ # "enabled": true
372
+ # }
373
+ # ```
374
+ # *Note: If an invalid or non-existent key_id parameter is specified in the
375
+ # request, then an HTTP 404 Not Found response will be returned*
376
+ # @param [String] content_type Required parameter: Example:
377
+ # @param [String] accept Required parameter: Example:
378
+ # @param [EnableSignatureKeyRequest] body Required parameter: Example:
379
+ # @return EnableSignatureKeyResponse response from the API call
380
+ def update_enable_signature_key(content_type,
381
+ accept,
382
+ body)
383
+ begin
384
+ @logger.info("update_enable_signature_key called.")
385
+ # Prepare query url.
386
+ @logger.info("Preparing query URL for update_enable_signature_key.")
387
+ _query_builder = Configuration.base_uri.dup
388
+ _query_builder << '/v1/iam/signature_keys/enabled'
389
+ _query_url = APIHelper.clean_url _query_builder
390
+
391
+ # Prepare headers.
392
+ @logger.info("Preparing headers for update_enable_signature_key.")
393
+ _headers = {
394
+ 'Content-Type' => content_type,
395
+ 'Accept' => accept
396
+ }
397
+
398
+ # Prepare and execute HttpRequest.
399
+ @logger.info('Preparing and executing HttpRequest for update_enable_signature_key.')
400
+ _request = @http_client.patch(
401
+ _query_url,
402
+ headers: _headers,
403
+ parameters: body.to_json
404
+ )
405
+ BasicAuth.apply(_request)
406
+ _context = execute_request(_request, name: 'update_enable_signature_key')
407
+
408
+ # Validate response against endpoint and global error codes.
409
+ @logger.info("Validating response for update_enable_signature_key.")
410
+ if _context.response.status_code == 400
411
+ raise EnableSignatureKey400ResponseException.new(
412
+ 'Unexpected error in API call. See HTTP response body for details.',
413
+ _context
414
+ )
415
+ elsif _context.response.status_code == 404
416
+ raise EnableSignatureKey403ResponseException.new(
417
+ 'Unexpected error in API call. See HTTP response body for details.',
418
+ _context
419
+ )
420
+ end
421
+ validate_response(_context)
422
+
423
+ # Return appropriate response type.
424
+ @logger.info("Returning response for update_enable_signature_key.")
425
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
426
+ EnableSignatureKeyResponse.from_hash(decoded)
427
+
428
+ rescue Exception => e
429
+ @logger.error(e)
430
+ raise e
431
+ end
432
+ end
433
+
434
+ # Retrieve the paginated list of signature keys.
435
+ # A successful request for the ```get signature key list``` endpoint will
436
+ # return a response body as follows:
437
+ # ```json
438
+ # [
439
+ # {
440
+ # "key_id": "7ca628a8-08b0-4e42-aeb8-960b37049c31",
441
+ # "cipher": "RSA",
442
+ # "digest": "SHA224",
443
+ # "created": "2018-01-18T10:16:12.364Z",
444
+ # "enabled": false
445
+ # }
446
+ # ]
447
+ # ```
448
+ # @param [String] content_type Required parameter: Example:
449
+ # @param [String] accept Required parameter: Example:
450
+ # @param [String] page Optional parameter: Example:
451
+ # @param [String] page_size Optional parameter: Example:
452
+ # @return List of GETSignatureKeyListResponse response from the API call
453
+ def get_signature_key_list(content_type,
454
+ accept,
455
+ page = nil,
456
+ page_size = nil)
457
+ begin
458
+ @logger.info("get_signature_key_list called.")
459
+ # Prepare query url.
460
+ @logger.info("Preparing query URL for get_signature_key_list.")
461
+ _query_builder = Configuration.base_uri.dup
462
+ _query_builder << '/v1/iam/signature_keys?page={page}&page_size={page_size}'
463
+ _query_builder = APIHelper.append_url_with_template_parameters(
464
+ _query_builder,
465
+ 'page' => page,
466
+ 'page_size' => page_size
467
+ )
468
+ _query_url = APIHelper.clean_url _query_builder
469
+
470
+ # Prepare headers.
471
+ @logger.info("Preparing headers for get_signature_key_list.")
472
+ _headers = {
473
+ 'Content-Type' => content_type,
474
+ 'Accept' => accept
475
+ }
476
+
477
+ # Prepare and execute HttpRequest.
478
+ @logger.info('Preparing and executing HttpRequest for get_signature_key_list.')
479
+ _request = @http_client.get(
480
+ _query_url,
481
+ headers: _headers
482
+ )
483
+ BasicAuth.apply(_request)
484
+ _context = execute_request(_request, name: 'get_signature_key_list')
485
+
486
+ # Validate response against endpoint and global error codes.
487
+ @logger.info("Validating response for get_signature_key_list.")
488
+ if _context.response.status_code == 400
489
+ raise GETSignatureKeyList400ResponseException.new(
490
+ 'Unexpected error in API call. See HTTP response body for details.',
491
+ _context
492
+ )
493
+ end
494
+ validate_response(_context)
495
+
496
+ # Return appropriate response type.
497
+ @logger.info("Returning response for get_signature_key_list.")
498
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
499
+ decoded.map { |element| GETSignatureKeyListResponse.from_hash(element) }
500
+
501
+ rescue Exception => e
502
+ @logger.error(e)
503
+ raise e
504
+ end
505
+ end
506
+ end
507
+ end