Skip to content

Commit 668da2a

Browse files
committed
Update readme
1 parent e0e96c1 commit 668da2a

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed

README.md

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,101 @@ Will return the following string to the `index` view:
5656
"The IP address 127.0.0.1"
5757
```
5858

59+
Mais par défaut cet object `$geolocation` est une instance de la classe `\Laravelcm\AbstractIpGeolocation\DataObject\GeolocationData` qui donne toutes les valeurs transformées de l'API (tableau) en objet PHP.
60+
Les informations sont stockées par défaut dans la session depuis le middleware, ce qui vous permet d'avoir accès aux informations n'importe où dans votre code.
61+
62+
Voici le contenu de l'objet `$geolocation` apres un dump:
63+
64+
```bash
65+
Laravelcm\AbstractIpGeolocation\DataObject\GeolocationData {#1164
66+
+ipAddress: "166.171.248.255"
67+
+city: "Paris"
68+
+cityGeonameId: 2997712
69+
+region: "Île-de-France"
70+
+regionIsoCode: "IDF"
71+
+regionGeonameId: 3012874
72+
+postalCode: "75002"
73+
+country: "France"
74+
+countryCode: "FR"
75+
+countryIsEU: true
76+
+continent: "Europe"
77+
+continentCode: "EU"
78+
+continentGeonameId: 3017382
79+
+longitude: 2.3024
80+
+latitude: 48.6939
81+
+security: Laravelcm\AbstractIpGeolocation\DataObject\Security {#839
82+
+isVpn: false
83+
}
84+
+timezone: Laravelcm\AbstractIpGeolocation\DataObject\Timezone {#1182
85+
+name: "Europe/Paris"
86+
+abbreviation: "CEST"
87+
+gmtOffset: 2
88+
+currentTime: "19:08:34"
89+
+isDST: true
90+
}
91+
+flag: Laravelcm\AbstractIpGeolocation\DataObject\Flag {#1165
92+
+svg: "https://static.abstractapi.com/country-flags/FR_flag.svg"
93+
+png: "https://static.abstractapi.com/country-flags/FR_flag.png"
94+
+emoji: "🇫🇷"
95+
+unicode: "U+1F1EB U+1F1F7"
96+
}
97+
+currency: Laravelcm\AbstractIpGeolocation\DataObject\Currency {#817
98+
+name: "Euros"
99+
+code: "EUR"
100+
}
101+
+connection: Laravelcm\AbstractIpGeolocation\DataObject\Connection {#425
102+
+connectionType: "Cable/DSL"
103+
+autonomousSystemNumber: 45980
104+
+autonomousSystemOrganization: "Free SAS"
105+
+ispName: "ProXad network / Free SAS"
106+
+organizationName: "Proxad / Free SAS"
107+
}
108+
}
109+
```
110+
59111
### Configuration
60-
wip..
112+
Config file are located at `config/abstract-ip-geolocation.php` after publishing provider element.
113+
114+
#### Fields
115+
By default, all fields are returned by the Abstract API, but you can choose to retrieve just the values you're interested in from the API.
116+
To do this, you need to specify the fields you want (the list of fields is available here https://docs.abstractapi.com/ip-geolocation#request-parameters).
117+
118+
```php
119+
/*
120+
|--------------------------------------------------------------------------
121+
| Geolocation Fields
122+
|--------------------------------------------------------------------------
123+
| You can include a fields value in the query parameters with a comma
124+
| separated list of the top-level keys you want to be returned. For example
125+
| "fields => 'city,region'" will return only the city and region in the response.
126+
|
127+
| see: https://docs.abstractapi.com/ip-geolocation#request-parameters
128+
*/
129+
130+
'fields' => null,
131+
```
132+
133+
Once you've specified the fields you want (e.g. `country,currency`) only these values will be returned by the API and in your geolocations DTO object,
134+
you'll only have the `country` and `currency` values available - the others will be null.
135+
136+
To access this information, consult `session()`.
137+
138+
```php
139+
$geolocation = session()->get('abstract-ip-geolocation');
140+
141+
$geolocation->country // return "France"
142+
$currency = $geolocation->currency // instance of \Laravelcm\AbstractIpGeolocation\DataObject\Currency
143+
```
144+
145+
#### DTO
146+
The available DTO classes are listed below. In the json return from the Abstract Geolocation API, all objects are represented by DTO classes
61147

62-
### Test
63-
wip..
148+
- `\Laravelcm\AbstractIpGeolocation\DataObject\GeolocationData` which represents the geolocation class containing all information relating to the user via its IP address
149+
- `\Laravelcm\AbstractIpGeolocation\DataObject\Connection` which represents the DTO class for its connection origin information
150+
- `\Laravelcm\AbstractIpGeolocation\DataObject\Currency` which represents the DTO class for the currency
151+
- `\Laravelcm\AbstractIpGeolocation\DataObject\Flag` which represents the DTO class for country flag information
152+
- `\Laravelcm\AbstractIpGeolocation\DataObject\Timezone` which represents the DTO class for Timezone information
153+
- `\Laravelcm\AbstractIpGeolocation\DataObject\Security` which represents the DTO class for security information, lets you know whether the user is using a VPN or not
64154

65155
## License
66156

src/DataObject/GeolocationData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function fromResponse(array $data): GeolocationData
104104
countryCode: self::valueIfExist('country_code', $data),
105105
countryIsEU: self::valueIfExist('country_is_eu', $data),
106106
continent: self::valueIfExist('continent', $data),
107-
continentCode: self::valueIfExist('continent', $data),
107+
continentCode: self::valueIfExist('continent_code', $data),
108108
continentGeonameId: self::valueIfExist('country_geoname_id', $data),
109109
longitude: self::valueIfExist('longitude', $data),
110110
latitude: self::valueIfExist('latitude', $data),

0 commit comments

Comments
 (0)