blueprint_ruby_client 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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +65 -0
  4. data/README.md +152 -0
  5. data/blueprint_ruby_client.gemspec +31 -0
  6. data/config.json +13 -0
  7. data/docs/Asset.md +9 -0
  8. data/docs/AssetBody.md +9 -0
  9. data/docs/AssetResultSet.md +9 -0
  10. data/docs/AssetsApi.md +376 -0
  11. data/docs/Error.md +10 -0
  12. data/docs/Errors.md +8 -0
  13. data/docs/HierarchyApi.md +745 -0
  14. data/docs/Links.md +10 -0
  15. data/docs/Meta.md +10 -0
  16. data/docs/Namespace.md +9 -0
  17. data/docs/NamespaceRelationship.md +8 -0
  18. data/docs/Node.md +11 -0
  19. data/docs/NodeAttributes.md +13 -0
  20. data/docs/NodeBody.md +9 -0
  21. data/docs/NodeRelationship.md +10 -0
  22. data/docs/NodeRelationships.md +10 -0
  23. data/docs/NodeResultSet.md +10 -0
  24. data/generate.sh +7 -0
  25. data/git_push.sh +52 -0
  26. data/lib/blueprint_ruby_client/api/assets_api.rb +598 -0
  27. data/lib/blueprint_ruby_client/api/hierarchy_api.rb +1174 -0
  28. data/lib/blueprint_ruby_client/api_client.rb +365 -0
  29. data/lib/blueprint_ruby_client/api_error.rb +36 -0
  30. data/lib/blueprint_ruby_client/configuration.rb +170 -0
  31. data/lib/blueprint_ruby_client/models/asset.rb +242 -0
  32. data/lib/blueprint_ruby_client/models/asset_body.rb +237 -0
  33. data/lib/blueprint_ruby_client/models/asset_result_set.rb +234 -0
  34. data/lib/blueprint_ruby_client/models/error.rb +267 -0
  35. data/lib/blueprint_ruby_client/models/errors.rb +209 -0
  36. data/lib/blueprint_ruby_client/models/links.rb +257 -0
  37. data/lib/blueprint_ruby_client/models/meta.rb +260 -0
  38. data/lib/blueprint_ruby_client/models/namespace.rb +242 -0
  39. data/lib/blueprint_ruby_client/models/namespace_relationship.rb +207 -0
  40. data/lib/blueprint_ruby_client/models/node.rb +293 -0
  41. data/lib/blueprint_ruby_client/models/node_attributes.rb +338 -0
  42. data/lib/blueprint_ruby_client/models/node_body.rb +237 -0
  43. data/lib/blueprint_ruby_client/models/node_relationship.rb +259 -0
  44. data/lib/blueprint_ruby_client/models/node_relationships.rb +257 -0
  45. data/lib/blueprint_ruby_client/models/node_result_set.rb +261 -0
  46. data/lib/blueprint_ruby_client/version.rb +15 -0
  47. data/lib/blueprint_ruby_client.rb +56 -0
  48. data/spec/api/assets_api_spec.rb +150 -0
  49. data/spec/api/hierarchy_api_spec.rb +266 -0
  50. data/spec/models/asset_body_spec.rb +56 -0
  51. data/spec/models/asset_result_set_spec.rb +56 -0
  52. data/spec/models/asset_spec.rb +56 -0
  53. data/spec/models/error_spec.rb +66 -0
  54. data/spec/models/errors_spec.rb +46 -0
  55. data/spec/models/links_spec.rb +66 -0
  56. data/spec/models/meta_spec.rb +66 -0
  57. data/spec/models/namespace_relationship_spec.rb +46 -0
  58. data/spec/models/namespace_spec.rb +56 -0
  59. data/spec/models/node_attributes_spec.rb +96 -0
  60. data/spec/models/node_body_spec.rb +56 -0
  61. data/spec/models/node_relationship_spec.rb +66 -0
  62. data/spec/models/node_relationships_spec.rb +66 -0
  63. data/spec/models/node_result_set_spec.rb +66 -0
  64. data/spec/models/node_spec.rb +76 -0
  65. data/swagger-codegen-cli.jar +0 -0
  66. data/templates/Gemfile.mustache +4 -0
  67. data/templates/README.mustache +139 -0
  68. data/templates/api.mustache +135 -0
  69. data/templates/api_client.mustache +357 -0
  70. data/templates/api_doc.mustache +79 -0
  71. data/templates/api_error.mustache +28 -0
  72. data/templates/api_info.mustache +18 -0
  73. data/templates/api_test.mustache +47 -0
  74. data/templates/base_object.mustache +103 -0
  75. data/templates/configuration.mustache +192 -0
  76. data/templates/gem.mustache +40 -0
  77. data/templates/gemspec.mustache +31 -0
  78. data/templates/gitignore.mustache +40 -0
  79. data/templates/model.mustache +242 -0
  80. data/templates/model_doc.mustache +9 -0
  81. data/templates/model_test.mustache +40 -0
  82. data/templates/version.mustache +7 -0
  83. metadata +322 -0
@@ -0,0 +1,357 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ require 'date'
6
+ require 'json'
7
+ require 'logger'
8
+ require 'tempfile'
9
+ require 'typhoeus'
10
+ require 'uri'
11
+
12
+ module {{moduleName}}
13
+ class ApiClient
14
+ # The Configuration object holding settings to be used in the API client.
15
+ attr_accessor :config
16
+
17
+ # Defines the headers to be used in HTTP requests of all API calls by default.
18
+ #
19
+ # @return [Hash]
20
+ attr_accessor :default_headers
21
+
22
+ # Initializes the ApiClient
23
+ # @option config [Configuration] Configuraiton for initializing the object, default to Configuration.default
24
+ def initialize(config = Configuration.default)
25
+ @config = config
26
+ @user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}talis-blueprint-client/#{VERSION} ruby/#{RUBY_VERSION}{{/httpUserAgent}}"
27
+ @default_headers = {
28
+ 'Content-Type' => "application/json",
29
+ 'User-Agent' => @user_agent
30
+ }
31
+ end
32
+
33
+ def self.default
34
+ @@default ||= ApiClient.new
35
+ end
36
+
37
+ # Call an API with given options.
38
+ #
39
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
40
+ # the data deserialized from response body (could be nil), response status code and response headers.
41
+ def call_api(http_method, path, opts = {})
42
+ request = build_request(http_method, path, opts)
43
+ response = request.run
44
+
45
+ if @config.debugging
46
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
47
+ end
48
+
49
+ unless response.success?
50
+ fail ApiError.new(:code => response.code,
51
+ :response_headers => response.headers,
52
+ :response_body => response.body),
53
+ response.status_message
54
+ end
55
+
56
+ if opts[:return_type]
57
+ data = deserialize(response, opts[:return_type])
58
+ else
59
+ data = nil
60
+ end
61
+ return data, response.code, response.headers
62
+ end
63
+
64
+ # Builds the HTTP request
65
+ #
66
+ # @param [String] http_method HTTP method/verb (e.g. POST)
67
+ # @param [String] path URL path (e.g. /account/new)
68
+ # @option opts [Hash] :header_params Header parameters
69
+ # @option opts [Hash] :query_params Query parameters
70
+ # @option opts [Hash] :form_params Query parameters
71
+ # @option opts [Object] :body HTTP body (JSON/XML)
72
+ # @return [Typhoeus::Request] A Typhoeus Request
73
+ def build_request(http_method, path, opts = {})
74
+ url = build_request_url(path)
75
+ http_method = http_method.to_sym.downcase
76
+
77
+ header_params = @default_headers.merge(opts[:header_params] || {})
78
+ query_params = opts[:query_params] || {}
79
+ form_params = opts[:form_params] || {}
80
+
81
+ {{#hasAuthMethods}}
82
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
83
+ {{/hasAuthMethods}}
84
+
85
+ req_opts = {
86
+ :method => http_method,
87
+ :headers => header_params,
88
+ :params => query_params,
89
+ :timeout => @config.timeout,
90
+ :ssl_verifypeer => @config.verify_ssl,
91
+ :sslcert => @config.cert_file,
92
+ :sslkey => @config.key_file,
93
+ :verbose => @config.debugging
94
+ }
95
+
96
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
97
+
98
+ if [:post, :patch, :put, :delete].include?(http_method)
99
+ req_body = build_request_body(header_params, form_params, opts[:body])
100
+ req_opts.update :body => req_body
101
+ if @config.debugging
102
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
103
+ end
104
+ end
105
+
106
+ Typhoeus::Request.new(url, req_opts)
107
+ end
108
+
109
+ # Check if the given MIME is a JSON MIME.
110
+ # JSON MIME examples:
111
+ # application/json
112
+ # application/vnd.api+json
113
+ # application/json; charset=UTF8
114
+ # APPLICATION/JSON
115
+ # @param [String] mime MIME
116
+ # @return [Boolean] True if the MIME is applicaton/json
117
+ def json_mime?(mime)
118
+ !(mime =~ /\Aapplication\/(vnd\.api\+)?json(;.*)?\z/i).nil?
119
+ end
120
+
121
+ # Deserialize the response to the given return type.
122
+ #
123
+ # @param [Response] response HTTP response
124
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
125
+ def deserialize(response, return_type)
126
+ body = response.body
127
+ return nil if body.nil? || body.empty?
128
+
129
+ # return response body directly for String return type
130
+ return body if return_type == 'String'
131
+
132
+ # handle file downloading - save response body into a tmp file and return the File instance
133
+ return download_file(response) if return_type == 'File'
134
+
135
+ # ensuring a default content type
136
+ content_type = response.headers['Content-Type'] || 'application/json'
137
+
138
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
139
+
140
+ begin
141
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
142
+ rescue JSON::ParserError => e
143
+ if %w(String Date DateTime).include?(return_type)
144
+ data = body
145
+ else
146
+ raise e
147
+ end
148
+ end
149
+
150
+ convert_to_type data, return_type
151
+ end
152
+
153
+ # Convert data to the given return type.
154
+ # @param [Object] data Data to be converted
155
+ # @param [String] return_type Return type
156
+ # @return [Mixed] Data in a particular type
157
+ def convert_to_type(data, return_type)
158
+ return nil if data.nil?
159
+ case return_type
160
+ when 'String'
161
+ data.to_s
162
+ when 'Integer'
163
+ data.to_i
164
+ when 'Float'
165
+ data.to_f
166
+ when 'BOOLEAN'
167
+ data == true
168
+ when 'DateTime'
169
+ # parse date time (expecting ISO 8601 format)
170
+ DateTime.parse data
171
+ when 'Date'
172
+ # parse date time (expecting ISO 8601 format)
173
+ Date.parse data
174
+ when 'Object'
175
+ # generic object (usually a Hash), return directly
176
+ data
177
+ when /\AArray<(.+)>\z/
178
+ # e.g. Array<Pet>
179
+ sub_type = $1
180
+ data.map {|item| convert_to_type(item, sub_type) }
181
+ when /\AHash\<String, (.+)\>\z/
182
+ # e.g. Hash<String, Integer>
183
+ sub_type = $1
184
+ {}.tap do |hash|
185
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
186
+ end
187
+ else
188
+ # models, e.g. Pet
189
+ {{moduleName}}.const_get(return_type).new.tap do |model|
190
+ model.build_from_hash data
191
+ end
192
+ end
193
+ end
194
+
195
+ # Save response body into a file in (the defined) temporary folder, using the filename
196
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
197
+ #
198
+ # @see Configuration#temp_folder_path
199
+ # @return [Tempfile] the file downloaded
200
+ def download_file(response)
201
+ content_disposition = response.headers['Content-Disposition']
202
+ if content_disposition
203
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
204
+ prefix = sanitize_filename(filename)
205
+ else
206
+ prefix = 'download-'
207
+ end
208
+ prefix = prefix + '-' unless prefix.end_with?('-')
209
+
210
+ tempfile = nil
211
+ encoding = response.body.encoding
212
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
213
+ file.write(response.body)
214
+ tempfile = file
215
+ end
216
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
217
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
218
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
219
+ "explicitly with `tempfile.delete`"
220
+ tempfile
221
+ end
222
+
223
+ # Sanitize filename by removing path.
224
+ # e.g. ../../sun.gif becomes sun.gif
225
+ #
226
+ # @param [String] filename the filename to be sanitized
227
+ # @return [String] the sanitized filename
228
+ def sanitize_filename(filename)
229
+ filename.gsub(/.*[\/\\]/, '')
230
+ end
231
+
232
+ def build_request_url(path)
233
+ # Add leading and trailing slashes to path
234
+ path = "/#{path}".gsub(/\/+/, '/')
235
+ URI.encode(@config.base_url + path)
236
+ end
237
+
238
+ # Builds the HTTP request body
239
+ #
240
+ # @param [Hash] header_params Header parameters
241
+ # @param [Hash] form_params Query parameters
242
+ # @param [Object] body HTTP body (JSON/XML)
243
+ # @return [String] HTTP body data in the form of string
244
+ def build_request_body(header_params, form_params, body)
245
+ # http form
246
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
247
+ header_params['Content-Type'] == 'multipart/form-data'
248
+ data = {}
249
+ form_params.each do |key, value|
250
+ case value
251
+ when File, Array, nil
252
+ # let typhoeus handle File, Array and nil parameters
253
+ data[key] = value
254
+ else
255
+ data[key] = value.to_s
256
+ end
257
+ end
258
+ elsif body
259
+ data = body.is_a?(String) ? body : body.to_json
260
+ else
261
+ data = nil
262
+ end
263
+ data
264
+ end
265
+
266
+ # Update hearder and query params based on authentication settings.
267
+ #
268
+ # @param [Hash] header_params Header parameters
269
+ # @param [Hash] form_params Query parameters
270
+ # @param [String] auth_names Authentication scheme name
271
+ def update_params_for_auth!(header_params, query_params, auth_names)
272
+ Array(auth_names).each do |auth_name|
273
+ auth_setting = @config.auth_settings[auth_name]
274
+ next unless auth_setting
275
+ case auth_setting[:in]
276
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
277
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
278
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
279
+ end
280
+ end
281
+ end
282
+
283
+ # Sets user agent in HTTP header
284
+ #
285
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
286
+ def user_agent=(user_agent)
287
+ @user_agent = user_agent
288
+ @default_headers['User-Agent'] = @user_agent
289
+ end
290
+
291
+ # Return Accept header based on an array of accepts provided.
292
+ # @param [Array] accepts array for Accept
293
+ # @return [String] the Accept header (e.g. application/json)
294
+ def select_header_accept(accepts)
295
+ return nil if accepts.nil? || accepts.empty?
296
+ # use JSON when present, otherwise use all of the provided
297
+ json_accept = accepts.find { |s| json_mime?(s) }
298
+ return json_accept || accepts.join(',')
299
+ end
300
+
301
+ # Return Content-Type header based on an array of content types provided.
302
+ # @param [Array] content_types array for Content-Type
303
+ # @return [String] the Content-Type header (e.g. application/json)
304
+ def select_header_content_type(content_types)
305
+ # use application/json by default
306
+ return 'application/json' if content_types.nil? || content_types.empty?
307
+ # use JSON when present, otherwise use the first one
308
+ json_content_type = content_types.find { |s| json_mime?(s) }
309
+ return json_content_type || content_types.first
310
+ end
311
+
312
+ # Convert object (array, hash, object, etc) to JSON string.
313
+ # @param [Object] model object to be converted into JSON string
314
+ # @return [String] JSON string representation of the object
315
+ def object_to_http_body(model)
316
+ return model if model.nil? || model.is_a?(String)
317
+ local_body = nil
318
+ if model.is_a?(Array)
319
+ local_body = model.map{|m| object_to_hash(m) }
320
+ else
321
+ local_body = object_to_hash(model)
322
+ end
323
+ local_body.to_json
324
+ end
325
+
326
+ # Convert object(non-array) to hash.
327
+ # @param [Object] obj object to be converted into JSON string
328
+ # @return [String] JSON string representation of the object
329
+ def object_to_hash(obj)
330
+ if obj.respond_to?(:to_hash)
331
+ obj.to_hash
332
+ else
333
+ obj
334
+ end
335
+ end
336
+
337
+ # Build parameter value according to the given collection format.
338
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
339
+ def build_collection_param(param, collection_format)
340
+ case collection_format
341
+ when :csv
342
+ param.join(',')
343
+ when :ssv
344
+ param.join(' ')
345
+ when :tsv
346
+ param.join("\t")
347
+ when :pipes
348
+ param.join('|')
349
+ when :multi
350
+ # return the array directly as typhoeus will handle it as expected
351
+ param
352
+ else
353
+ fail "unknown collection format: #{collection_format.inspect}"
354
+ end
355
+ end
356
+ end
357
+ end
@@ -0,0 +1,79 @@
1
+ # {{moduleName}}::{{classname}}{{#description}}
2
+ {{description}}{{/description}}
3
+
4
+ All URIs are relative to *{{basePath}}*
5
+
6
+ Method | HTTP request | Description
7
+ ------------- | ------------- | -------------
8
+ {{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
9
+ {{/operation}}{{/operations}}
10
+
11
+ {{#operations}}
12
+ {{#operation}}
13
+ # **{{operationId}}**
14
+ > {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}){{/hasParams}}
15
+
16
+ {{{summary}}}{{#notes}}
17
+
18
+ {{{notes}}}{{/notes}}
19
+
20
+ ### Example
21
+ ```ruby
22
+ # load the gem
23
+ require '{{{gemName}}}'
24
+ {{#hasAuthMethods}}
25
+ # setup authorization
26
+ {{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
27
+ # Configure HTTP basic authorization: {{{name}}}
28
+ config.username = 'YOUR USERNAME'
29
+ config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
30
+ # Configure API key authorization: {{{name}}}
31
+ config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
32
+ # Uncomment the following line to set a prefix for the API key, e.g. 'BEARER' (defaults to nil)
33
+ #config.api_key_prefix['{{{keyParamName}}}'] = 'BEARER'{{/isApiKey}}{{#isOAuth}}
34
+ # Configure OAuth2 access token for authorization: {{{name}}}
35
+ config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
36
+ {{/authMethods}}end
37
+ {{/hasAuthMethods}}
38
+
39
+ api_instance = {{{moduleName}}}::{{{classname}}}.new{{#hasParams}}
40
+ {{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}}
41
+ {{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}}
42
+ {{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}}
43
+ opts = { {{#allParams}}{{^required}}
44
+ {{{paramName}}}: {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} # {{{dataType}}} | {{{description}}}{{/required}}{{/allParams}}
45
+ }{{/hasOptionalParams}}{{/hasParams}}
46
+
47
+ begin
48
+ {{#summary}} #{{{.}}}
49
+ {{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}){{/hasParams}}{{#returnType}}
50
+ p result{{/returnType}}
51
+ rescue {{{moduleName}}}::ApiError => e
52
+ puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}"
53
+ end
54
+ ```
55
+
56
+ ### Parameters
57
+ {{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
58
+ Name | Type | Description | Notes
59
+ ------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
60
+ {{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
61
+ {{/allParams}}
62
+
63
+ ### Return type
64
+
65
+ {{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil (empty response body){{/returnType}}
66
+
67
+ ### Authorization
68
+
69
+ {{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
70
+
71
+ ### HTTP request headers
72
+
73
+ - **Content-Type**: {{#consumes}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
74
+ - **Accept**: {{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
75
+
76
+
77
+
78
+ {{/operation}}
79
+ {{/operations}}
@@ -0,0 +1,28 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ module {{moduleName}}
6
+ class ApiError < StandardError
7
+ attr_reader :code, :response_headers, :response_body
8
+
9
+ # Usage examples:
10
+ # ApiError.new
11
+ # ApiError.new("message")
12
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
13
+ # ApiError.new(:code => 404, :message => "Not Found")
14
+ def initialize(arg = nil)
15
+ if arg.is_a? Hash
16
+ arg.each do |k, v|
17
+ if k.to_s == 'message'
18
+ super v
19
+ else
20
+ instance_variable_set "@#{k}", v
21
+ end
22
+ end
23
+ else
24
+ super arg
25
+ end
26
+ end
27
+ end
28
+ end