2017 © Pedro Peláez
 

library open-weather

Simply web widget showing weather in defined location based on Open Weather API

image

dwr/open-weather

Simply web widget showing weather in defined location based on Open Weather API

  • Thursday, February 23, 2017
  • by dwr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Latest Stable Version Software License Build Status Coverage Status Scrutinizer Code Quality Total Downloads, (*1)

DwrOpenWeather

DwrOpenWeather is a simply wrapper for Open Weather API.
In order to start please generate your personal ApiKey first.
You can do it here., (*2)

Installation and usage

When you have ApiKey, installation and usage is very easy., (*3)

Step 1: Download DwrOpenWeather using composer

Add DwrOpenWeather in your composer.json:, (*4)

    {
        "require": {
            "dwr/open-weather": "1.0.0"
        }
    }

or download it by running the command:, (*5)

    $ php composer.phar require dwr/open-weather

Step 2: Use it in your application

GET Weather

    // errors reporting
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    require __DIR__ . '/vendor/autoload.php';

    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;

    $apiKey = YOURS-API-KEY; //consider keeping api key in environment variable: getenv('OPEN_WEATHER_API_KEY'); 
    $openWeatherConfig = new Configuration($apiKey);

    $openWeather = new OpenWeather('Weather', $openWeatherConfig);
    $weather = $openWeather->getByCityName('London');

    var_dump($weather);

You can get weather from OpenWeather API by using: * getByCityName('London') * getByCityId('2643743')
List of city ID city.list.json.gz can be downloaded here * getByGeographicCoordinates(-0.12574, 51.50853), (*6)

GET Forecast

    // errors reporting
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    require __DIR__ . '/vendor/autoload.php';

    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;

    $apiKey = YOURS-API-KEY; 

    //Consider keeping api key in environment variable.
    //$apiKey = getenv('OPEN_WEATHER_API_KEY');

    $openWeatherConfig = new Configuration($apiKey);

    $openWeather = new OpenWeather('Forecast', $openWeatherConfig);
    $forecast = $openWeather->getByCityName('London');

    var_dump($forecast);

You can get forecast from OpenWeather API by using: * getByCityName('London') * getByCityId('2643743')
List of city ID city.list.json.gz can be downloaded here * getByGeographicCoordinates(-0.12574, 51.50853), (*7)

Configuration (Optional)

You may configure library on your own if you like. There are several variables which you can set by yourself: * baseUri, * version, * timeout, * httpClient * apiKey;, (*8)

    require __DIR__ . '/../vendor/autoload.php';

    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;

    $apiKey = YOURS-API-KEY;

    //Consider keeping api key in environment variable.
    //$apiKey = getenv('OPEN_WEATHER_API_KEY');

    $openWeatherConfig = new Configuration($apiKey);

    //CONFIGURATION DwrOpenWeather
    $openWeatherConfig->setBaseUri(NEW-BASE-URI);
    $openWeatherConfig->setVersion(NEW-API-VERSION);
    $openWeatherConfig->setTimeout(NEW-TIMEOUT);
    $openWeatherConfig->setHttpClient(NEW-HTTP-CLIENT); //Has to implement GuzzleHttp\ClientInterface
    $openWeatherConfig->setApiKey(NEW-API-URI);

    $openWeather = new OpenWeather('Weather', $openWeatherConfig);

Examples

Take a moment and check examples directory in DwrOpenWeather. Maybe you will find there a solution which you like., (*9)

weather-basic-small

weather-basic-small, (*10)

weather-basic-medium

weather-basic-medium, (*11)

weather-basic-large

weather-basic-large, (*12)

forecast-chart

forecast-chart, (*13)

forecast-basic

forecast-basic, (*14)

License

The MIT License (MIT). Please see License File for more information., (*15)

The Versions

23/02 2017

dev-master

9999999-dev https://github.com//dariuszwrzesien//DwrOpenWeather

Simply web widget showing weather in defined location based on Open Weather API

  Sources   Download

MIT

The Requires

 

The Development Requires

weather open weather weather rest api

15/02 2017

1.0.0

1.0.0.0 https://github.com//dariuszwrzesien//DwrOpenWeather

Simply web widget showing weather in defined location based on Open Weather API

  Sources   Download

MIT

The Requires

 

The Development Requires

weather open weather weather rest api

14/02 2017

1.0.0-rc0

1.0.0.0-RC https://github.com//dariuszwrzesien//DwrOpenWeather

Simply web widget showing weather in defined location based on Open Weather API

  Sources   Download

MIT

The Requires

 

The Development Requires

weather open weather weather rest api