Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed May 23, 2024
1 parent e0e96c1 commit 668da2a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
96 changes: 93 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,101 @@ Will return the following string to the `index` view:
"The IP address 127.0.0.1"
```

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.
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.

Voici le contenu de l'objet `$geolocation` apres un dump:

```bash
Laravelcm\AbstractIpGeolocation\DataObject\GeolocationData {#1164
+ipAddress: "166.171.248.255"
+city: "Paris"
+cityGeonameId: 2997712
+region: "Île-de-France"
+regionIsoCode: "IDF"
+regionGeonameId: 3012874
+postalCode: "75002"
+country: "France"
+countryCode: "FR"
+countryIsEU: true
+continent: "Europe"
+continentCode: "EU"
+continentGeonameId: 3017382
+longitude: 2.3024
+latitude: 48.6939
+security: Laravelcm\AbstractIpGeolocation\DataObject\Security {#839
+isVpn: false
}
+timezone: Laravelcm\AbstractIpGeolocation\DataObject\Timezone {#1182
+name: "Europe/Paris"
+abbreviation: "CEST"
+gmtOffset: 2
+currentTime: "19:08:34"
+isDST: true
}
+flag: Laravelcm\AbstractIpGeolocation\DataObject\Flag {#1165
+svg: "https://static.abstractapi.com/country-flags/FR_flag.svg"
+png: "https://static.abstractapi.com/country-flags/FR_flag.png"
+emoji: "🇫🇷"
+unicode: "U+1F1EB U+1F1F7"
}
+currency: Laravelcm\AbstractIpGeolocation\DataObject\Currency {#817
+name: "Euros"
+code: "EUR"
}
+connection: Laravelcm\AbstractIpGeolocation\DataObject\Connection {#425
+connectionType: "Cable/DSL"
+autonomousSystemNumber: 45980
+autonomousSystemOrganization: "Free SAS"
+ispName: "ProXad network / Free SAS"
+organizationName: "Proxad / Free SAS"
}
}
```

### Configuration
wip..
Config file are located at `config/abstract-ip-geolocation.php` after publishing provider element.

#### Fields
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.
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).

```php
/*
|--------------------------------------------------------------------------
| Geolocation Fields
|--------------------------------------------------------------------------
| You can include a fields value in the query parameters with a comma
| separated list of the top-level keys you want to be returned. For example
| "fields => 'city,region'" will return only the city and region in the response.
|
| see: https://docs.abstractapi.com/ip-geolocation#request-parameters
*/

'fields' => null,
```

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,
you'll only have the `country` and `currency` values available - the others will be null.

To access this information, consult `session()`.

```php
$geolocation = session()->get('abstract-ip-geolocation');

$geolocation->country // return "France"
$currency = $geolocation->currency // instance of \Laravelcm\AbstractIpGeolocation\DataObject\Currency
```

#### DTO
The available DTO classes are listed below. In the json return from the Abstract Geolocation API, all objects are represented by DTO classes

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

## License

Expand Down
2 changes: 1 addition & 1 deletion src/DataObject/GeolocationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function fromResponse(array $data): GeolocationData
countryCode: self::valueIfExist('country_code', $data),
countryIsEU: self::valueIfExist('country_is_eu', $data),
continent: self::valueIfExist('continent', $data),
continentCode: self::valueIfExist('continent', $data),
continentCode: self::valueIfExist('continent_code', $data),
continentGeonameId: self::valueIfExist('country_geoname_id', $data),
longitude: self::valueIfExist('longitude', $data),
latitude: self::valueIfExist('latitude', $data),
Expand Down

0 comments on commit 668da2a

Please sign in to comment.