New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

j-crowe/open-weather

A very simple wrapper for Open Weather
18,479 4
Install
composer require j-crowe/open-weather
Latest Version:v1.2.0
PHP:>=5.3.0
Laravel:4 · 5
License:MIT
Last Updated:Mar 15, 2016
Links: GitHub  ·  Packagist
Maintainer: jcrowe206

OpenWeather PHP Wrapper

Build Status

PHP Wrapper for the Open Weather API

This library does not require Laravel; however, a Laravel Service Provider is included.

Installation

Install using composer:

"require": {
    "j-crowe/open-weather": "1.2"
}

or via CLI

composer require j-crowe/open-weather 1.2

Configuration

There are 3 required configurations:

First, the app_id - an environment variable named 'OPENWEATHER_APPID' that must be set in your application

Please see here to get one

The other two - the Base URL and Default Guzzle Options.

Please see here for possible options

Usage Without Laravel

See below for sample initialization code:

<?php

include_once 'vendor/autoload.php';

use JCrowe\OpenWeather\OpenWeather;

// Note the configs that are required. Guzzle Opts are default options for Guzzle
$baseUrl = 'http://api.openweathermap.org';
$guzzleOpts = array(
    'timeout' => 3,
    'connect_timeout' => 3
);
$appId = 'abcdefghijklmnop1234567890';

$openWeather = OpenWeather::getInstance($guzzleOpts, $baseUrl, $appId);

$response = $openWeather->getByCityName('los angeles');

if($response->isValid()) {
    print_r($response->getWeatherData());
}

?>

Usage With Laravel

In config/app.php, add the following to the service providers array.

array(
    ...
    'JCrowe\OpenWeather\Providers\OpenWeatherServiceProvider',
)

Then add the following to the aliases array.

'OpenWeather' => 'JCrowe\OpenWeather\Facades\OpenWeather'

Publish the configs using php artisan config:publish j-crowe/open-weather, which should include the default configuration, which should include the default configuration.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

407,699,310 4,663

Version History

Version Released PHP Laravel License
v1.2.0 >=5.3.0 >=4.0 MIT
1.1.0 >=5.3.0 4.* MIT
1.0.2 >=5.3.0 4.* MIT
1.0.1 >=5.3.0 4.* MIT
1.0.0 >=5.3.0 4.* MIT