Passed
Push — master ( a2c862...16044f )
by Robert
05:35
created

LiveEngageLaravel::skills()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Root class file for all api wrappers.
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel
6
 *
7
 */
8
 
9
namespace LivePersonInc\LiveEngageLaravel;
10
11
use Carbon\Carbon;
12
use GuzzleHttp\Client;
13
use GuzzleHttp\HandlerStack;
14
use GuzzleHttp\Subscriber\Oauth\Oauth1;
15
use LivePersonInc\LiveEngageLaravel\Models\Info;
16
use LivePersonInc\LiveEngageLaravel\Models\MetaData;
17
use LivePersonInc\LiveEngageLaravel\Models\AccountStatus;
18
use LivePersonInc\LiveEngageLaravel\Models\MessagingInfo;
19
use LivePersonInc\LiveEngageLaravel\Models\Payload;
20
use LivePersonInc\LiveEngageLaravel\Models\Visitor;
21
use LivePersonInc\LiveEngageLaravel\Models\Agent;
22
use LivePersonInc\LiveEngageLaravel\Models\Skill;
23
use LivePersonInc\LiveEngageLaravel\Models\Campaign;
24
use LivePersonInc\LiveEngageLaravel\Models\Engagement;
25
use LivePersonInc\LiveEngageLaravel\Models\Conversation;
26
use LivePersonInc\LiveEngageLaravel\Models\Message;
27
use LivePersonInc\LiveEngageLaravel\Collections\EngagementHistory;
28
use LivePersonInc\LiveEngageLaravel\Collections\Skills;
29
use LivePersonInc\LiveEngageLaravel\Collections\AgentParticipants;
30
use LivePersonInc\LiveEngageLaravel\Exceptions\LiveEngageException;
31
use LivePersonInc\LiveEngageLaravel\Collections\ConversationHistory;
32
33
/**
34
 * LiveEngageLaravel class holds all of the root package functions.
35
 *
36
 * All "setting" functions will return `$this` so method can be chained. Most methods will return a class object or Laravel collection.
37
 */
38
class LiveEngageLaravel
39
{
40
	/**
41
	 * account - LiveEngage account number, usually set by configuration
42
	 * 
43
	 * (default value: false)
44
	 * 
45
	 * @var long
0 ignored issues
show
Bug introduced by
The type LivePersonInc\LiveEngageLaravel\long was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
	 * @access private
47
	 */
48
	private $account = false;
49
	/**
50
	 * skills - holds the skills for history retrieval
51
	 * 
52
	 * (default value: [])
53
	 * 
54
	 * @var array
55
	 * @access private
56
	 */
57
	private $skills = [];
58
	/**
59
	 * config - holds the configuration key where keyset is stored in config/services.php
60
	 * 
61
	 * (default value: 'services.liveperson.default')
62
	 * 
63
	 * @var string
64
	 * @access private
65
	 */
66
	private $config = 'services.liveperson.default';
67
	/**
68
	 * version - api version
69
	 * 
70
	 * (default value: '1.0')
71
	 * 
72
	 * @var string
73
	 * @access private
74
	 */
75
	private $version = '1.0';
76
	/**
77
	 * history_limit - stores the history page limit
78
	 * 
79
	 * (default value: 50)
80
	 * 
81
	 * @var int
82
	 * @access private
83
	 */
84
	private $history_limit = 50;
85
	private $interactive = true;
86
	private $ended = true;
87
	/**
88
	 * bearer - bearer token for V2 authentication
89
	 * 
90
	 * (default value: false)
91
	 * 
92
	 * @var string
93
	 * @access private
94
	 */
95
	private $bearer = false;
96
	/**
97
	 * revision
98
	 * 
99
	 * (default value: 0)
100
	 * 
101
	 * @var int
102
	 * @access private
103
	 */
104
	private $revision = 0;
105
106
	/**
107
	 * domain - api domain storage
108
	 * 
109
	 * (default value: false)
110
	 * 
111
	 * @var bool
112
	 * @access private
113
	 */
114
	private $domain = false;
115
116
	/**
117
	 * retry_limit - number of times the request will attempt before it throws the exception.
118
	 * 
119
	 * (default value: 5)
120
	 * 
121
	 * @var int
122
	 * @access private
123
	 */
124
	private $retry_limit = 5;
125
	/**
126
	 * retry_counter - stores current count of retries.
127
	 * 
128
	 * (default value: 0)
129
	 * 
130
	 * @var int
131
	 * @access private
132
	 */
133
	private $retry_counter = 0;
134
135
	/**
136
	 * __get magic function to retrieve private properties of the class.
137
	 * 
138
	 * @access public
139
	 * @param mixed $attribute
140
	 * @return mixed
141
	 */
142 5
	public function __get($attribute)
143
	{
144 5
		return $this->$attribute;
145
	}
146
	
147
	private $request;
148
149
	/**
150
	 * __construct function.
151
	 * 
152
	 * @access public
153
	 * @return void
154
	 */
155 8
	public function __construct()
156
	{
157 8
		$this->account = config("{$this->config}.account");
158 8
		$this->version = config("{$this->config}.version") ?: $this->version;
159 8
		$this->request = new LiveEngageRequest($this->config);
160 8
	}
161
162
	/**
163
	 * key function sets the keyset the class should use. Setting this once will be stored for script execution, but not for the session.
164
	 * 
165
	 * @access public
166
	 * @param string $key (default: 'default')
167
	 * @return this
168
	 */
169 1
	public function key($key = 'default')
170
	{
171 1
		$this->config = "services.liveperson.$key";
172 1
		$this->__construct();
173
174 1
		return $this;
175
	}
176
	
177
	/**
178
	 * nonInteractive function.
179
	 * 
180
	 * @access public
181
	 * @return void
182
	 */
183 1
	public function nonInteractive()
184
	{
185 1
		$this->interactive = false;
186 1
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LivePersonInc\LiveEngageLaravel\LiveEngageLaravel which is incompatible with the documented return type void.
Loading history...
187
	}
188
	
189
	/**
190
	 * active function.
191
	 * 
192
	 * @access public
193
	 * @return void
194
	 */
195 1
	public function active()
196
	{
197 1
		$this->ended = false;
198 1
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LivePersonInc\LiveEngageLaravel\LiveEngageLaravel which is incompatible with the documented return type void.
Loading history...
199
	}
200
201
	/**
202
	 * limit function.
203
	 * 
204
	 * @access public
205
	 * @param mixed $limit
206
	 * @return void
207
	 */
208 1
	public function limit($limit)
209
	{
210 1
		$this->history_limit = $limit;
211
212 1
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LivePersonInc\LiveEngageLaravel\LiveEngageLaravel which is incompatible with the documented return type void.
Loading history...
213
	}
214
215
	/**
216
	 * retry function.
217
	 * 
218
	 * @access public
219
	 * @param mixed $limit
220
	 * @return void
221
	 */
222 1
	public function retry($limit)
223
	{
224 1
		$this->retry_limit = $limit;
225
226 1
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LivePersonInc\LiveEngageLaravel\LiveEngageLaravel which is incompatible with the documented return type void.
Loading history...
227
	}
228
229
	/**
230
	 * account function.
231
	 * 
232
	 * @access public
233
	 * @param mixed $accountid
234
	 * @return void
235
	 */
236 1
	public function account($accountid)
237
	{
238 1
		$this->account = $accountid;
239
240 1
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LivePersonInc\LiveEngageLaravel\LiveEngageLaravel which is incompatible with the documented return type void.
Loading history...
241
	}
242
243
	/**
244
	 * domain function sets the LivePerson domain for the secified service. Like `key` it is set for the execution script, but not session. It must be run each time.
245
	 * 
246
	 * @access public
247
	 * @param mixed $service
248
	 * @return this
249
	 */
250 1
	public function domain($service)
251
	{
252 1
		$response = $this->request->V1("https://api.liveperson.net/api/account/{$this->account}/service/{$service}/baseURI.json?version={$this->version}", 'GET');
253
		
254 1
		$this->domain = $response->baseURI;
255
256 1
		return $this;
257
	}
258
259
	/**
260
	 * visitor function gets or sets visitor attribute information - this only works for CHAT, not messaging.
261
	 * 
262
	 * @access public
263
	 * @param string $visitorID
264
	 * @param string $sessionID
265
	 * @param mixed $setData (default: false)
266
	 * @return mixed
267
	 * @codeCoverageIgnore
268
	 */
269
	public function visitor($visitorID, $sessionID, $setData = false)
270
	{
271
		$this->domain('smt');
272
273
		if ($setData) {
274
			$url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/events?v=1&sid={$sessionID}";
275
276
			return $this->request->V1($url, 'POST', $setData);
277
		} else {
278
			$url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/state?v=1&sid={$sessionID}";
279
280
			return $this->request->V1($url, 'GET');
281
		}
282
	}
283
	
284
	/**
285
	 * chat function
286
	 *
287
     * @codeCoverageIgnore
288
     *
289
     * @todo connect this to the server chat api - this function currently does nothing.
290
     */
291
	public function chat()
292
	{
293
		$this->domain('conversationVep');
294
		
295
		$url = "https://{$this->domain}/api/account/{$this->account}/chat/request?v=1&NC=true";
296
		
297
		$args = [
298
			
299
		];
300
		$payload = new Payload($args);
301
		
302
		$response = $this->request->V1($url, 'POST', $payload);
0 ignored issues
show
Bug introduced by
$payload of type LivePersonInc\LiveEngageLaravel\Models\Payload is incompatible with the type array expected by parameter $payload of LivePersonInc\LiveEngage...LiveEngageRequest::V1(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

302
		$response = $this->request->V1($url, 'POST', /** @scrutinizer ignore-type */ $payload);
Loading history...
303
		
304
		return $response;
305
	}
306
307
	/**
308
	 * retrieveHistory function.
309
	 * 
310
	 * @access public
311
	 * @final
312
	 * @param Carbon $start
313
	 * @param Carbon $end
314
	 * @param string $url (default: false)
315
	 * @return mixed
316
	 */
317 1
	final public function retrieveHistory(Carbon $start, Carbon $end, $url = false)
318
	{
319 1
		$this->domain('engHistDomain');
320
321 1
		$url = $url ?: "https://{$this->domain}/interaction_history/api/account/{$this->account}/interactions/search?limit={$this->history_limit}&offset=0";
322
323 1
		$start_str = $start->toW3cString();
324 1
		$end_str = $end->toW3cString();
325
326 1
		$data = new Payload([
327 1
			'interactive' => $this->interactive,
328 1
			'ended' => $this->ended,
329
			'start' => [
330 1
				'from' => strtotime($start_str) . '000',
331 1
				'to' => strtotime($end_str) . '000',
332
			],
333 1
			'skillIds' => $this->skills
334
		]);
335
336 1
		$result = $this->request->V1($url, 'POST', $data);
0 ignored issues
show
Bug introduced by
$data of type LivePersonInc\LiveEngageLaravel\Models\Payload is incompatible with the type array expected by parameter $payload of LivePersonInc\LiveEngage...LiveEngageRequest::V1(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

336
		$result = $this->request->V1($url, 'POST', /** @scrutinizer ignore-type */ $data);
Loading history...
337 1
		$result->records = $result->interactionHistoryRecords;
338 1
		$result->interactionHistoryRecords = null;
339
		
340 1
		return $result;
341
	}
342
343
	/**
344
	 * retrieveMsgHistory function.
345
	 * 
346
	 * @access public
347
	 * @final
348
	 * @param Carbon $start
349
	 * @param Carbon $end
350
	 * @param string $url (default: false)
351
	 * @return mixed
352
	 */
353 1
	final public function retrieveMsgHistory(Carbon $start, Carbon $end, $url = false)
354
	{
355 1
		$this->domain('msgHist');
356
357 1
		$url = $url ?: "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/search?limit={$this->history_limit}&offset=0&sort=start:desc";
358
359 1
		$start_str = $start->toW3cString();
360 1
		$end_str = $end->toW3cString();
361
362 1
		$data = new Payload([
363 1
			'status' => $this->ended ? ['CLOSE'] : ['OPEN', 'CLOSE'],
364
			'start' => [
365 1
				'from' => strtotime($start_str) . '000',
366 1
				'to' => strtotime($end_str) . '000',
367
			],
368 1
			'skillIds' => $this->skills
369
		]);
370
		
371 1
		$result = $this->request->V1($url, 'POST', $data);
0 ignored issues
show
Bug introduced by
$data of type LivePersonInc\LiveEngageLaravel\Models\Payload is incompatible with the type array expected by parameter $payload of LivePersonInc\LiveEngage...LiveEngageRequest::V1(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

371
		$result = $this->request->V1($url, 'POST', /** @scrutinizer ignore-type */ $data);
Loading history...
372 1
		$result->records = $result->conversationHistoryRecords;
373 1
		$result->conversationHistoryRecords = null;
374
		
375 1
		return $result;
376
	}
377
	
378
	/**
379
	 * skills function gets collection of skills associated with the account.
380
	 * 
381
	 * @access public
382
	 * @return Collections\Skills
383
	 */
384 1
	public function skills()
385
	{
386 1
		$this->domain('accountConfigReadOnly');
387
		
388 1
		$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/skills?v=4.0";
389
		
390 1
		return new Skills($this->request->V2($url, 'GET'));
0 ignored issues
show
Bug introduced by
$this->request->V2($url, 'GET') of type void is incompatible with the type array expected by parameter $models of LivePersonInc\LiveEngage...s\Skills::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

390
		return new Skills(/** @scrutinizer ignore-type */ $this->request->V2($url, 'GET'));
Loading history...
Bug introduced by
Are you sure the usage of $this->request->V2($url, 'GET') targeting LivePersonInc\LiveEngage...LiveEngageRequest::V2() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
391
	}
392
	
393
	/**
394
	 * getSkill function gets skill object based on ID.
395
	 * 
396
	 * @access public
397
	 * @param int $skillId
398
	 * @return Models\Skill
399
	 */
400 1
	public function getSkill($skillId)
401
	{
402 1
		$this->domain('accountConfigReadOnly');
403
		
404 1
		$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/skills/{$skillId}?v=4.0";
405
		
406 1
		return new Skill((array) $this->request->V2($url, 'GET'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->request->V2($url, 'GET') targeting LivePersonInc\LiveEngage...LiveEngageRequest::V2() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
407
	}
408
	
409
	/**
410
	 * getAgent function gets agent object based on ID.
411
	 * 
412
	 * @access public
413
	 * @param int $userId
414
	 * @return Models\Agent
415
	 */
416 1
	public function getAgent($userId)
417
	{
418 1
		$this->domain('accountConfigReadOnly');
419
		
420 1
		$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users/{$userId}?v=4.0";
421
		
422 1
		return new Agent((array) $this->request->V2($url, 'GET'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->request->V2($url, 'GET') targeting LivePersonInc\LiveEngage...LiveEngageRequest::V2() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
423
	}
424
	
425
	/**
426
	 * updateAgent function.
427
	 * 
428
	 * @access public
429
	 * @param mixed $userId
430
	 * @param mixed $properties
431
	 * @return void
432
	 * @codeCoverageIgnore
433
	 */
434
	public function updateAgent($userId, $properties)
435
	{
436
		$agent = $this->getAgent($userId);
0 ignored issues
show
Unused Code introduced by
The assignment to $agent is dead and can be removed.
Loading history...
437
		
438
		$this->domain('accountConfigReadWrite');
439
		
440
		$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users/{$userId}?v=4.0";
441
		$headers = [
442
			'X-HTTP-Method-Override' => 'PUT',
443
			'if-Match' => '*'
444
		];
445
		
446
		return new Agent((array) $this->request->V2($url, 'PUT', $properties, $headers));
0 ignored issues
show
Bug Best Practice introduced by
The expression return new LivePersonInc...$properties, $headers)) returns the type LivePersonInc\LiveEngageLaravel\Models\Agent which is incompatible with the documented return type void.
Loading history...
Bug introduced by
Are you sure the usage of $this->request->V2($url,... $properties, $headers) targeting LivePersonInc\LiveEngage...LiveEngageRequest::V2() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
447
	}
448
	
449
	/**
450
	 * agents function gets collection of agents from account.
451
	 * 
452
	 * @access public
453
	 * @return Collections\AgentParticipants
454
	 */
455 1
	public function agents()
456
	{
457 1
		$this->domain('accountConfigReadOnly');
458
		
459 1
		$select = implode(',', [
460 1
			'id',
461
			'pid',
462
			'deleted',
463
			'loginName',
464
			'skills',
465
			'nickname',
466
			'dateCreated',
467
			'userTypeId',
468
			'isApiUser',
469
			'profileIds',
470
			'permissionGroups',
471
			'allowedAppKeys',
472
			'changePwdNextLogin',
473
			'maxChats',
474
			'skillIds',
475
			'lpaCreatedUser',
476
			'email',
477
			'lobs',
478
			'profiles',
479
			'fullName',
480
			'employeeId',
481
			'managedAgentGroups',
482
			'dateUpdated',
483
			'isEnabled',
484
			'lastPwdChangeDate',
485
			'pictureUrl'
486
		]);
487
		
488 1
		$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users?v=4.0&select=$select";
489
		
490 1
		return new AgentParticipants($this->request->V2($url, 'GET'));
0 ignored issues
show
Bug introduced by
$this->request->V2($url, 'GET') of type void is incompatible with the type array expected by parameter $models of LivePersonInc\LiveEngage...icipants::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

490
		return new AgentParticipants(/** @scrutinizer ignore-type */ $this->request->V2($url, 'GET'));
Loading history...
Bug introduced by
Are you sure the usage of $this->request->V2($url, 'GET') targeting LivePersonInc\LiveEngage...LiveEngageRequest::V2() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
491
	}
492
	
493
	/**
494
	 * getAgentStatus function gets status of agents based on provided Skill IDs.
495
	 * 
496
	 * @access public
497
	 * @param int/array $skills
0 ignored issues
show
Documentation Bug introduced by
The doc comment int/array at position 0 could not be parsed: Unknown type name 'int/array' at position 0 in int/array.
Loading history...
498
	 * @return Collections\AgentParticipants
499
	 */
500 1
	public function getAgentStatus($skills)
501
	{
502 1
		$skills = is_array($skills) ? $skills : [$skills];
503
	
504 1
		$this->domain('msgHist');
505
		
506 1
		$url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/agent-view/status";
507
		
508 1
		$data = ['skillIds' => $skills];
509
		
510 1
		$response = $this->request->V1($url, 'POST', $data);
511 1
		$collection = new AgentParticipants($response->agentStatusRecords);
512 1
		$collection->metaData = new MetaData((array) $response->_metadata);
513
		
514 1
		return $collection;
515
		
516
	}
517
	
518
	/**
519
	 * conversationHistory function.
520
	 * 
521
	 * @access public
522
	 * @param Carbon $start (default: null)
523
	 * @param Carbon $end (default: null)
524
	 * @param int/array $skills (default: [])
0 ignored issues
show
Documentation Bug introduced by
The doc comment int/array at position 0 could not be parsed: Unknown type name 'int/array' at position 0 in int/array.
Loading history...
525
	 * @return Collections\ConversationHistory
526
	 */
527 1
	public function conversationHistory(Carbon $start = null, Carbon $end = null, $skills = [])
528
	{
529 1
		$this->retry_counter = 0;
530 1
		$this->skills = $skills;
531
532 1
		$start = $start ?: (new Carbon())->today();
533 1
		$end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59);
534
535 1
		$results_object = $this->retrieveMsgHistory($start, $end);
536
		
537 1
		$results_object->_metadata->start = $start;
538 1
		$results_object->_metadata->end = $end;
539
	
540 1
		$meta = new MetaData((array) $results_object->_metadata);
541
		
542 1
		$collection = new ConversationHistory($results_object->records);
543 1
		$collection->metaData = $meta;
544
		
545 1
		return $collection;
546
			
547
	}
548
	
549
	/**
550
	 * getConversation function.
551
	 * 
552
	 * @access public
553
	 * @param mixed $conversationId
554
	 * @return Models\Conversation
555
	 */
556 1
	public function getConversation($conversationId)
557
	{
558 1
		$this->domain('msgHist');
559
		
560 1
		$url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/conversation/search";
561
		
562 1
		$data = new Payload([
563 1
			'conversationId' => $conversationId
564
		]);
565
		
566 1
		$result = $this->request->V1($url, 'POST', $data);
0 ignored issues
show
Bug introduced by
$data of type LivePersonInc\LiveEngageLaravel\Models\Payload is incompatible with the type array expected by parameter $payload of LivePersonInc\LiveEngage...LiveEngageRequest::V1(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

566
		$result = $this->request->V1($url, 'POST', /** @scrutinizer ignore-type */ $data);
Loading history...
567 1
		if (!count($result->conversationHistoryRecords)) {
568
			return null; // @codeCoverageIgnore
569
		}
570
		
571 1
		return new Conversation((array) $result->conversationHistoryRecords[0]);
572
	}
573
574
	/**
575
	 * engagementHistory function.
576
	 * 
577
	 * @access public
578
	 * @param Carbon $start (default: null)
579
	 * @param Carbon $end (default: null)
580
	 * @param int/array $skills (default: [])
0 ignored issues
show
Documentation Bug introduced by
The doc comment int/array at position 0 could not be parsed: Unknown type name 'int/array' at position 0 in int/array.
Loading history...
581
	 * @return Collections\EngagementHistory
582
	 */
583 1
	public function engagementHistory(Carbon $start = null, Carbon $end = null, $skills = [])
584
	{
585 1
		$this->retry_counter = 0;
586 1
		$this->skills = $skills;
587
588 1
		$start = $start ?: (new Carbon())->today();
589 1
		$end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59);
590
591 1
		$results_object = $this->retrieveHistory($start, $end);
592
		
593 1
		$results_object->_metadata->start = $start;
594 1
		$results_object->_metadata->end = $end;
595
	
596 1
		$meta = new MetaData((array) $results_object->_metadata);
597
		
598 1
		$collection = new EngagementHistory($results_object->records);
599 1
		$collection->metaData = $meta;
600
		
601 1
		return $collection;
602
			
603
	}
604
	
605
	/**
606
	 * status function gets status of the account.
607
	 * 
608
	 * @access public
609
	 * @return Models\AccountStatus
610
	 */
611 1
	public function status()
612
	{
613 1
		$url = "https://status.liveperson.com/json?site={$this->account}";
614
		
615 1
		$response = $this->request->V1($url, 'GET');
616
		
617 1
		return new AccountStatus((array) $response);
618
	}
619
}