Coder Social home page Coder Social logo

ipstack-client's Introduction

Latest Stable Version Total Downloads License

ipstack-client

A PHP wrapper for using Ipstack API

Install via composer:

composer require ok/ipstack-client

Basic usage

Get data as the Location object:

$client = new OK\Ipstack\Client('api_key');
$location = $client->get('134.201.250.155', false);
var_dump($location);

result:

class OK\Ipstack\Entity\Location#3 (12) {
  protected $city =>
  string(11) "Los Angeles"
  protected $continentCode =>
  string(2) "NA"
  protected $continentName =>
  string(13) "North America"
  protected $countryCode =>
  string(2) "US"
  protected $countryName =>
  string(13) "United States"
  protected $regionCode =>
  string(2) "CA"
  protected $regionName =>
  string(10) "California"
  protected $zip =>
  string(5) "90026"
  protected $latitude =>
  double(34.0766)
  protected $longitude =>
  double(-118.2646)
  protected $ip =>
  string(15) "134.201.250.155"
  protected $valid =>
  bool(true)
}

Get data as a simple array:

$client = new OK\Ipstack\Client('api_key');
$location = $client->get('134.201.250.155');
var_dump($location);

result:

array(13) {
  'ip' =>
  string(15) "134.201.250.155"
  'type' =>
  string(4) "ipv4"
  'continent_code' =>
  string(2) "NA"
  'continent_name' =>
  string(13) "North America"
  'country_code' =>
  string(2) "US"
  'country_name' =>
  string(13) "United States"
  'region_code' =>
  string(2) "CA"
  'region_name' =>
  string(10) "California"
  'city' =>
  string(11) "Los Angeles"
  'zip' =>
  string(5) "90026"
  'latitude' =>
  string(7) "34.0766"
  'longitude' =>
  string(9) "-118.2646"
  'location' =>
  array(8) {
    'geoname_id' =>
    string(7) "5368361"
    'capital' =>
    string(15) "Washington D.C."
    'languages' =>
    array(3) {
      'code' =>
      string(2) "en"
      'name' =>
      string(7) "English"
      'native' =>
      string(7) "English"
    }
    'country_flag' =>
    string(38) "http://assets.ipstack.com/flags/us.svg"
    'country_flag_emoji' =>
    string(8) "πŸ‡ΊπŸ‡Έ"
    'country_flag_emoji_unicode' =>
    string(15) "U+1F1FA U+1F1F8"
    'calling_code' =>
    string(1) "1"
    'is_eu' =>
    array(0) {
    }
  }
}

Information

Modifiable output params

Available params for getting custom result

For example:

$client = new OK\Ipstack\Client('api_key');
$client->getParams()->addField("calling_code");

Data providers

Now, here are available several providers:

You can change provider by pass one of type above as second argument in constructor

For example:

$client = new OK\Ipstack\Client('api_key', OK\Ipstack\Provider\ProviderFactory::TYPE_IPAPI);

ipstack-client's People

Contributors

githubhubus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.