This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89fe12c
commit cbb4ec4
Showing
3,147 changed files
with
442 additions
and
356,495 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
vendor/* | ||
composer.phar | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
# Geocoder | ||
A class for handling geocoding. | ||
# Darksky | ||
A simple wrapper for Dark Sky API | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/geocoder/geocoder/v/stable)](https://packagist.org/packages/geocoder/geocoder) | ||
[![Build Status](https://travis-ci.org/iranianpep/geocoder.svg?branch=master)](https://travis-ci.org/iranianpep/geocoder) | ||
[![Build Status](https://scrutinizer-ci.com/g/iranianpep/geocoder/badges/build.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/geocoder/build-status/master) | ||
[![Code Climate](https://codeclimate.com/github/iranianpep/geocoder/badges/gpa.svg)](https://codeclimate.com/github/iranianpep/geocoder) | ||
[![Test Coverage](https://codeclimate.com/github/iranianpep/geocoder/badges/coverage.svg)](https://codeclimate.com/github/iranianpep/geocoder/coverage) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/iranianpep/geocoder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/geocoder/?branch=master) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/iranianpep/geocoder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/geocoder/?branch=master) | ||
[![Issue Count](https://codeclimate.com/github/iranianpep/geocoder/badges/issue_count.svg)](https://codeclimate.com/github/iranianpep/geocoder) | ||
[![License](https://poser.pugx.org/geocoder/geocoder/license)](https://packagist.org/packages/geocoder/geocoder) | ||
[![Latest Stable Version](https://poser.pugx.org/darksky/darksky/v/stable)](https://packagist.org/packages/darksky/darksky) | ||
[![Build Status](https://travis-ci.org/iranianpep/darksky.svg?branch=master)](https://travis-ci.org/iranianpep/darksky) | ||
[![Build Status](https://scrutinizer-ci.com/g/iranianpep/darksky/badges/build.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/darksky/build-status/master) | ||
[![Code Climate](https://codeclimate.com/github/iranianpep/darksky/badges/gpa.svg)](https://codeclimate.com/github/iranianpep/darksky) | ||
[![Test Coverage](https://codeclimate.com/github/iranianpep/darksky/badges/coverage.svg)](https://codeclimate.com/github/iranianpep/darksky/coverage) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/iranianpep/darksky/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/darksky/?branch=master) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/iranianpep/darksky/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/iranianpep/darksky/?branch=master) | ||
[![Issue Count](https://codeclimate.com/github/iranianpep/darksky/badges/issue_count.svg)](https://codeclimate.com/github/iranianpep/darksky) | ||
[![License](https://poser.pugx.org/darksky/darksky/license)](https://packagist.org/packages/darksky/darksky) | ||
[![StyleCI](https://styleci.io/repos/95418474/shield?branch=master)](https://styleci.io/repos/95418474) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8575ff8e33034e0a81cedd9464ac359a)](https://www.codacy.com/app/iranianpep/geocoder?utm_source=github.com&utm_medium=referral&utm_content=iranianpep/geocoder&utm_campaign=Badge_Grade) | ||
[![Packagist](https://img.shields.io/packagist/dt/geocoder/geocoder.svg)](https://packagist.org/packages/geocoder/geocoder) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iranianpep/geocoder/master/LICENSE) | ||
|
||
## Usage | ||
- Get the Google Maps Geocoding API key: https://developers.google.com/maps/documentation/geocoding/get-api-key | ||
- `$result = (new Geocoder('THE_API_KEY'))->geocode('THE_ADDRESS');` | ||
- To get latitude and longitude `(new Geocoder('THE_API_KEY'))->getLatLng('THE_ADDRESS')` | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8575ff8e33034e0a81cedd9464ac359a)](https://www.codacy.com/app/iranianpep/darksky?utm_source=github.com&utm_medium=referral&utm_content=iranianpep/darksky&utm_campaign=Badge_Grade) | ||
[![Packagist](https://img.shields.io/packagist/dt/darksky/darksky.svg)](https://packagist.org/packages/darksky/darksky) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iranianpep/darksky/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
{ | ||
"name": "geocoder/geocoder", | ||
"description": "A class for handling geocoding", | ||
"homepage": "https://github.com/iranianpep/geocoder", | ||
"name": "darksky/darksky", | ||
"description": "A simple wrapper for Dark Sky API", | ||
"homepage": "https://github.com/iranianpep/darksky", | ||
"license": "MIT", | ||
"authors": [ | ||
{ "name": "Ehsan Abbasi", "email": "ehsan.abb@gmail.com" } | ||
], | ||
"require": { | ||
"php": ">=7", | ||
"nlp-tools/nlp-tools": "^0.1.3", | ||
"guzzlehttp/guzzle": "6.2.*", | ||
"codeclimate/php-test-reporter": "^0.4.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "6.1.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Geocoder\\": ["src/Geocoder"] | ||
"Darksky\\": ["src/Darksky"] | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": {"Geocoder\\": "tests/Geocoder"} | ||
"psr-4": {"Darksky\\": "tests/Darksky"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
namespace Darksky; | ||
|
||
class Darksky | ||
{ | ||
const API_BASE_URL = 'https://api.darksky.net/forecast'; | ||
const VALID_UNITS = [ | ||
'auto', | ||
'ca', | ||
'uk2', | ||
'us', | ||
'si' | ||
]; | ||
|
||
const VALID_EXCLUDE = [ | ||
'currently', | ||
'minutely', | ||
'hourly', | ||
'daily', | ||
'alerts', | ||
'flags' | ||
]; | ||
|
||
private $key; | ||
private $latitude; | ||
private $longitude; | ||
private $language; | ||
private $units; | ||
|
||
public function __construct($key, $latitude, $longitude, $lang = 'en', $units = 'auto') | ||
{ | ||
$this->setKey($key); | ||
$this->setLatitude($latitude); | ||
$this->setLongitude($longitude); | ||
$this->setLanguage($lang); | ||
$this->setUnits($units); | ||
} | ||
|
||
public function forecast(array $exclude = [], $extend = false) | ||
{ | ||
try { | ||
return file_get_contents($this->generateRequestUrl($exclude, $extend)); | ||
} catch (\Exception $e) { | ||
throw $e; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
*/ | ||
public function setKey($key) | ||
{ | ||
$this->key = $key; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLatitude() | ||
{ | ||
return $this->latitude; | ||
} | ||
|
||
/** | ||
* @param string $latitude | ||
*/ | ||
public function setLatitude($latitude) | ||
{ | ||
$this->latitude = $latitude; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLongitude() | ||
{ | ||
return $this->longitude; | ||
} | ||
|
||
/** | ||
* @param string $longitude | ||
*/ | ||
public function setLongitude($longitude) | ||
{ | ||
$this->longitude = $longitude; | ||
} | ||
|
||
private function generateRequestUrl(array $exclude = [], $extend = false) | ||
{ | ||
$queryString = [ | ||
'lang' => $this->getLanguage(), | ||
'units' => $this->getUnits() | ||
]; | ||
|
||
if (!empty($exclude)) { | ||
// validate $exclude | ||
foreach ($exclude as $anExclude) { | ||
if (!in_array($anExclude, self::VALID_EXCLUDE)) { | ||
$validExcludes = implode(',', self::VALID_EXCLUDE); | ||
throw new \Exception("'{$anExclude}' is not a valid exclude. Valid excludes: {$validExcludes}'"); | ||
} | ||
} | ||
|
||
$queryString['exclude'] = implode(',', $exclude); | ||
} | ||
|
||
if ($extend === true) { | ||
$queryString['extend'] = 'hourly'; | ||
} | ||
|
||
return self::API_BASE_URL.'/'.$this->getKey().'/'.$this->getLatitude().','.$this->getLongitude() | ||
.'?'.http_build_query($queryString); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLanguage() | ||
{ | ||
return $this->language; | ||
} | ||
|
||
/** | ||
* @param string $language | ||
*/ | ||
public function setLanguage($language) | ||
{ | ||
$this->language = $language; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUnits() | ||
{ | ||
return $this->units; | ||
} | ||
|
||
/** | ||
* @param $units | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function setUnits($units) | ||
{ | ||
if (!in_array($units, self::VALID_UNITS)) { | ||
$validUnits = implode(',', self::VALID_UNITS); | ||
throw new \Exception("'{$units}' is not a valid unit. Valid units: {$validUnits}"); | ||
} | ||
|
||
$this->units = $units; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.