├── LICENSE.md ├── README.md ├── composer.json └── src └── Forecast └── Forecast.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Guilherme Uhelski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | forecast-php 2 | ============ 3 | 4 | Drop dead simple ~~[Forecast.io](http://forecast.io) API v2~~ [Dark Sky](https://darksky.net) API wrapper in PHP. 5 | 6 | This lets you get from the [Dark Sky API docs](https://darksky.net/dev/docs) to the code as directly as possible. 7 | 8 | PSR friendly and requires nothing. Abstractions not included. 9 | 10 | Installation 11 | ------------ 12 | 13 | Easy breezy using [Composer](http://getcomposer.org): 14 | ``` 15 | composer require guhelski/forecast-php 16 | ``` 17 | 18 | Usage 19 | ----- 20 | 21 | As simple as calling one method. 22 | ```php 23 | get('37.8267','-122.423')); 31 | 32 | // Get the forecast at a given time 33 | var_dump($forecast->get('37.8267','-122.423', '2013-05-06T12:00:00-0400')); 34 | 35 | // Use some optional query parameters 36 | var_dump($forecast->get( 37 | '37.8267', 38 | '-122.423', 39 | null, 40 | array( 41 | 'units' => 'si', 42 | 'exclude' => 'flags' 43 | ) 44 | ) 45 | ); 46 | ``` 47 | 48 | For more details and all available options check the [official documentation](https://darksky.net/dev/docs). 49 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guhelski/forecast-php", 3 | "description": "Drop dead simple Dark Sky API wrapper in PHP", 4 | "keywords": ["dark sky", "darksky", "darksky.net", "forecast", "forecast.io", "weather"], 5 | "type": "library", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Guilherme Uhelski", 10 | "email": "guilherme@uhelski.org", 11 | "homepage": "http://uhelski.org" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.0" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "": "src" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Forecast/Forecast.php: -------------------------------------------------------------------------------- 1 | api_key = $api_key; 13 | } 14 | 15 | private function request($latitude, $longitude, $time = null, $options = array()) 16 | { 17 | $request_url = self::API_ENDPOINT 18 | . $this->api_key 19 | . '/' 20 | . $latitude 21 | . ',' 22 | . $longitude 23 | . ((is_null($time)) ? '' : ','. $time); 24 | 25 | if (!empty($options)) { 26 | $request_url .= '?'. http_build_query($options); 27 | } 28 | 29 | $response = json_decode(file_get_contents($request_url)); 30 | $response->headers = $http_response_header; 31 | return $response; 32 | } 33 | 34 | public function get($latitude, $longitude, $time = null, $options = array()) 35 | { 36 | return $this->request($latitude, $longitude, $time, $options); 37 | } 38 | } 39 | --------------------------------------------------------------------------------