kafka_rest_proxy_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +69 -0
  4. data/README.md +129 -0
  5. data/Rakefile +8 -0
  6. data/bin/console +9 -0
  7. data/docs/Body.md +12 -0
  8. data/docs/InlineResponse200.md +10 -0
  9. data/docs/InlineResponse200Offsets.md +11 -0
  10. data/docs/Offset.md +11 -0
  11. data/docs/ProducerApi.md +58 -0
  12. data/docs/ProducerRequest.md +12 -0
  13. data/docs/ProducerResponse.md +10 -0
  14. data/docs/Record.md +10 -0
  15. data/docs/TopicstopicNameRecords.md +10 -0
  16. data/git_push.sh +55 -0
  17. data/kafka_rest_proxy_client.gemspec +33 -0
  18. data/lib/kafka_rest_proxy_client.rb +48 -0
  19. data/lib/kafka_rest_proxy_client/api/producer_api.rb +69 -0
  20. data/lib/kafka_rest_proxy_client/api_client.rb +364 -0
  21. data/lib/kafka_rest_proxy_client/api_error.rb +26 -0
  22. data/lib/kafka_rest_proxy_client/configuration.rb +184 -0
  23. data/lib/kafka_rest_proxy_client/models/body.rb +214 -0
  24. data/lib/kafka_rest_proxy_client/models/inline_response_200.rb +196 -0
  25. data/lib/kafka_rest_proxy_client/models/inline_response_200_offsets.rb +203 -0
  26. data/lib/kafka_rest_proxy_client/models/offset.rb +203 -0
  27. data/lib/kafka_rest_proxy_client/models/producer_request.rb +214 -0
  28. data/lib/kafka_rest_proxy_client/models/producer_response.rb +196 -0
  29. data/lib/kafka_rest_proxy_client/models/record.rb +194 -0
  30. data/lib/kafka_rest_proxy_client/models/topicstopic_name_records.rb +194 -0
  31. data/lib/kafka_rest_proxy_client/version.rb +3 -0
  32. data/spec/api/producer_api_spec.rb +47 -0
  33. data/spec/api_client_spec.rb +225 -0
  34. data/spec/configuration_spec.rb +41 -0
  35. data/spec/models/body_spec.rb +65 -0
  36. data/spec/models/inline_response_200_offsets_spec.rb +59 -0
  37. data/spec/models/inline_response_200_spec.rb +53 -0
  38. data/spec/models/offset_spec.rb +59 -0
  39. data/spec/models/producer_request_spec.rb +65 -0
  40. data/spec/models/producer_response_spec.rb +53 -0
  41. data/spec/models/record_spec.rb +53 -0
  42. data/spec/models/topicstopic_name_records_spec.rb +53 -0
  43. data/spec/spec_helper.rb +110 -0
  44. data/swagger.yml +170 -0
  45. metadata +279 -0
@@ -0,0 +1,26 @@
1
+ module KafkaProxyRestClient
2
+ class ApiError < StandardError
3
+ attr_reader :code, :response_headers, :response_body
4
+
5
+ # Usage examples:
6
+ # ApiError.new
7
+ # ApiError.new("message")
8
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
9
+ # ApiError.new(:code => 404, :message => "Not Found")
10
+ def initialize(arg = nil)
11
+ if arg.is_a? Hash
12
+ if arg.key?(:message) || arg.key?('message')
13
+ super(arg[:message] || arg['message'])
14
+ else
15
+ super arg
16
+ end
17
+
18
+ arg.each do |k, v|
19
+ instance_variable_set "@#{k}", v
20
+ end
21
+ else
22
+ super arg
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,184 @@
1
+ require 'uri'
2
+
3
+ module KafkaProxyRestClient
4
+ class Configuration
5
+ # Defines url scheme
6
+ attr_accessor :scheme
7
+
8
+ # Defines url host
9
+ attr_accessor :host
10
+
11
+ # Defines url base path
12
+ attr_accessor :base_path
13
+
14
+ # Defines API keys used with API Key authentications.
15
+ #
16
+ # @return [Hash] key: parameter name, value: parameter value (API key)
17
+ #
18
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
19
+ # config.api_key['api_key'] = 'xxx'
20
+ attr_accessor :api_key
21
+
22
+ # Defines API key prefixes used with API Key authentications.
23
+ #
24
+ # @return [Hash] key: parameter name, value: API key prefix
25
+ #
26
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
27
+ # config.api_key_prefix['api_key'] = 'Token'
28
+ attr_accessor :api_key_prefix
29
+
30
+ # Defines the username used with HTTP basic authentication.
31
+ #
32
+ # @return [String]
33
+ attr_accessor :username
34
+
35
+ # Defines the password used with HTTP basic authentication.
36
+ #
37
+ # @return [String]
38
+ attr_accessor :password
39
+
40
+ # Defines the access token (Bearer) used with OAuth2.
41
+ attr_accessor :access_token
42
+
43
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
44
+ # details will be logged with `logger.debug` (see the `logger` attribute).
45
+ # Default to false.
46
+ #
47
+ # @return [true, false]
48
+ attr_accessor :debugging
49
+
50
+ # Defines the logger used for debugging.
51
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
52
+ #
53
+ # @return [#debug]
54
+ attr_accessor :logger
55
+
56
+ # Defines the temporary folder to store downloaded files
57
+ # (for API endpoints that have file response).
58
+ # Default to use `Tempfile`.
59
+ #
60
+ # @return [String]
61
+ attr_accessor :temp_folder_path
62
+
63
+ # The time limit for HTTP request in seconds.
64
+ # Default to 0 (never times out).
65
+ attr_accessor :timeout
66
+
67
+ ### TLS/SSL setting
68
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
69
+ # Default to true.
70
+ #
71
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
72
+ #
73
+ # @return [true, false]
74
+ attr_accessor :verify_ssl
75
+
76
+ ### TLS/SSL setting
77
+ # Set this to false to skip verifying SSL host name
78
+ # Default to true.
79
+ #
80
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
81
+ #
82
+ # @return [true, false]
83
+ attr_accessor :verify_ssl_host
84
+
85
+ ### TLS/SSL setting
86
+ # Set this to customize the certificate file to verify the peer.
87
+ #
88
+ # @return [String] the path to the certificate file
89
+ #
90
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
91
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
92
+ attr_accessor :ssl_ca_cert
93
+
94
+ ### TLS/SSL setting
95
+ # Client certificate file (for client certificate)
96
+ attr_accessor :cert_file
97
+
98
+ ### TLS/SSL setting
99
+ # Client private key file (for client certificate)
100
+ attr_accessor :key_file
101
+
102
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
103
+ # Default to nil.
104
+ #
105
+ # @see The params_encoding option of Ethon. Related source code:
106
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
107
+ attr_accessor :params_encoding
108
+
109
+ attr_accessor :inject_format
110
+
111
+ attr_accessor :force_ending_format
112
+
113
+ def initialize
114
+ @scheme = 'https'
115
+ @host = ''
116
+ @base_path = ''
117
+ @api_key = {}
118
+ @api_key_prefix = {}
119
+ @timeout = 0
120
+ @verify_ssl = true
121
+ @verify_ssl_host = true
122
+ @params_encoding = nil
123
+ @cert_file = nil
124
+ @key_file = nil
125
+ @debugging = false
126
+ @inject_format = false
127
+ @force_ending_format = false
128
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
129
+
130
+ yield(self) if block_given?
131
+ end
132
+
133
+ # The default Configuration object.
134
+ def self.default
135
+ @@default ||= Configuration.new
136
+ end
137
+
138
+ def configure
139
+ yield(self) if block_given?
140
+ end
141
+
142
+ def scheme=(scheme)
143
+ # remove :// from scheme
144
+ @scheme = scheme.sub(/:\/\//, '')
145
+ end
146
+
147
+ def host=(host)
148
+ # remove http(s):// and anything after a slash
149
+ @host = host.sub(/https?:\/\//, '').split('/').first
150
+ end
151
+
152
+ def base_path=(base_path)
153
+ # Add leading and trailing slashes to base_path
154
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
155
+ @base_path = "" if @base_path == "/"
156
+ end
157
+
158
+ def base_url
159
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
160
+ URI.encode(url)
161
+ end
162
+
163
+ # Gets API key (with prefix if set).
164
+ # @param [String] param_name the parameter name of API key auth
165
+ def api_key_with_prefix(param_name)
166
+ if @api_key_prefix[param_name]
167
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
168
+ else
169
+ @api_key[param_name]
170
+ end
171
+ end
172
+
173
+ # Gets Basic Auth token string
174
+ def basic_auth_token
175
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
176
+ end
177
+
178
+ # Returns Auth Settings hash for api client.
179
+ def auth_settings
180
+ {
181
+ }
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,214 @@
1
+ require 'date'
2
+
3
+ module KafkaProxyRestClient
4
+
5
+ class Body
6
+ attr_accessor :records
7
+
8
+ attr_accessor :key_schema
9
+
10
+ attr_accessor :key_schema_id
11
+
12
+ attr_accessor :value_schema
13
+
14
+ attr_accessor :value_schema_id
15
+
16
+
17
+ # Attribute mapping from ruby-style variable name to JSON key.
18
+ def self.attribute_map
19
+ {
20
+ :'records' => :'records',
21
+ :'key_schema' => :'key_schema',
22
+ :'key_schema_id' => :'key_schema_id',
23
+ :'value_schema' => :'value_schema',
24
+ :'value_schema_id' => :'value_schema_id'
25
+ }
26
+ end
27
+
28
+ # Attribute type mapping.
29
+ def self.swagger_types
30
+ {
31
+ :'records' => :'Array<TopicstopicNameRecords>',
32
+ :'key_schema' => :'String',
33
+ :'key_schema_id' => :'Integer',
34
+ :'value_schema' => :'String',
35
+ :'value_schema_id' => :'Integer'
36
+ }
37
+ end
38
+
39
+ # Initializes the object
40
+ # @param [Hash] attributes Model attributes in the form of hash
41
+ def initialize(attributes = {})
42
+ return unless attributes.is_a?(Hash)
43
+
44
+ # convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
46
+
47
+ if attributes.has_key?(:'records')
48
+ if (value = attributes[:'records']).is_a?(Array)
49
+ self.records = value
50
+ end
51
+ end
52
+
53
+ if attributes.has_key?(:'key_schema')
54
+ self.key_schema = attributes[:'key_schema']
55
+ end
56
+
57
+ if attributes.has_key?(:'key_schema_id')
58
+ self.key_schema_id = attributes[:'key_schema_id']
59
+ end
60
+
61
+ if attributes.has_key?(:'value_schema')
62
+ self.value_schema = attributes[:'value_schema']
63
+ end
64
+
65
+ if attributes.has_key?(:'value_schema_id')
66
+ self.value_schema_id = attributes[:'value_schema_id']
67
+ end
68
+
69
+ end
70
+
71
+ # Show invalid properties with the reasons. Usually used together with valid?
72
+ # @return Array for valid properies with the reasons
73
+ def list_invalid_properties
74
+ invalid_properties = Array.new
75
+ return invalid_properties
76
+ end
77
+
78
+ # Check to see if the all the properties in the model are valid
79
+ # @return true if the model is valid
80
+ def valid?
81
+ return true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(o)
87
+ return true if self.equal?(o)
88
+ self.class == o.class &&
89
+ records == o.records &&
90
+ key_schema == o.key_schema &&
91
+ key_schema_id == o.key_schema_id &&
92
+ value_schema == o.value_schema &&
93
+ value_schema_id == o.value_schema_id
94
+ end
95
+
96
+ # @see the `==` method
97
+ # @param [Object] Object to be compared
98
+ def eql?(o)
99
+ self == o
100
+ end
101
+
102
+ # Calculates hash code according to all attributes.
103
+ # @return [Fixnum] Hash code
104
+ def hash
105
+ [records, key_schema, key_schema_id, value_schema, value_schema_id].hash
106
+ end
107
+
108
+ # Builds the object from hash
109
+ # @param [Hash] attributes Model attributes in the form of hash
110
+ # @return [Object] Returns the model itself
111
+ def build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ self.class.swagger_types.each_pair do |key, type|
114
+ if type =~ /\AArray<(.*)>/i
115
+ # check to ensure the input is an array given that the the attribute
116
+ # is documented as an array but the input is not
117
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
118
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
119
+ end
120
+ elsif !attributes[self.class.attribute_map[key]].nil?
121
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
122
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
123
+ end
124
+
125
+ self
126
+ end
127
+
128
+ # Deserializes the data based on type
129
+ # @param string type Data type
130
+ # @param string value Value to be deserialized
131
+ # @return [Object] Deserialized data
132
+ def _deserialize(type, value)
133
+ case type.to_sym
134
+ when :DateTime
135
+ DateTime.parse(value)
136
+ when :Date
137
+ Date.parse(value)
138
+ when :String
139
+ value.to_s
140
+ when :Integer
141
+ value.to_i
142
+ when :Float
143
+ value.to_f
144
+ when :BOOLEAN
145
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
146
+ true
147
+ else
148
+ false
149
+ end
150
+ when :Object
151
+ # generic object (usually a Hash), return directly
152
+ value
153
+ when /\AArray<(?<inner_type>.+)>\z/
154
+ inner_type = Regexp.last_match[:inner_type]
155
+ value.map { |v| _deserialize(inner_type, v) }
156
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
157
+ k_type = Regexp.last_match[:k_type]
158
+ v_type = Regexp.last_match[:v_type]
159
+ {}.tap do |hash|
160
+ value.each do |k, v|
161
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
162
+ end
163
+ end
164
+ else # model
165
+ temp_model = KafkaProxyRestClient.const_get(type).new
166
+ temp_model.build_from_hash(value)
167
+ end
168
+ end
169
+
170
+ # Returns the string representation of the object
171
+ # @return [String] String presentation of the object
172
+ def to_s
173
+ to_hash.to_s
174
+ end
175
+
176
+ # to_body is an alias to to_hash (backward compatibility)
177
+ # @return [Hash] Returns the object in the form of hash
178
+ def to_body
179
+ to_hash
180
+ end
181
+
182
+ # Returns the object in the form of hash
183
+ # @return [Hash] Returns the object in the form of hash
184
+ def to_hash
185
+ hash = {}
186
+ self.class.attribute_map.each_pair do |attr, param|
187
+ value = self.send(attr)
188
+ next if value.nil?
189
+ hash[param] = _to_hash(value)
190
+ end
191
+ hash
192
+ end
193
+
194
+ # Outputs non-array value in the form of hash
195
+ # For object, use to_hash. Otherwise, just return the value
196
+ # @param [Object] value Any valid value
197
+ # @return [Hash] Returns the value in the form of hash
198
+ def _to_hash(value)
199
+ if value.is_a?(Array)
200
+ value.compact.map{ |v| _to_hash(v) }
201
+ elsif value.is_a?(Hash)
202
+ {}.tap do |hash|
203
+ value.each { |k, v| hash[k] = _to_hash(v) }
204
+ end
205
+ elsif value.respond_to? :to_hash
206
+ value.to_hash
207
+ else
208
+ value
209
+ end
210
+ end
211
+
212
+ end
213
+
214
+ end
@@ -0,0 +1,196 @@
1
+ require 'date'
2
+
3
+ module KafkaProxyRestClient
4
+
5
+ class InlineResponse200
6
+ attr_accessor :offsets
7
+
8
+ attr_accessor :key_schema_id
9
+
10
+ attr_accessor :value_schema_id
11
+
12
+
13
+ # Attribute mapping from ruby-style variable name to JSON key.
14
+ def self.attribute_map
15
+ {
16
+ :'offsets' => :'offsets',
17
+ :'key_schema_id' => :'key_schema_id',
18
+ :'value_schema_id' => :'value_schema_id'
19
+ }
20
+ end
21
+
22
+ # Attribute type mapping.
23
+ def self.swagger_types
24
+ {
25
+ :'offsets' => :'Array<InlineResponse200Offsets>',
26
+ :'key_schema_id' => :'Integer',
27
+ :'value_schema_id' => :'Integer'
28
+ }
29
+ end
30
+
31
+ # Initializes the object
32
+ # @param [Hash] attributes Model attributes in the form of hash
33
+ def initialize(attributes = {})
34
+ return unless attributes.is_a?(Hash)
35
+
36
+ # convert string to symbol for hash key
37
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
38
+
39
+ if attributes.has_key?(:'offsets')
40
+ if (value = attributes[:'offsets']).is_a?(Array)
41
+ self.offsets = value
42
+ end
43
+ end
44
+
45
+ if attributes.has_key?(:'key_schema_id')
46
+ self.key_schema_id = attributes[:'key_schema_id']
47
+ end
48
+
49
+ if attributes.has_key?(:'value_schema_id')
50
+ self.value_schema_id = attributes[:'value_schema_id']
51
+ end
52
+
53
+ end
54
+
55
+ # Show invalid properties with the reasons. Usually used together with valid?
56
+ # @return Array for valid properies with the reasons
57
+ def list_invalid_properties
58
+ invalid_properties = Array.new
59
+ return invalid_properties
60
+ end
61
+
62
+ # Check to see if the all the properties in the model are valid
63
+ # @return true if the model is valid
64
+ def valid?
65
+ return true
66
+ end
67
+
68
+ # Checks equality by comparing each attribute.
69
+ # @param [Object] Object to be compared
70
+ def ==(o)
71
+ return true if self.equal?(o)
72
+ self.class == o.class &&
73
+ offsets == o.offsets &&
74
+ key_schema_id == o.key_schema_id &&
75
+ value_schema_id == o.value_schema_id
76
+ end
77
+
78
+ # @see the `==` method
79
+ # @param [Object] Object to be compared
80
+ def eql?(o)
81
+ self == o
82
+ end
83
+
84
+ # Calculates hash code according to all attributes.
85
+ # @return [Fixnum] Hash code
86
+ def hash
87
+ [offsets, key_schema_id, value_schema_id].hash
88
+ end
89
+
90
+ # Builds the object from hash
91
+ # @param [Hash] attributes Model attributes in the form of hash
92
+ # @return [Object] Returns the model itself
93
+ def build_from_hash(attributes)
94
+ return nil unless attributes.is_a?(Hash)
95
+ self.class.swagger_types.each_pair do |key, type|
96
+ if type =~ /\AArray<(.*)>/i
97
+ # check to ensure the input is an array given that the the attribute
98
+ # is documented as an array but the input is not
99
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
100
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
101
+ end
102
+ elsif !attributes[self.class.attribute_map[key]].nil?
103
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
104
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
105
+ end
106
+
107
+ self
108
+ end
109
+
110
+ # Deserializes the data based on type
111
+ # @param string type Data type
112
+ # @param string value Value to be deserialized
113
+ # @return [Object] Deserialized data
114
+ def _deserialize(type, value)
115
+ case type.to_sym
116
+ when :DateTime
117
+ DateTime.parse(value)
118
+ when :Date
119
+ Date.parse(value)
120
+ when :String
121
+ value.to_s
122
+ when :Integer
123
+ value.to_i
124
+ when :Float
125
+ value.to_f
126
+ when :BOOLEAN
127
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
128
+ true
129
+ else
130
+ false
131
+ end
132
+ when :Object
133
+ # generic object (usually a Hash), return directly
134
+ value
135
+ when /\AArray<(?<inner_type>.+)>\z/
136
+ inner_type = Regexp.last_match[:inner_type]
137
+ value.map { |v| _deserialize(inner_type, v) }
138
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
139
+ k_type = Regexp.last_match[:k_type]
140
+ v_type = Regexp.last_match[:v_type]
141
+ {}.tap do |hash|
142
+ value.each do |k, v|
143
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
144
+ end
145
+ end
146
+ else # model
147
+ temp_model = KafkaProxyRestClient.const_get(type).new
148
+ temp_model.build_from_hash(value)
149
+ end
150
+ end
151
+
152
+ # Returns the string representation of the object
153
+ # @return [String] String presentation of the object
154
+ def to_s
155
+ to_hash.to_s
156
+ end
157
+
158
+ # to_body is an alias to to_hash (backward compatibility)
159
+ # @return [Hash] Returns the object in the form of hash
160
+ def to_body
161
+ to_hash
162
+ end
163
+
164
+ # Returns the object in the form of hash
165
+ # @return [Hash] Returns the object in the form of hash
166
+ def to_hash
167
+ hash = {}
168
+ self.class.attribute_map.each_pair do |attr, param|
169
+ value = self.send(attr)
170
+ next if value.nil?
171
+ hash[param] = _to_hash(value)
172
+ end
173
+ hash
174
+ end
175
+
176
+ # Outputs non-array value in the form of hash
177
+ # For object, use to_hash. Otherwise, just return the value
178
+ # @param [Object] value Any valid value
179
+ # @return [Hash] Returns the value in the form of hash
180
+ def _to_hash(value)
181
+ if value.is_a?(Array)
182
+ value.compact.map{ |v| _to_hash(v) }
183
+ elsif value.is_a?(Hash)
184
+ {}.tap do |hash|
185
+ value.each { |k, v| hash[k] = _to_hash(v) }
186
+ end
187
+ elsif value.respond_to? :to_hash
188
+ value.to_hash
189
+ else
190
+ value
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ end