Skip to content

Commit e795e02

Browse files
committed
ipstack
1 parent 26be325 commit e795e02

15 files changed

+240
-231
lines changed

.php_cs

Lines changed: 106 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,109 @@
11
<?php
22

3-
use Symfony\CS\Config\Config;
4-
use Symfony\CS\FixerInterface;
5-
use Symfony\CS\Finder\DefaultFinder;
3+
return PhpCsFixer\Config::create()
4+
->setRules([
5+
'@PSR2' => true,
6+
'array_syntax' => ['syntax' => 'short'],
7+
'combine_consecutive_unsets' => true,
8+
'method_separation' => true,
9+
'no_multiline_whitespace_before_semicolons' => true,
10+
'single_quote' => true,
611

7-
$fixers = [
8-
'blankline_after_open_tag',
9-
'braces',
10-
'concat_without_spaces',
11-
'double_arrow_multiline_whitespaces',
12-
'duplicate_semicolon',
13-
'elseif',
14-
'empty_return',
15-
'encoding',
16-
'eof_ending',
17-
'extra_empty_lines',
18-
'function_call_space',
19-
'function_declaration',
20-
'include',
21-
'indentation',
22-
'join_function',
23-
'line_after_namespace',
24-
'linefeed',
25-
'list_commas',
26-
'logical_not_operators_with_successor_space',
27-
'lowercase_constants',
28-
'lowercase_keywords',
29-
'method_argument_space',
30-
'multiline_array_trailing_comma',
31-
'multiline_spaces_before_semicolon',
32-
'multiple_use',
33-
'namespace_no_leading_whitespace',
34-
'no_blank_lines_after_class_opening',
35-
'no_empty_lines_after_phpdocs',
36-
'object_operator',
37-
'operators_spaces',
38-
'parenthesis',
39-
'phpdoc_indent',
40-
'phpdoc_inline_tag',
41-
'phpdoc_no_access',
42-
'phpdoc_no_package',
43-
'phpdoc_scalar',
44-
'phpdoc_short_description',
45-
'phpdoc_to_comment',
46-
'phpdoc_trim',
47-
'phpdoc_type_to_var',
48-
'phpdoc_var_without_name',
49-
'remove_leading_slash_use',
50-
'remove_lines_between_uses',
51-
'return',
52-
'self_accessor',
53-
'short_array_syntax',
54-
'short_echo_tag',
55-
'short_tag',
56-
'single_array_no_trailing_comma',
57-
'single_blank_line_before_namespace',
58-
'single_line_after_imports',
59-
'single_quote',
60-
'spaces_before_semicolon',
61-
'spaces_cast',
62-
'standardize_not_equal',
63-
'ternary_spaces',
64-
'trailing_spaces',
65-
'trim_array_spaces',
66-
'unalign_equals',
67-
'unary_operators_spaces',
68-
'unused_use',
69-
'visibility',
70-
'whitespacy_lines',
71-
];
72-
73-
return Config::create()
74-
->fixers($fixers)
75-
->level(FixerInterface::NONE_LEVEL)
76-
->setUsingCache(false);
12+
'binary_operator_spaces' => [
13+
'align_double_arrow' => false,
14+
'align_equals' => false,
15+
],
16+
'blank_line_after_opening_tag' => true,
17+
'blank_line_before_return' => true, // DEPRECATED: use blank_line_before_statement instead.
18+
'blank_line_before_statement' => [
19+
'statements' => [
20+
'break',
21+
'continue',
22+
'declare',
23+
'return',
24+
'throw',
25+
'try',
26+
],
27+
],
28+
'braces' => [
29+
'allow_single_line_closure' => true,
30+
],
31+
// 'cast_spaces' => true,
32+
// 'class_definition' => ['singleLine' => true],
33+
'concat_space' => ['spacing' => 'none'],
34+
'declare_equal_normalize' => true,
35+
'function_typehint_space' => true,
36+
'hash_to_slash_comment' => true,
37+
'include' => true,
38+
'lowercase_cast' => true,
39+
// 'native_function_casing' => true,
40+
// 'new_with_braces' => true,
41+
// 'no_blank_lines_after_class_opening' => true,
42+
// 'no_blank_lines_after_phpdoc' => true,
43+
// 'no_empty_comment' => true,
44+
// 'no_empty_phpdoc' => true,
45+
// 'no_empty_statement' => true,
46+
'no_extra_consecutive_blank_lines' => [
47+
'curly_brace_block',
48+
'extra',
49+
'parenthesis_brace_block',
50+
'square_brace_block',
51+
'throw',
52+
'use',
53+
],
54+
// 'not_operator_with_space' => true,
55+
'not_operator_with_successor_space' => true,
56+
// 'no_leading_import_slash' => true,
57+
// 'no_leading_namespace_whitespace' => true,
58+
// 'no_mixed_echo_print' => ['use' => 'echo'],
59+
'no_multiline_whitespace_around_double_arrow' => true,
60+
// 'no_short_bool_cast' => true,
61+
// 'no_singleline_whitespace_before_semicolons' => true,
62+
'no_spaces_around_offset' => true,
63+
// 'no_trailing_comma_in_list_call' => true,
64+
// 'no_trailing_comma_in_singleline_array' => true,
65+
// 'no_unneeded_control_parentheses' => true,
66+
'no_unused_imports' => true,
67+
'no_whitespace_before_comma_in_array' => true,
68+
'no_whitespace_in_blank_line' => true,
69+
// 'normalize_index_brace' => true,
70+
'object_operator_without_whitespace' => true,
71+
// 'php_unit_fqcn_annotation' => true,
72+
// 'phpdoc_align' => true,
73+
// 'phpdoc_annotation_without_dot' => true,
74+
// 'phpdoc_indent' => true,
75+
// 'phpdoc_inline_tag' => true,
76+
// 'phpdoc_no_access' => true,
77+
// 'phpdoc_no_alias_tag' => true,
78+
// 'phpdoc_no_empty_return' => true,
79+
// 'phpdoc_no_package' => true,
80+
// 'phpdoc_no_useless_inheritdoc' => true,
81+
// 'phpdoc_return_self_reference' => true,
82+
// 'phpdoc_scalar' => true,
83+
// 'phpdoc_separation' => true,
84+
// 'phpdoc_single_line_var_spacing' => true,
85+
// 'phpdoc_summary' => true,
86+
// 'phpdoc_to_comment' => true,
87+
// 'phpdoc_trim' => true,
88+
// 'phpdoc_types' => true,
89+
// 'phpdoc_var_without_name' => true,
90+
// 'pre_increment' => true,
91+
// 'return_type_declaration' => true,
92+
// 'self_accessor' => true,
93+
// 'short_scalar_cast' => true,
94+
'single_blank_line_before_namespace' => true,
95+
// 'single_class_element_per_statement' => true,
96+
// 'space_after_semicolon' => true,
97+
// 'standardize_not_equals' => true,
98+
'ternary_operator_spaces' => true,
99+
'trailing_comma_in_multiline_array' => true,
100+
'trim_array_spaces' => true,
101+
'unary_operator_spaces' => true,
102+
'whitespace_after_comma_in_array' => true,
103+
'ternary_to_null_coalescing' => true,
104+
'compact_nullable_typehint' => true,
105+
'linebreak_after_opening_tag' => true,
106+
'lowercase_cast' => true,
107+
])
108+
//->setIndent("\t")
109+
->setLineEnding("\n");

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "pulkitjalan/geoip",
3-
"description": "Geoip Wrapper with Laravel 4 & 5 Support",
3+
"description": "Geoip Wrapper with Laravel Support",
44
"homepage": "https://github.com/pulkitjalan/geoip",
5-
"keywords": ["geoip", "freegeoip", "ip-api", "maxmind", "telize"],
5+
"keywords": ["geoip", "ipstack", "ip-api", "maxmind", "telize"],
66
"license": "MIT",
77
"authors": [
88
{
@@ -14,11 +14,11 @@
1414
"illuminate/support": "~5",
1515
"illuminate/console": "~5",
1616
"guzzlehttp/guzzle": "~6",
17-
"geoip2/geoip2": "2.*"
17+
"geoip2/geoip2": "^2.0"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "4.*",
21-
"mockery/mockery": "0.9.*"
20+
"phpunit/phpunit": "^7.0",
21+
"mockery/mockery": "^1.0"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -30,7 +30,7 @@
3030
},
3131
"extra": {
3232
"branch-alias": {
33-
"dev-master": "2.7.x-dev"
33+
"dev-master": "3.0.x-dev"
3434
},
3535
"laravel": {
3636
"providers": [

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<logging>
2929
<log type="tap" target="build/report.tap"/>
3030
<log type="junit" target="build/report.junit.xml"/>
31-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
31+
<log type="coverage-html" target="build/coverage"/>
3232
<log type="coverage-text" target="build/coverage.txt"/>
3333
<log type="coverage-clover" target="build/logs/clover.xml"/>
3434
</logging>

src/Console/UpdateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function handle()
4545
{
4646
$result = $this->geoIPUpdater->update();
4747

48-
if (!$result) {
48+
if (! $result) {
4949
$this->error('Update failed!');
5050

5151
return;
5252
}
5353

5454
$this->info('New update file ('.$result.') installed.');
5555
}
56-
56+
5757
/**
5858
* Compatibility with old versions of Laravel.
5959
*/

src/Drivers/FreeGeoIPDriver.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/Drivers/IPApiDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function get($ip)
1515
{
1616
$data = $this->getRaw($ip);
1717

18-
if (empty($data) || array_get($data, 'status') === 'fail') {
18+
if (empty($data) || (array_get($data, 'status') === 'fail')) {
1919
return $this->getDefault();
2020
}
2121

src/Drivers/IpStackDriver.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace PulkitJalan\GeoIP\Drivers;
4+
5+
use GuzzleHttp\Exception\RequestException;
6+
use PulkitJalan\GeoIP\Exceptions\InvalidCredentialsException;
7+
8+
class IpStackDriver extends AbstractGeoIPDriver
9+
{
10+
/**
11+
* @param array $config
12+
*/
13+
public function __construct(array $config)
14+
{
15+
parent::__construct($config);
16+
17+
if (! array_get($this->config, 'key')) {
18+
throw new InvalidCredentialsException();
19+
}
20+
}
21+
22+
/**
23+
* Get array of data using ipstack.
24+
*
25+
* @param string $ip
26+
*
27+
* @return array
28+
*/
29+
public function get($ip)
30+
{
31+
$data = $this->getRaw($ip);
32+
33+
if (empty($data) || (array_get($data, 'latitude') === 0 && array_get($data, 'longitude') === 0)) {
34+
return $this->getDefault();
35+
}
36+
37+
return [
38+
'city' => array_get($data, 'city'),
39+
'country' => array_get($data, 'country_name'),
40+
'countryCode' => array_get($data, 'country_code'),
41+
'latitude' => (float) number_format(array_get($data, 'latitude'), 5),
42+
'longitude' => (float) number_format(array_get($data, 'longitude'), 5),
43+
'region' => array_get($data, 'region_name'),
44+
'regionCode' => array_get($data, 'region_code'),
45+
'timezone' => array_get($data, 'time_zone.id'),
46+
'postalCode' => array_get($data, 'zip'),
47+
];
48+
}
49+
50+
/**
51+
* Get the raw GeoIP info using ipstack.
52+
*
53+
* @param string $ip
54+
*
55+
* @return array
56+
*/
57+
public function getRaw($ip)
58+
{
59+
try {
60+
return json_decode($this->guzzle->get($this->getUrl($ip))->getBody(), true);
61+
} catch (RequestException $e) {
62+
// ignore
63+
}
64+
65+
return [];
66+
}
67+
68+
/**
69+
* Get the ipstack url.
70+
*
71+
* @param string $ip
72+
*
73+
* @return string
74+
*/
75+
protected function getUrl($ip)
76+
{
77+
return 'https://api.ipstack.com/'.$ip.'?access_key='.array_get($this->config, 'key');
78+
}
79+
}

0 commit comments

Comments
 (0)