Skip to content

Commit dd26a0f

Browse files
authored
Merge pull request #1 from bakaphp/feat-search
2 parents 09180a2 + 924e689 commit dd26a0f

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

src/Leads/Contact.php

+27
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ public function __construct(array $data)
3636
$this->leadInformation = $data['leadInformation'] ?? [];
3737
}
3838

39+
/**
40+
* Get all the leads for the given dealer.
41+
*
42+
* @param Dealer $dealer
43+
* @param User $user
44+
* @param array $params
45+
*
46+
* @return array
47+
*/
48+
public static function getAll(Dealer $dealer, User $user, string $search, array $params = []) : array
49+
{
50+
$client = new Client($dealer->id, $user->id);
51+
$client->useDigitalShowRoomKey();
52+
53+
$data = [];
54+
$data['DealerId'] = $dealer->id;
55+
$data['UserId'] = $user->id;
56+
57+
$params = http_build_query($params);
58+
59+
$response = $client->get(
60+
'/gateway/v1/contact?dealerId=' . $dealer->id . '&userId=' . $user->id . '&searchText=' . $search . '&' . $params,
61+
);
62+
63+
return $response;
64+
}
65+
3966
/**
4067
* Get a contact by its ID.
4168
*

src/Leads/Lead.php

+27
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ public function __construct(array $data)
3636
$this->isOnShowroom = isset($data['IsOnShowroom']) ? (int) $data['IsOnShowroom'] : 0;
3737
}
3838

39+
/**
40+
* Get all the leads for the given dealer.
41+
*
42+
* @param Dealer $dealer
43+
* @param User $user
44+
* @param array $params
45+
*
46+
* @return array
47+
*/
48+
public static function getAll(Dealer $dealer, User $user, array $params = []) : array
49+
{
50+
$client = new Client($dealer->id, $user->id);
51+
$client->useDigitalShowRoomKey();
52+
53+
$data = [];
54+
$data['DealerId'] = $dealer->id;
55+
$data['UserId'] = $user->id;
56+
57+
$params = http_build_query($params);
58+
59+
$response = $client->get(
60+
'/gateway/v1/lead?dealerId=' . $dealer->id . '&userId=' . $user->id . '&' . $params,
61+
);
62+
63+
return $response;
64+
}
65+
3966
/**
4067
* Get a contact by its ID.
4168
*

tests/integration/ContactTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,35 @@ public function testUpdateContact()
170170
$this->assertEquals($contactInfo->information['LastName'], $contactInfoNew->information['LastName']);
171171
$this->assertEquals($contactInfo->emails[0]['EmailAddress'], $contactInfoNew->emails[0]['EmailAddress']);
172172
}
173+
174+
public function testGetAllContacts()
175+
{
176+
$dealer = Dealer::getById(1);
177+
$user = Dealer::getUser($dealer, 9);
178+
$contacts = LeadsContact::getAll($dealer, $user, 'gmail');
179+
180+
$this->assertIsArray($contacts);
181+
$this->assertTrue(count($contacts) > 0);
182+
}
183+
184+
public function testGetAllContactsWithParams()
185+
{
186+
$dealer = Dealer::getById(1);
187+
$user = Dealer::getUser($dealer, 9);
188+
189+
$params = [
190+
'pageNumber' => 2,
191+
'pageSize' => 50,
192+
];
193+
194+
$contacts = LeadsContact::getAll(
195+
$dealer,
196+
$user,
197+
'gmail',
198+
$params,
199+
);
200+
201+
$this->assertIsArray($contacts);
202+
$this->assertTrue(count($contacts) === $params['pageSize']);
203+
}
173204
}

tests/integration/LeadsTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,33 @@ public function testGetTradeVehicles()
461461
$this->assertIsArray($tradeIn);
462462
$this->assertTrue(count($tradeIn) > 0);
463463
}
464+
465+
public function testGetAllLeads()
466+
{
467+
$dealer = Dealer::getById(1);
468+
$user = Dealer::getUser($dealer, 9);
469+
$leads = Lead::getAll($dealer, $user);
470+
471+
$this->assertIsArray($leads);
472+
$this->assertTrue(count($leads) > 0);
473+
}
474+
475+
public function testGetAllLeadsPagination()
476+
{
477+
$dealer = Dealer::getById(1);
478+
$user = Dealer::getUser($dealer, 9);
479+
480+
$params = [
481+
'leadStatusTypeId' => 1,
482+
'pageNumber' => 2,
483+
'pageSize' => 50,
484+
];
485+
486+
$leads = Lead::getAll($dealer, $user, $params);
487+
488+
$this->assertIsArray($leads);
489+
$this->assertTrue(count($leads) > 0);
490+
$this->assertTrue($leads['PagingInfo']['PageSize'] === $params['pageSize']);
491+
$this->assertTrue($leads['PagingInfo']['PageNumber'] === $params['pageNumber']);
492+
}
464493
}

0 commit comments

Comments
 (0)