Skip to content

Commit eac52bc

Browse files
authored
Merge pull request #137 from maxmind/markf/user_count
add support for user_counts trait
2 parents 3070575 + cc81488 commit eac52bc

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Record/Traits.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
* @property-read string|null $organization The name of the organization associated
6767
* with the IP address. This attribute is only available from the City and
6868
* Insights web services and the GeoIP2 Enterprise database.
69+
* @property-read int|null $userCount The estimated number of users sharing
70+
* the IP/network during the past 24 hours. For IPv4, the count is for the
71+
* individual IP. For IPv6, the count is for the /64 network. This property is
72+
* only available from GeoIP2 Precision Insights.
6973
* @property-read string|null $userType <p>The user type associated with the IP
7074
* address. This can be one of the following values:</p>
7175
* <ul>
@@ -111,6 +115,7 @@ class Traits extends AbstractRecord
111115
'isSatelliteProvider',
112116
'isTorExitNode',
113117
'organization',
118+
'userCount',
114119
'userType',
115120
];
116121
}

tests/GeoIp2/Test/Model/InsightsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function testFull()
7373
'is_tor_exit_node' => true,
7474
'isp' => 'Comcast',
7575
'organization' => 'Blorg',
76+
'user_count' => 2,
7677
'user_type' => 'college',
7778
],
7879
];
@@ -191,6 +192,12 @@ public function testFull()
191192
$model->raw,
192193
'raw method returns raw input'
193194
);
195+
196+
$this->assertSame(
197+
2,
198+
$model->traits->userCount,
199+
'userCount is correct'
200+
);
194201
}
195202

196203
public function testEmptyObjects()

tests/GeoIp2/Test/WebService/ClientTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ class ClientTest extends \PHPUnit_Framework_TestCase
2727
],
2828
];
2929

30-
private function getResponse($ipAddress)
30+
private function getResponse($service, $ipAddress)
3131
{
32+
if ($service === 'Insights') {
33+
$insights = unserialize(serialize($this->country));
34+
$insights['traits']['user_count'] = 2;
35+
36+
$responses = [
37+
'1.2.3.4' => $this->response(
38+
'insights',
39+
200,
40+
$insights
41+
),
42+
];
43+
44+
return $responses[$ipAddress];
45+
}
46+
3247
$responses = [
3348
'1.2.3.4' => $this->response(
3449
'country',
@@ -223,6 +238,12 @@ public function testInsights()
223238
$record->continent->geonameId,
224239
'continent geoname_id is 42'
225240
);
241+
242+
$this->assertSame(
243+
2,
244+
$record->traits->userCount,
245+
'user_count is 2'
246+
);
226247
}
227248

228249
public function testCity()
@@ -444,7 +465,7 @@ private function makeRequest(
444465
$licenseKey = 'abcdef123456';
445466

446467
list($statusCode, $headers, $responseBody)
447-
= $this->getResponse($ipAddress);
468+
= $this->getResponse($service, $ipAddress);
448469

449470
$stub = $this->getMockForAbstractClass(
450471
'MaxMind\\WebService\\Http\\Request'

0 commit comments

Comments
 (0)