Skip to content

Commit

Permalink
Updating code style, README and the license
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardfischer committed Jan 24, 2018
1 parent 860a22c commit 850705c
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 395 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Leonard Fischer
Copyright (c) 2018 Leonard Fischer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ At some point I'd like to improve this client to be as readable as possible. For

```php
use lfischer\wunderground;

$weather = (new API('<API-key here>'))
->getConditions()
->byLocation('Germany', 'Dusseldorf')
->fetch()
->asArray();
```
->asArray();
```

## Contributors

- **Leonard Fischer** - initial programming [Github profile](https://github.com/leonardfischer)
- **Stefano Borghi** - writing tests and improving code [Github profile](https://github.com/stebogit)
251 changes: 121 additions & 130 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,133 +11,124 @@
*/
class API extends Request
{
/**
* Retrieves weather data by a weather station ID.
* See https://www.wunderground.com/wundermap/ for more information
*
* @param string $id
* @return array
* @throws \ErrorException
*/
public function getByPWSId ($id)
{
return $this->fetch(['query' => 'pws:' . $id])->getResponseArray();
} // function


/**
* Retrieves weather data by a airport code.
*
* @param string $code
* @return array
* @throws \ErrorException
*/
public function getByAirportCode ($code)
{
return $this->fetch(['query' => $code])->getResponseArray();
} // function


/**
* Retrieves weather data by geo coordinates.
*
* @param float $lat
* @param float $lng
* @return array
* @throws \ErrorException
*/
public function getByCoordinates ($lat, $lng)
{
return $this->fetch(['query' => $lat . ',' . $lng])->getResponseArray();
} // function


/**
* Retrieves weather data by a given country and city name.
*
* @param string $country
* @param string $city
* @return array
* @throws \ErrorException
*/
public function getByLocation ($country, $city)
{
return $this->fetch(['query' => $country . '/' . $city])->getResponseArray();
} // function


/**
* Retrieves weather data by a given country and city name.
*
* @param string|int $zipcode
* @return array
* @throws \ErrorException
*/
public function getByUSZipcode ($zipcode)
{
return $this->fetch(['query' => $zipcode])->getResponseArray();
} // function


/**
* Retrieves weather data by a given country and city name.
*
* @param string $state
* @param string $city
* @return array
* @throws \ErrorException
*/
public function getByUSCity ($state, $city)
{
$c = str_replace(' ', '_', $city);
return $this->fetch(['query' => $state . '/' . $c])->getResponseArray();
} // function


/**
* Retrieves hourly and daily weather forecast data by a given location (country+city, coordinates,
* zipcode, etc) for the next three days (daily records) or 36 hours (hourly records).
* Daily records will include today, hourly records will include the current hour.
*
* @param string $location any valid Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getForecast ($location)
{
return $this->setFeatures(['forecast', 'hourly'])->setQuery($location)->fetch()->getResponseArray();
} // function


/**
* Retrieves hourly and daily weather forecast data by a given
* location (country+city, coordinates, zipcode, etc) for the next 10 days.
* Daily records will include today, hourly records will include the current hour.
*
* @param string $location Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getExtendedForecast ($location)
{
return $this->setFeatures(['forecast10day', 'hourly10day'])->setQuery($location)->fetch()->getResponseArray();
} // function


/**
* Retrieves observed weather records and the daily summary for the specified date.
*
* @param string $date any valid {@link http://php.net/manual/en/datetime.formats.date.php Date Formats} format
* @param string $location Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getHistoric ($date, $location)
{
$d = date('Ymd', strtotime($date));

return $this->setFeature("history_$d")->setQuery($location)->fetch()->getResponseArray();
} // function


} // class
/**
* Retrieves weather data by a weather station ID.
* See https://www.wunderground.com/wundermap/ for more information
*
* @param string $id
* @return array
* @throws \ErrorException
*/
public function getByPWSId($id)
{
return $this->fetch(['query' => 'pws:' . $id])->getResponseArray();
}

/**
* Retrieves weather data by a airport code.
*
* @param string $code
* @return array
* @throws \ErrorException
*/
public function getByAirportCode($code)
{
return $this->fetch(['query' => $code])->getResponseArray();
}

/**
* Retrieves weather data by geo coordinates.
*
* @param float $lat
* @param float $lng
* @return array
* @throws \ErrorException
*/
public function getByCoordinates($lat, $lng)
{
return $this->fetch(['query' => $lat . ',' . $lng])->getResponseArray();
}

/**
* Retrieves weather data by a given country and city name.
*
* @param string $country
* @param string $city
* @return array
* @throws \ErrorException
*/
public function getByLocation($country, $city)
{
return $this->fetch(['query' => $country . '/' . $city])->getResponseArray();
}

/**
* Retrieves weather data by a given country and city name.
*
* @param string|int $zipcode
* @return array
* @throws \ErrorException
*/
public function getByUSZipcode($zipcode)
{
return $this->fetch(['query' => $zipcode])->getResponseArray();
}

/**
* Retrieves weather data by a given country and city name.
*
* @param string $state
* @param string $city
* @return array
* @throws \ErrorException
*/
public function getByUSCity($state, $city)
{
$c = str_replace(' ', '_', $city);

return $this->fetch(['query' => $state . '/' . $c])->getResponseArray();
}

/**
* Retrieves hourly and daily weather forecast data by a given location (country+city, coordinates,
* zipcode, etc) for the next three days (daily records) or 36 hours (hourly records).
* Daily records will include today, hourly records will include the current hour.
*
* @param string $location any valid Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getForecast($location)
{
return $this->setFeatures(['forecast', 'hourly'])->setQuery($location)->fetch()->getResponseArray();
}

/**
* Retrieves hourly and daily weather forecast data by a given
* location (country+city, coordinates, zipcode, etc) for the next 10 days.
* Daily records will include today, hourly records will include the current hour.
*
* @param string $location Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getExtendedForecast($location)
{
return $this->setFeatures(['forecast10day', 'hourly10day'])->setQuery($location)->fetch()->getResponseArray();
}

/**
* Retrieves observed weather records and the daily summary for the specified date.
*
* @param string $date any valid {@link http://php.net/manual/en/datetime.formats.date.php Date Formats} format
* @param string $location Country/City, Lat,Lon, Airport code, etc.
* @return array
* @throws \ErrorException
*/
public function getHistoric($date, $location)
{
$d = date('Ymd', strtotime($date));

return $this->setFeature("history_$d")->setQuery($location)->fetch()->getResponseArray();
}
}
Loading

0 comments on commit 850705c

Please sign in to comment.