Class: Pinch::TicketController
- Inherits:
-
Object
- Object
- Pinch::TicketController
- Defined in:
- lib/pinch/controllers/ticket_controller.rb
Constant Summary collapse
- @@instance =
TicketController.new
Class Method Summary collapse
-
.instance ⇒ Object
Singleton instance of the controller class.
Instance Method Summary collapse
-
#accept_intervention(ticket_id) ⇒ Object
This method returns no result but the status code tells you if the operation succedded.
-
#declare_intervention_done(ticket_id, intervention_date = nil) ⇒ Object
TODO: type endpoint description here.
-
#get(ticket_id) ⇒ Object
TODO: type endpoint description here.
-
#list ⇒ Object
List all the opened tickets of every clients you are working for.
-
#send_message(body, ticket_id) ⇒ Object
TODO: type endpoint description here.
-
#set_intervention_date(intervention_date, ticket_id) ⇒ Object
TODO: type endpoint description here.
-
#upload_document(file, ticket_id) ⇒ Object
The document should not be an invoice nor a quote.
-
#upload_picture(file, ticket_id) ⇒ Object
TODO: type endpoint description here.
-
#upload_quote(file, ticket_id) ⇒ Object
TODO: type endpoint description here.
Class Method Details
.instance ⇒ Object
Singleton instance of the controller class
7 8 9 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 7 def self.instance @@instance end |
Instance Method Details
#accept_intervention(ticket_id) ⇒ Object
This method returns no result but the status code tells you if the operation succedded
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 65 def accept_intervention(ticket_id) # Validate required parameters if ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/accept' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#declare_intervention_done(ticket_id, intervention_date = nil) ⇒ Object
TODO: type endpoint description here
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 301 def declare_intervention_done(ticket_id, intervention_date = nil) # Validate required parameters if ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/intervention_done' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'intervention_date' => intervention_date } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#get(ticket_id) ⇒ Object
TODO: type endpoint description here
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 481 def get(ticket_id) # Validate required parameters if ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'accept' => 'application/json', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # invoke the API call request to fetch the response _response = Unirest.get _query_url, headers: _headers # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Try to cast response to desired type if _response.body.instance_of? Hash begin Ticket.from_hash(_response.body) rescue Exception raise APIException.new "Invalid JSON returned.", _response.code, _response.body end end end |
#list ⇒ Object
List all the opened tickets of every clients you are working for
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 13 def list # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets' # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'accept' => 'application/json', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # invoke the API call request to fetch the response _response = Unirest.get _query_url, headers: _headers # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Try to cast response to list of desired type if _response.body.instance_of? Array value = Array.new _response.body.each do |item| begin value << (Ticket.from_hash(item)) rescue Exception raise APIException.new "Invalid JSON returned.", _response.code, _response.body end end value end end |
#send_message(body, ticket_id) ⇒ Object
TODO: type endpoint description here
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 240 def (body, ticket_id) # Validate required parameters if body == nil raise ArgumentError.new "Required parameter 'body' cannot be nil." elsif ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/message' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'body' => body } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#set_intervention_date(intervention_date, ticket_id) ⇒ Object
TODO: type endpoint description here
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 118 def set_intervention_date(intervention_date, ticket_id) # Validate required parameters if intervention_date == nil raise ArgumentError.new "Required parameter 'intervention_date' cannot be nil." elsif ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/set_intervention_date' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'intervention_date' => intervention_date } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#upload_document(file, ticket_id) ⇒ Object
The document should not be an invoice nor a quote
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 360 def upload_document(file, ticket_id) # Validate required parameters if file == nil raise ArgumentError.new "Required parameter 'file' cannot be nil." elsif ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/document_upload' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'file' => file } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#upload_picture(file, ticket_id) ⇒ Object
TODO: type endpoint description here
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 421 def upload_picture(file, ticket_id) # Validate required parameters if file == nil raise ArgumentError.new "Required parameter 'file' cannot be nil." elsif ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/picture_upload' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'file' => file } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |
#upload_quote(file, ticket_id) ⇒ Object
TODO: type endpoint description here
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/pinch/controllers/ticket_controller.rb', line 179 def upload_quote(file, ticket_id) # Validate required parameters if file == nil raise ArgumentError.new "Required parameter 'file' cannot be nil." elsif ticket_id == nil raise ArgumentError.new "Required parameter 'ticket_id' cannot be nil." end # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/tickets/{ticket_id}/quote_upload' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'ticket_id' => ticket_id } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'user-agent' => 'APIMATIC 2.0', 'X-API-TOKEN' => Configuration.x_api_token, 'X-API-EMAIL' => Configuration.x_api_email } # append custom auth authorization CustomAuthUtility.append_custom_auth_params _headers # prepare parameters _parameters = { 'file' => file } # invoke the API call request to fetch the response _response = Unirest.post _query_url, headers: _headers, parameters: _parameters # Error handling using HTTP status codes if _response.code == 401 raise APIException.new 'Your API key is incorrect', 401, _response.body elsif _response.code == 400 raise APIException.new 'There is an error in the parameters you send', 400, _response.body elsif _response.code == 404 raise APIException.new 'Cannot find the resource specified', 404, _response.body elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', _response.code, _response.body end # Return appropriate type _response.body end |