Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidgh83 committed Sep 27, 2023
1 parent ffed98c commit abd2b49
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
1 change: 0 additions & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

'html_minify': True,
'css_minify': True,
'logo': False,
'logo_icon': '&#xe869',

'repo_type': 'github',
Expand Down
41 changes: 39 additions & 2 deletions source/how_to_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,50 @@
Installation
************

Step1: Composer Installation
Using Composer
==============

Start by installing the IP-Intelligence package via Composer. Run the following command in your terminal:

.. code-block:: sh
composer require jetcod/ip-intelligence
This will fetch and install the necessary package files.

This will fetch and install the necessary package files.

Configuration
=============

Laravel project
---------------

IP-Intelligence requires configuration to work effectively. This library offers an artisan command tailored for Laravel projects, streamlining the installation and configuration of necessary databases. To kickstart this process, simply execute the following artisan command:

.. code-block:: sh
php artisan IpIntelligence:data-install
Throughout this setup, you will be prompted to specify the paths to the Maxmind databases, and the associated environment variables will be automatically configured.

Non-Laravel project
-------------------

If your project is not based on the Laravel framework, you can integrate the cldr-core package by following these steps:

.. code-block:: sh
npm install cldr-core
You will then need to configure the environment attributes and specify the paths to the database files manually. Your .env file should resemble the following:

.. code-block:: ini
# Paths to Maxmind DBs
MAXMIND_DB_CITY="/path/to/GeoLite2-City.mmdb"
MAXMIND_DB_COUNTRY="/path/to/GeoIP/GeoLite2-Country.mmdb"
MAXMIND_DB_ASN="/path/to/GeoIP/GeoLite2-ASN.mmdb"
# Paths to CLDR datasets
CLDR_DATA_TERRITORYINFO="/path/to/territoryInfo.json"
91 changes: 91 additions & 0 deletions source/how_to_use.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.. _how_to_use
How to Use?
***********


The `jetcod/ip-intelligence` package provides a comprehensive solution for performing IP address lookups and obtaining valuable geographical and language-related information. This documentation outlines the available methods and their functionality.


IP Lookup
=========


ip($address)
------------

The ``ip()`` method is employed to instantiate the ``GeoIpLookup`` object with a valid IP address. Subsequently, you can utilize additional methods to retrieve valuable information associated with the IP address.

.. code-block:: php
<?php
$address = '206.47.249.128';
$ip = $lookup->ip($address);
country()
---------

The ``country()`` method allows you to retrieve various country-related details associated with the IP address.

.. code-block:: php
<?php
$countryName = $ip->country()->name;
// Returns the name of the country, e.g., 'Canada'
.. table::
:width: 100%
:align: center

+------------+---------------------------------------------------------------------------------+
| Attributes | Description |
+============+=================================================================================+
| name | The name of the country based on the locale extracted from the given IP address |
+------------+---------------------------------------------------------------------------------+
| names | An array map where the keys are locale codes and the values are names |
+------------+---------------------------------------------------------------------------------+
| isoCode | The two-character ISO 3166-1 alpha code for the country. |
+------------+---------------------------------------------------------------------------------+


city()
------

The ``city()`` method allows you to retrieve various city-related details associated with the IP address.

.. code-block:: php
<?php
$countryName = $ip->city()->name;
// Returns the name of the city, e.g., 'Toronto'
.. table::
:width: 100%
:align: center

+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Attributes | Description |
+============+============================================================================================================================================================================+
| confidence | A value from 0-100 indicating MaxMind confidence that the city is correct. This attribute is only available from the Insights service and the GeoIP2 Enterprise database |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| geonameId | The GeoName ID for the city. This attribute is returned by all location services and databases. |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name | An array map where the keys are locale codes and the values are names |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| names | An array map where the keys are locale codes and the values are names |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Error Handling
==============

The code example also includes error handling for potential exceptions:

- ``InvalidIpAddressException``: This exception is thrown when the provided IP address is invalid.

- ``AddressNotFoundException``: This exception is thrown when the IP address is not found in the database.
3 changes: 2 additions & 1 deletion source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ PHP GeoIP Locale and Language Package

overview.rst
requirements.rst
how_to_install.rst
how_to_install.rst
how_to_use.rst

0 comments on commit abd2b49

Please sign in to comment.