Giter VIP home page Giter VIP logo

endroidopenweathermapbundle's Introduction

Endroid OpenWeatherMap Bundle

By endroid

Build Status Latest Stable Version Total Downloads

This bundle enables you to use Endroid OpenWeatherMap as a service in your Symfony project. It also provides an API controller that takes a local API request, adds the API key (APPID) to it and returns the corresponding OpenWeatherMap API response. This enables you to expose the OpenWeatherMap API on your own domain without having to bother about passing your API key on every request and creating a new instance each time you make a request.

For more information see the endroid/OpenWeatherMap repository and the OpenWeatherMap API.

knpbundles.com

Requirements

Installation

Add in your composer.json

{
    "require": {
        "endroid/openweathermap-bundle": "dev-master"
    }
}

Install the bundle

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update endroid/openweathermap-bundle

Composer will install the bundle to your project's vendor/endroid directory.

Enable the bundle via the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Endroid\Bundle\OpenWeatherMapBundle\EndroidOpenWeatherMapBundle(),
    );
}

Configuration

config.yml

endroid_open_weather_map:
    api_key: "..."
    api_url: "..." // optional
    units: "..." // optional

Routing

If you don't want to expose the OpenWeatherMap API via your application, you can skip this section.

EndroidOpenWeatherMapBundle:
    resource:	"@EndroidOpenWeatherMapBundle/Controller/"
    type:		annotation
    prefix:		/openweathermap/api

This exposes the OpenWeatherMap API via /openweathermap/api. This means that instead of sending a request to http://api.openweathermap.org/ you can now send an unsigned request to /openweathermap/api/*. Make sure you secure this area if you don't want others to be able to post on your behalf.

Usage

After installation and configuration, the service can be directly referenced from within your controllers.

<?php

$openWeatherMap = $this->get('endroid.openweathermap');

// Retrieve the current weather for Breda
$weather = $openWeatherMap->getWeather('Breda,nl');

// Or retrieve the weather using the generic query method
$response = $openWeatherMap->query('weather', array('q' => 'Breda,nl'));
$weather = json_decode($response->getContent());

License

This bundle is under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

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.