Skip to content

Commit

Permalink
Simplified methods
Browse files Browse the repository at this point in the history
  • Loading branch information
grubersjoe committed May 28, 2018
1 parent fc398b8 commit a91cf1d
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions BingPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class BingPhoto
/**
* Constructor: Fetches image(s) of the day from Bing
* @param array $args Options array
* $args['n'] int Number of images / days
* $args['cacheDir'] string Cache (download) images in this directory
* $args['date'] intDate offset. 0 equals today, 1 = yesterday, and so on.
* $args['locale'] string Localization string (en-US, de-DE, ...)
* $args['n'] int Number of images / days
* $args['quality'] string Resolution of images(s)
* $args['cacheDir'] string Cache (download) images in this directory
* @throws Exception
*/
public function __construct(array $args = [])
Expand Down Expand Up @@ -130,7 +130,8 @@ private function sanitizeArgs(array $args)
*/
private function fetchImagesMetadata()
{
$url = $this->buildApiUrl($this->args['date'], $this->args['n'], $this->args['locale']);
$url = sprintf(self::BASE_URL . self::JSON_URL . '&idx=%d&n=%d&mkt=%s',
$this->args['date'], $this->args['n'], $this->args['locale']);
$data = json_decode(file_get_contents($url), true);
$error = json_last_error();

Expand Down Expand Up @@ -234,18 +235,6 @@ private function readRunfile()
}
}

/**
* Build the API URL
* @param int $date The date offset
* @param int $n Number of images to fetch
* @param int $locale Locale code
* @return string The URL to the JSON endpoint
*/
private function buildApiUrl($date, $n, $locale)
{
return sprintf(self::BASE_URL . self::JSON_URL . '&idx=%d&n=%d&mkt=%s', $date, $n, $locale);
}

/**
* Changes relative to absolute URLs
*/
Expand Down

0 comments on commit a91cf1d

Please sign in to comment.