Skip to content

Commit 5dc27c0

Browse files
committed
updated ipapi pro secure connection
1 parent 18f27d2 commit 5dc27c0

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ $config = [
7171
'driver' => 'ip-api',
7272
'ip-api' => [
7373
'key' => 'YOUR IP-API KEY',
74+
// optionally set secure (https) connection (default: false)
75+
'secure' => true
7476
],
7577
];
7678
```

src/Drivers/IPApiDriver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ protected function getUrl($ip)
7171
*/
7272
protected function create()
7373
{
74+
$protocol = 'http:';
75+
if (array_get($this->config, 'secure', false)) {
76+
$protocol = 'https:';
77+
}
78+
7479
if (array_get($this->config, 'key', false)) {
75-
$this->baseUrl = 'http://pro.ip-api.com/json/';
80+
$this->baseUrl = $protocol.'://pro.ip-api.com/json/';
7681
$this->key = array_get($this->config, 'key');
7782
}
7883

src/GeoIP.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ public function getDriver()
3939
return $this->driver;
4040
}
4141

42-
/**
43-
* Setter for driver
44-
*
45-
* @return \PulkitJalan\GeoIP\GeoIP
46-
*/
47-
public function setDriver($driver)
48-
{
49-
$this->driver = $driver;
50-
51-
return $this;
52-
}
53-
5442
/**
5543
* Set ip
5644
*

src/GeoIPManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getDriver($driver = null)
3333
$method = 'create'.ucfirst(camel_case($driver)).'Driver';
3434

3535
if (!method_exists($this, $method)) {
36-
throw new InvalidDriverException(sprintf('Driver [%s] does not exist.', $driver));
36+
throw new InvalidDriverException(sprintf('Driver [%s] not supported.', $driver));
3737
}
3838

3939
return $this->{$method}(array_get($this->config, $driver, []));

src/Laravel/config/config.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,16 @@
4848
|--------------------------------------------------------------------------
4949
*/
5050
'key' => '',
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| IP-API Secure connection
55+
|--------------------------------------------------------------------------
56+
|
57+
| Use https instead of http
58+
| Only applicable with the Pro service
59+
|
60+
*/
61+
'secure' => false,
5162
],
5263
];

tests/GeoIPTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function testIpApiProException()
124124
'driver' => 'ip-api',
125125
'ip-api' => [
126126
'key' => 'test',
127+
'secure' => true,
127128
],
128129
];
129130

@@ -132,7 +133,7 @@ public function testIpApiProException()
132133
$geoip = new \PulkitJalan\GeoIP\GeoIP($config);
133134
$geoip = $geoip->setIP($this->validIP);
134135

135-
$this->assertEquals($geoip->getCountry(), '');
136+
$geoip->get();
136137
}
137138

138139
public function testIpApi()

0 commit comments

Comments
 (0)