-
Notifications
You must be signed in to change notification settings - Fork 53
/
BaseController.php
69 lines (61 loc) · 1.68 KB
/
BaseController.php
1
2
3
4
5
6
7
8
9
10
11
12
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
61
62
63
64
65
66
67
68
69
<?php
/*
* Pipedrive
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
namespace Pipedrive\Controllers;
use Pipedrive\Http\HttpCallBack;
use Pipedrive\Http\HttpContext;
use Pipedrive\Http\HttpResponse;
use Pipedrive\APIException;
use Pipedrive\Exceptions;
use \apimatic\jsonmapper\JsonMapper;
use Unirest\Request;
/**
* Base controller
*/
class BaseController
{
/**
* User-agent to be sent with API calls
* @var string
*/
const USER_AGENT = 'Pipedrive-SDK-PHP-4.0.0';
/**
* HttpCallBack instance associated with this controller
* @var HttpCallBack
*/
private $httpCallBack = null;
/**
* Set HttpCallBack for this controller
* @param HttpCallBack $httpCallBack Http Callbacks called before/after each API call
*/
public function setHttpCallBack(HttpCallBack $httpCallBack)
{
$this->httpCallBack = $httpCallBack;
}
/**
* Get HttpCallBack for this controller
* @return HttpCallBack The HttpCallBack object set for this controller
*/
public function getHttpCallBack()
{
return $this->httpCallBack;
}
/**
* Get a new JsonMapper instance for mapping objects
* @return \apimatic\jsonmapper\JsonMapper JsonMapper instance
*/
protected function getJsonMapper()
{
$mapper = new JsonMapper();
return $mapper;
}
protected function validateResponse(HttpResponse $response, HttpContext $_httpContext)
{
if (($response->getStatusCode() < 200) || ($response->getStatusCode() > 208)) { //[200,208] = HTTP OK
throw new APIException('HTTP Response Not OK', $_httpContext);
}
}
}