pinch-api 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3847478d602a0b7ba7d315279b6501e46dbf05fc
4
+ data.tar.gz: 7fa3b4f0e62309c6cd2dd48179c609f1ab9058db
5
+ SHA512:
6
+ metadata.gz: 6025eea1563e0011bd82289a803965b43ec8f56de85d7dcb62b73722d6c2bf6f922ad361cccfa5a84407e3e7ffb78099b284d271eec84c355c5c86b45954f7c2
7
+ data.tar.gz: c3ea6842853b29a0bfe2a79920233a6bfc108a9f208dd6c9708b72775cad4df8c7421eaace36272a0f7ead67e614ba3911d9a8e881321b1b97cfe94465275723
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2016 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
@@ -0,0 +1,48 @@
1
+ Pinch
2
+ =================
3
+ This API SDK was automatically generated by APIMATIC v2.0
4
+
5
+ How To Configure:
6
+ =================
7
+ The generated code might need to be configured with your API credentials. To do that,
8
+ open the file "configuration.rb" and edit it's contents.
9
+
10
+ Alternatively, you can modify the Configuration parameters at run-time through the following
11
+ ```
12
+ Pinch::Configuration.your_paramater=YOUR_VALUE
13
+ ```
14
+
15
+ How To Build:
16
+ =============
17
+ The generated code uses a Ruby gem namely 'unirest'. The reference to this gem is
18
+ already added in the gemspec. Therefore, you will need internet access to resolve
19
+ this dependency.
20
+
21
+ How To Use:
22
+ ===========
23
+ The generated code can be used to build gem, which can then be distributed online.
24
+ Otherwise, you can include the generated code in your project to use directly.
25
+
26
+ Use the following steps to build a gem and use locally
27
+
28
+ 1. Run the build command
29
+ ```
30
+ gem build pinch.gemspec
31
+ ```
32
+
33
+ 2. Run the install command
34
+ ```
35
+ gem install ./pinch-1.0.gem
36
+ ```
37
+
38
+ 3. In your Gemfile add this line
39
+ ```
40
+ gem 'pinch', '~> 1.0'
41
+ ```
42
+
43
+ 4. Now create an instance and use the instance methods, like following.
44
+
45
+ ```
46
+ ctl = Pinch::WebhookTypeController.new params
47
+ ctl.list params
48
+ ```
@@ -0,0 +1,24 @@
1
+ # This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'unirest'
5
+
6
+ # APIMATIC Helper Files
7
+ require_relative 'pinch/api_helper.rb'
8
+ require_relative 'pinch/api_exception.rb'
9
+ require_relative 'pinch/configuration.rb'
10
+ require_relative 'pinch/pinch_client.rb'
11
+ require_relative 'pinch/custom_auth_utility.rb'
12
+
13
+ # Controllers
14
+ require_relative 'pinch/controllers/webhook_type_controller.rb'
15
+ require_relative 'pinch/controllers/webhook_controller.rb'
16
+ require_relative 'pinch/controllers/ticket_controller.rb'
17
+
18
+ # Models
19
+ require_relative 'pinch/models/webhook_type.rb'
20
+ require_relative 'pinch/models/webhook.rb'
21
+ require_relative 'pinch/models/ticket.rb'
22
+ require_relative 'pinch/models/person.rb'
23
+ require_relative 'pinch/models/building.rb'
24
+ require_relative 'pinch/models/unit.rb'
@@ -0,0 +1,21 @@
1
+ # This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
2
+
3
+ module Pinch
4
+ class APIException < StandardError
5
+ # value store
6
+ attr_reader :response_code
7
+
8
+ # value store
9
+ attr_reader :response_body
10
+
11
+ # The HTTP response code from the API request
12
+ # @param [String] reason the reason for raising an exception
13
+ # @param [Numeric] response_code the HTTP response code from the API request
14
+ # @param [Object] response_body the HTTP unprased response from the API request
15
+ def initialize(reason, response_code, response_body)
16
+ super(reason)
17
+ @response_code = response_code
18
+ @response_body = response_body
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,140 @@
1
+ # This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
2
+
3
+ module Pinch
4
+ class APIHelper
5
+ # Replaces template parameters in the given url
6
+ # @param [String] The query string builder to replace the template parameters
7
+ # @param [Array] The parameters to replace in the url
8
+ def self.append_url_with_template_parameters(query_builder, parameters)
9
+ # perform parameter validation
10
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.is_a? String
11
+
12
+ # return if there are no parameters to replace
13
+ if parameters.nil?
14
+ query_builder
15
+ else
16
+ # iterate and append parameters
17
+ parameters.each do |key, value|
18
+ replace_value = ''
19
+
20
+ if value.nil?
21
+ replace_value = ''
22
+ elsif value.is_a? Enumerable
23
+ replace_value = value.join('/')
24
+ else
25
+ replace_value = value.to_s
26
+ end
27
+
28
+ # find the template parameter and replace it with its value
29
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
30
+ end
31
+ end
32
+ query_builder
33
+ end
34
+
35
+ # Appends the given set of parameters to the given query string
36
+ # @param [String] The query string builder to replace the template parameters
37
+ # @param [Array] The parameters to append
38
+ def self.append_url_with_query_parameters(query_builder, parameters)
39
+ # perform parameter validation
40
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.is_a? String
41
+
42
+ # return if there are no parameters to replace
43
+ if parameters.nil?
44
+ query_builder
45
+ else
46
+ # remove any nil values
47
+ parameters = parameters.reject { |_key, value| value.nil? }
48
+
49
+ # does the query string already has parameters
50
+ has_params = query_builder.include? '?'
51
+ separator = has_params ? '&' : '?'
52
+
53
+ # append query with separator and parameters
54
+ query_builder << separator << URI.encode_www_form(parameters)
55
+ end
56
+ end
57
+
58
+ # Validates and processes the given Url
59
+ # @param [String] The given Url to process
60
+ # @return [String] Pre-processed Url as string
61
+ def self.clean_url(url)
62
+ # perform parameter validation
63
+ raise ArgumentError, 'Invalid Url.' unless url.is_a? String
64
+
65
+ # ensure that the urls are absolute
66
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
67
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
68
+
69
+ # get the http protocol match
70
+ protocol = matches[1]
71
+
72
+ # check if parameters exist
73
+ index = url.index('?')
74
+
75
+ # remove redundant forward slashes
76
+ query = url[protocol.length...(index != nil ? index : url.length)]
77
+ query.gsub!(%r{\/\/+}, '/')
78
+
79
+ # get the parameters
80
+ parameters = index != nil ? url[url.index('?')...url.length] : ""
81
+
82
+ # return processed url
83
+ protocol + query + parameters
84
+ end
85
+
86
+ # Form encodes a hash of parameters.
87
+ # @param [Hash] The hash of parameters to encode.
88
+ # @return [Hash] A hash with the same parameters form encoded.
89
+ def self.form_encode_parameters(form_parameters)
90
+ encoded = Hash.new
91
+ form_parameters.each do |key, value|
92
+ encoded.merge!(APIHelper.form_encode value, key)
93
+ end
94
+ encoded
95
+ end
96
+
97
+ # Form encodes an object.
98
+ # @param [Dynamic] An object to form encode.
99
+ # @param [String] The name of the object.
100
+ # @return [Hash] A form encoded representation of the object in the form of a hash.
101
+ def self.form_encode(obj, instance_name)
102
+ retval = Hash.new
103
+
104
+ # If this is a structure, resolve it's field names.
105
+ if obj.respond_to? :key_map
106
+ obj = obj.key_map
107
+ end
108
+
109
+ # Create a form encoded hash for this object.
110
+ if obj == nil
111
+ nil
112
+ elsif obj.is_a? Array
113
+ obj.each_with_index do |value, index|
114
+ retval.merge!(APIHelper.form_encode(value, instance_name + "[" + index.to_s + "]"))
115
+ end
116
+ elsif obj.is_a? Hash
117
+ obj.each do |key, value|
118
+ retval.merge!(APIHelper.form_encode(value, instance_name + "[" + key + "]"))
119
+ end
120
+ else
121
+ retval[instance_name] = obj
122
+ end
123
+ retval
124
+ end
125
+ end
126
+ end
127
+
128
+ # extend types to support to_bool
129
+ module ToBoolean
130
+ def to_bool
131
+ return true if self == true || self.to_s.strip =~ /^(true|yes|y|1)$/i
132
+ return false
133
+ end
134
+ end
135
+
136
+ class NilClass; include ToBoolean; end
137
+ class TrueClass; include ToBoolean; end
138
+ class FalseClass; include ToBoolean; end
139
+ class Numeric; include ToBoolean; end
140
+ class String; include ToBoolean; end
@@ -0,0 +1,23 @@
1
+ # This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
2
+
3
+ module Pinch
4
+ class Configuration
5
+ # The base Uri for API calls
6
+ @base_uri = 'https://api-company.inchbase.com/api/v1'
7
+
8
+ # Your api key
9
+ @x_api_token = TODO: Replace
10
+
11
+ # Your registered email
12
+ @x_api_email = TODO: Replace
13
+
14
+ # create the getters and setters
15
+ class << self
16
+ attr_accessor :base_uri
17
+ attr_accessor :x_api_token
18
+ attr_accessor :x_api_email
19
+ attr_accessor :x_api_token
20
+ attr_accessor :x_api_email
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,537 @@
1
+ # This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
2
+
3
+ module Pinch
4
+ class TicketController
5
+ @@instance = TicketController.new
6
+ # Singleton instance of the controller class
7
+ def self.instance
8
+ @@instance
9
+ end
10
+
11
+ # List all the opened tickets of every clients you are working for
12
+ # @return List of Ticket response from the API call
13
+ def list
14
+ # the base uri for api requests
15
+ _query_builder = Configuration.base_uri.dup
16
+
17
+ # prepare query string for API call
18
+ _query_builder << '/tickets'
19
+
20
+ # validate and preprocess url
21
+ _query_url = APIHelper.clean_url _query_builder
22
+
23
+ # prepare headers
24
+ _headers = {
25
+ 'user-agent' => 'APIMATIC 2.0',
26
+ 'accept' => 'application/json',
27
+ 'X-API-TOKEN' => Configuration.x_api_token,
28
+ 'X-API-EMAIL' => Configuration.x_api_email
29
+ }
30
+
31
+ # append custom auth authorization
32
+ CustomAuthUtility.append_custom_auth_params _headers
33
+
34
+ # invoke the API call request to fetch the response
35
+ _response = Unirest.get _query_url, headers: _headers
36
+
37
+ # Error handling using HTTP status codes
38
+ if _response.code == 401
39
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
40
+ elsif _response.code == 400
41
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
42
+ elsif _response.code == 404
43
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
44
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
45
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
46
+ end
47
+
48
+ # Try to cast response to list of desired type
49
+ if _response.body.instance_of? Array
50
+ value = Array.new
51
+ _response.body.each do |item|
52
+ begin
53
+ value << (Ticket.from_hash(item))
54
+ rescue Exception
55
+ raise APIException.new "Invalid JSON returned.", _response.code, _response.body
56
+ end
57
+ end
58
+ value
59
+ end
60
+ end
61
+
62
+ # This method returns no result but the status code tells you if the operation succedded
63
+ # @param [String] ticket_id Required parameter: TODO: type description here
64
+ # @return String response from the API call
65
+ def accept_intervention(ticket_id)
66
+
67
+ # Validate required parameters
68
+ if ticket_id == nil
69
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
70
+ end
71
+
72
+ # the base uri for api requests
73
+ _query_builder = Configuration.base_uri.dup
74
+
75
+ # prepare query string for API call
76
+ _query_builder << '/tickets/{ticket_id}/accept'
77
+
78
+ # process optional query parameters
79
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
80
+ 'ticket_id' => ticket_id
81
+ }
82
+
83
+ # validate and preprocess url
84
+ _query_url = APIHelper.clean_url _query_builder
85
+
86
+ # prepare headers
87
+ _headers = {
88
+ 'user-agent' => 'APIMATIC 2.0',
89
+ 'X-API-TOKEN' => Configuration.x_api_token,
90
+ 'X-API-EMAIL' => Configuration.x_api_email
91
+ }
92
+
93
+ # append custom auth authorization
94
+ CustomAuthUtility.append_custom_auth_params _headers
95
+
96
+ # invoke the API call request to fetch the response
97
+ _response = Unirest.post _query_url, headers: _headers
98
+
99
+ # Error handling using HTTP status codes
100
+ if _response.code == 401
101
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
102
+ elsif _response.code == 400
103
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
104
+ elsif _response.code == 404
105
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
106
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
107
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
108
+ end
109
+
110
+ # Return appropriate type
111
+ _response.body
112
+ end
113
+
114
+ # TODO: type endpoint description here
115
+ # @param [DateTime] intervention_date Required parameter: TODO: type description here
116
+ # @param [String] ticket_id Required parameter: TODO: type description here
117
+ # @return String response from the API call
118
+ def set_intervention_date(intervention_date,
119
+ ticket_id)
120
+
121
+ # Validate required parameters
122
+ if intervention_date == nil
123
+ raise ArgumentError.new "Required parameter 'intervention_date' cannot be nil."
124
+ elsif ticket_id == nil
125
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
126
+ end
127
+
128
+ # the base uri for api requests
129
+ _query_builder = Configuration.base_uri.dup
130
+
131
+ # prepare query string for API call
132
+ _query_builder << '/tickets/{ticket_id}/set_intervention_date'
133
+
134
+ # process optional query parameters
135
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
136
+ 'ticket_id' => ticket_id
137
+ }
138
+
139
+ # validate and preprocess url
140
+ _query_url = APIHelper.clean_url _query_builder
141
+
142
+ # prepare headers
143
+ _headers = {
144
+ 'user-agent' => 'APIMATIC 2.0',
145
+ 'X-API-TOKEN' => Configuration.x_api_token,
146
+ 'X-API-EMAIL' => Configuration.x_api_email
147
+ }
148
+
149
+ # append custom auth authorization
150
+ CustomAuthUtility.append_custom_auth_params _headers
151
+
152
+ # prepare parameters
153
+ _parameters = {
154
+ 'intervention_date' => intervention_date
155
+ }
156
+
157
+ # invoke the API call request to fetch the response
158
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
159
+
160
+ # Error handling using HTTP status codes
161
+ if _response.code == 401
162
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
163
+ elsif _response.code == 400
164
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
165
+ elsif _response.code == 404
166
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
167
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
168
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
169
+ end
170
+
171
+ # Return appropriate type
172
+ _response.body
173
+ end
174
+
175
+ # TODO: type endpoint description here
176
+ # @param [File] file Required parameter: TODO: type description here
177
+ # @param [String] ticket_id Required parameter: TODO: type description here
178
+ # @return String response from the API call
179
+ def upload_quote(file,
180
+ ticket_id)
181
+
182
+ # Validate required parameters
183
+ if file == nil
184
+ raise ArgumentError.new "Required parameter 'file' cannot be nil."
185
+ elsif ticket_id == nil
186
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
187
+ end
188
+
189
+ # the base uri for api requests
190
+ _query_builder = Configuration.base_uri.dup
191
+
192
+ # prepare query string for API call
193
+ _query_builder << '/tickets/{ticket_id}/quote_upload'
194
+
195
+ # process optional query parameters
196
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
197
+ 'ticket_id' => ticket_id
198
+ }
199
+
200
+ # validate and preprocess url
201
+ _query_url = APIHelper.clean_url _query_builder
202
+
203
+ # prepare headers
204
+ _headers = {
205
+ 'user-agent' => 'APIMATIC 2.0',
206
+ 'X-API-TOKEN' => Configuration.x_api_token,
207
+ 'X-API-EMAIL' => Configuration.x_api_email
208
+ }
209
+
210
+ # append custom auth authorization
211
+ CustomAuthUtility.append_custom_auth_params _headers
212
+
213
+ # prepare parameters
214
+ _parameters = {
215
+ 'file' => file
216
+ }
217
+
218
+ # invoke the API call request to fetch the response
219
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
220
+
221
+ # Error handling using HTTP status codes
222
+ if _response.code == 401
223
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
224
+ elsif _response.code == 400
225
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
226
+ elsif _response.code == 404
227
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
228
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
229
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
230
+ end
231
+
232
+ # Return appropriate type
233
+ _response.body
234
+ end
235
+
236
+ # TODO: type endpoint description here
237
+ # @param [String] body Required parameter: TODO: type description here
238
+ # @param [String] ticket_id Required parameter: TODO: type description here
239
+ # @return String response from the API call
240
+ def send_message(body,
241
+ ticket_id)
242
+
243
+ # Validate required parameters
244
+ if body == nil
245
+ raise ArgumentError.new "Required parameter 'body' cannot be nil."
246
+ elsif ticket_id == nil
247
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
248
+ end
249
+
250
+ # the base uri for api requests
251
+ _query_builder = Configuration.base_uri.dup
252
+
253
+ # prepare query string for API call
254
+ _query_builder << '/tickets/{ticket_id}/message'
255
+
256
+ # process optional query parameters
257
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
258
+ 'ticket_id' => ticket_id
259
+ }
260
+
261
+ # validate and preprocess url
262
+ _query_url = APIHelper.clean_url _query_builder
263
+
264
+ # prepare headers
265
+ _headers = {
266
+ 'user-agent' => 'APIMATIC 2.0',
267
+ 'X-API-TOKEN' => Configuration.x_api_token,
268
+ 'X-API-EMAIL' => Configuration.x_api_email
269
+ }
270
+
271
+ # append custom auth authorization
272
+ CustomAuthUtility.append_custom_auth_params _headers
273
+
274
+ # prepare parameters
275
+ _parameters = {
276
+ 'body' => body
277
+ }
278
+
279
+ # invoke the API call request to fetch the response
280
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
281
+
282
+ # Error handling using HTTP status codes
283
+ if _response.code == 401
284
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
285
+ elsif _response.code == 400
286
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
287
+ elsif _response.code == 404
288
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
289
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
290
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
291
+ end
292
+
293
+ # Return appropriate type
294
+ _response.body
295
+ end
296
+
297
+ # TODO: type endpoint description here
298
+ # @param [String] ticket_id Required parameter: TODO: type description here
299
+ # @param [DateTime] intervention_date Optional parameter: TODO: type description here
300
+ # @return String response from the API call
301
+ def declare_intervention_done(ticket_id,
302
+ intervention_date = nil)
303
+
304
+ # Validate required parameters
305
+ if ticket_id == nil
306
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
307
+ end
308
+
309
+ # the base uri for api requests
310
+ _query_builder = Configuration.base_uri.dup
311
+
312
+ # prepare query string for API call
313
+ _query_builder << '/tickets/{ticket_id}/intervention_done'
314
+
315
+ # process optional query parameters
316
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
317
+ 'ticket_id' => ticket_id
318
+ }
319
+
320
+ # validate and preprocess url
321
+ _query_url = APIHelper.clean_url _query_builder
322
+
323
+ # prepare headers
324
+ _headers = {
325
+ 'user-agent' => 'APIMATIC 2.0',
326
+ 'X-API-TOKEN' => Configuration.x_api_token,
327
+ 'X-API-EMAIL' => Configuration.x_api_email
328
+ }
329
+
330
+ # append custom auth authorization
331
+ CustomAuthUtility.append_custom_auth_params _headers
332
+
333
+ # prepare parameters
334
+ _parameters = {
335
+ 'intervention_date' => intervention_date
336
+ }
337
+
338
+ # invoke the API call request to fetch the response
339
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
340
+
341
+ # Error handling using HTTP status codes
342
+ if _response.code == 401
343
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
344
+ elsif _response.code == 400
345
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
346
+ elsif _response.code == 404
347
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
348
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
349
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
350
+ end
351
+
352
+ # Return appropriate type
353
+ _response.body
354
+ end
355
+
356
+ # The document should not be an invoice nor a quote
357
+ # @param [File] file Required parameter: TODO: type description here
358
+ # @param [String] ticket_id Required parameter: TODO: type description here
359
+ # @return String response from the API call
360
+ def upload_document(file,
361
+ ticket_id)
362
+
363
+ # Validate required parameters
364
+ if file == nil
365
+ raise ArgumentError.new "Required parameter 'file' cannot be nil."
366
+ elsif ticket_id == nil
367
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
368
+ end
369
+
370
+ # the base uri for api requests
371
+ _query_builder = Configuration.base_uri.dup
372
+
373
+ # prepare query string for API call
374
+ _query_builder << '/tickets/{ticket_id}/document_upload'
375
+
376
+ # process optional query parameters
377
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
378
+ 'ticket_id' => ticket_id
379
+ }
380
+
381
+ # validate and preprocess url
382
+ _query_url = APIHelper.clean_url _query_builder
383
+
384
+ # prepare headers
385
+ _headers = {
386
+ 'user-agent' => 'APIMATIC 2.0',
387
+ 'X-API-TOKEN' => Configuration.x_api_token,
388
+ 'X-API-EMAIL' => Configuration.x_api_email
389
+ }
390
+
391
+ # append custom auth authorization
392
+ CustomAuthUtility.append_custom_auth_params _headers
393
+
394
+ # prepare parameters
395
+ _parameters = {
396
+ 'file' => file
397
+ }
398
+
399
+ # invoke the API call request to fetch the response
400
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
401
+
402
+ # Error handling using HTTP status codes
403
+ if _response.code == 401
404
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
405
+ elsif _response.code == 400
406
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
407
+ elsif _response.code == 404
408
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
409
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
410
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
411
+ end
412
+
413
+ # Return appropriate type
414
+ _response.body
415
+ end
416
+
417
+ # TODO: type endpoint description here
418
+ # @param [File] file Required parameter: TODO: type description here
419
+ # @param [String] ticket_id Required parameter: TODO: type description here
420
+ # @return String response from the API call
421
+ def upload_picture(file,
422
+ ticket_id)
423
+
424
+ # Validate required parameters
425
+ if file == nil
426
+ raise ArgumentError.new "Required parameter 'file' cannot be nil."
427
+ elsif ticket_id == nil
428
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
429
+ end
430
+
431
+ # the base uri for api requests
432
+ _query_builder = Configuration.base_uri.dup
433
+
434
+ # prepare query string for API call
435
+ _query_builder << '/tickets/{ticket_id}/picture_upload'
436
+
437
+ # process optional query parameters
438
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
439
+ 'ticket_id' => ticket_id
440
+ }
441
+
442
+ # validate and preprocess url
443
+ _query_url = APIHelper.clean_url _query_builder
444
+
445
+ # prepare headers
446
+ _headers = {
447
+ 'user-agent' => 'APIMATIC 2.0',
448
+ 'X-API-TOKEN' => Configuration.x_api_token,
449
+ 'X-API-EMAIL' => Configuration.x_api_email
450
+ }
451
+
452
+ # append custom auth authorization
453
+ CustomAuthUtility.append_custom_auth_params _headers
454
+
455
+ # prepare parameters
456
+ _parameters = {
457
+ 'file' => file
458
+ }
459
+
460
+ # invoke the API call request to fetch the response
461
+ _response = Unirest.post _query_url, headers: _headers, parameters: _parameters
462
+
463
+ # Error handling using HTTP status codes
464
+ if _response.code == 401
465
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
466
+ elsif _response.code == 400
467
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
468
+ elsif _response.code == 404
469
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
470
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
471
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
472
+ end
473
+
474
+ # Return appropriate type
475
+ _response.body
476
+ end
477
+
478
+ # TODO: type endpoint description here
479
+ # @param [String] ticket_id Required parameter: TODO: type description here
480
+ # @return Ticket response from the API call
481
+ def get(ticket_id)
482
+
483
+ # Validate required parameters
484
+ if ticket_id == nil
485
+ raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil."
486
+ end
487
+
488
+ # the base uri for api requests
489
+ _query_builder = Configuration.base_uri.dup
490
+
491
+ # prepare query string for API call
492
+ _query_builder << '/tickets/{ticket_id}'
493
+
494
+ # process optional query parameters
495
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
496
+ 'ticket_id' => ticket_id
497
+ }
498
+
499
+ # validate and preprocess url
500
+ _query_url = APIHelper.clean_url _query_builder
501
+
502
+ # prepare headers
503
+ _headers = {
504
+ 'user-agent' => 'APIMATIC 2.0',
505
+ 'accept' => 'application/json',
506
+ 'X-API-TOKEN' => Configuration.x_api_token,
507
+ 'X-API-EMAIL' => Configuration.x_api_email
508
+ }
509
+
510
+ # append custom auth authorization
511
+ CustomAuthUtility.append_custom_auth_params _headers
512
+
513
+ # invoke the API call request to fetch the response
514
+ _response = Unirest.get _query_url, headers: _headers
515
+
516
+ # Error handling using HTTP status codes
517
+ if _response.code == 401
518
+ raise APIException.new 'Your API key is incorrect', 401, _response.body
519
+ elsif _response.code == 400
520
+ raise APIException.new 'There is an error in the parameters you send', 400, _response.body
521
+ elsif _response.code == 404
522
+ raise APIException.new 'Cannot find the resource specified', 404, _response.body
523
+ elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
524
+ raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
525
+ end
526
+
527
+ # Try to cast response to desired type
528
+ if _response.body.instance_of? Hash
529
+ begin
530
+ Ticket.from_hash(_response.body)
531
+ rescue Exception
532
+ raise APIException.new "Invalid JSON returned.", _response.code, _response.body
533
+ end
534
+ end
535
+ end
536
+ end
537
+ end