1 | <?php namespace Crunch\Salesforce; |
||
7 | class Client |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $salesforceLoginUrl; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $clientId; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $clientSecret; |
||
23 | |||
24 | /** |
||
25 | * @var AccessToken |
||
26 | */ |
||
27 | private $accessToken; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $baseUrl; |
||
33 | |||
34 | /** |
||
35 | * @var \GuzzleHttp\Client |
||
36 | */ |
||
37 | private $guzzleClient; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * Create a sf client using a client config object or an array of params |
||
42 | * |
||
43 | * @param ClientConfigInterface $clientConfig |
||
44 | * @param \GuzzleHttp\Client $guzzleClient |
||
45 | * @throws \Exception |
||
46 | */ |
||
47 | public function __construct(ClientConfigInterface $clientConfig, \GuzzleHttp\Client $guzzleClient) |
||
55 | |||
56 | /** |
||
57 | * Create an instance of the salesforce client using the passed in config data |
||
58 | * |
||
59 | * @param $salesforceLoginUrl |
||
60 | * @param $clientId |
||
61 | * @param $clientSecret |
||
62 | * @return Client |
||
63 | */ |
||
64 | public static function create($salesforceLoginUrl, $clientId, $clientSecret) |
||
68 | |||
69 | /** |
||
70 | * Fetch a specific object |
||
71 | * |
||
72 | * @param string $objectType |
||
73 | * @param string $sfId |
||
74 | * @param array $fields |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getRecord($objectType, $sfId, array $fields) |
||
84 | |||
85 | /** |
||
86 | * Execute an SOQL query and return the result set |
||
87 | * This will loop through large result sets collecting all the data so the query should be limited |
||
88 | * |
||
89 | * @param string|null $query |
||
90 | * @param string|null $next_url |
||
91 | * @return array |
||
92 | * @throws \Exception |
||
93 | */ |
||
94 | public function search($query = null, $next_url = null) |
||
114 | |||
115 | /** |
||
116 | * Make an update request |
||
117 | * |
||
118 | * @param string $object The object type to update |
||
119 | * @param string $id The ID of the record to update |
||
120 | * @param array $data The data to put into the record |
||
121 | * @return bool |
||
122 | * @throws \Exception |
||
123 | */ |
||
124 | public function updateRecord($object, $id, array $data) |
||
135 | |||
136 | /** |
||
137 | * Create a new object in salesforce |
||
138 | * |
||
139 | * @param string $object |
||
140 | * @param array|object $data |
||
141 | * @return string The id of the newly created record |
||
142 | * @throws \Exception |
||
143 | */ |
||
144 | public function createRecord($object, $data) |
||
156 | |||
157 | /** |
||
158 | * Delete an object with th specified id |
||
159 | * |
||
160 | * @param string $object |
||
161 | * @param string $id |
||
162 | * @return bool |
||
163 | * @throws \Exception |
||
164 | */ |
||
165 | public function deleteRecord($object, $id) |
||
173 | |||
174 | /** |
||
175 | * Complete the oauth process by confirming the code and returning an access token |
||
176 | * |
||
177 | * @param $code |
||
178 | * @param $redirect_url |
||
179 | * @return array|mixed |
||
180 | * @throws \Exception |
||
181 | */ |
||
182 | public function authorizeConfirm($code, $redirect_url) |
||
198 | |||
199 | /** |
||
200 | * Get the url to redirect users to when setting up a salesforce access token |
||
201 | * |
||
202 | * @param $redirectUrl |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getLoginUrl($redirectUrl) |
||
216 | |||
217 | /** |
||
218 | * Refresh an existing access token |
||
219 | * |
||
220 | * @return AccessToken |
||
221 | * @throws \Exception |
||
222 | */ |
||
223 | public function refreshToken() |
||
241 | |||
242 | /** |
||
243 | * @param AccessToken $accessToken |
||
244 | */ |
||
245 | public function setAccessToken(AccessToken $accessToken) |
||
250 | |||
251 | /** |
||
252 | * @param string $method |
||
253 | * @param string $url |
||
254 | * @param array $data |
||
255 | * @return mixed |
||
256 | * @throws AuthenticationException |
||
257 | * @throws RequestException |
||
258 | */ |
||
259 | private function makeRequest($method, $url, $data) |
||
280 | |||
281 | /** |
||
282 | * @return string |
||
283 | */ |
||
284 | private function getAuthHeader() |
||
292 | |||
293 | } |
||
294 |