/** * Request APi to get last photos * @param int $quantity Number of photos to return * @return string[] Photo download links indexed by IDs */ public function allPhotos($quantity) { $photos = []; foreach (Photo::all(1, $quantity) as $photo) { $photos[$photo->id] = $photo->links['download']; } return $photos; }
public function testRandomPhotoWithFilters() { VCR::insertCassette('photos.yml'); $filters = ['category' => [2, 3], 'featured' => true, 'username' => 'andy_brunner', 'query' => 'ice', 'w' => 100, 'h' => 100]; $photo = Unsplash\Photo::random($filters); VCR::eject(); $this->assertEquals('ZUaqqMxtxYk', $photo->id); $this->assertEquals('https://unsplash.imgix.net/photo-1428681756973-d318f055795a?q=75&fm=jpg&w=100&h=100&fit=max&s=b223d24e28ba1ced6731e98d46cd5f83', $photo->urls['custom']); }
public function testUnlikePhoto() { VCR::insertCassette('photos.yml'); $photo = Unsplash\Photo::find('j0g8taxHZa0'); $like = $photo->like(); $unlike = $photo->unlike(); VCR::eject(); $this->assertTrue($unlike); }
protected function generate($year, $month) { HttpClient::init(['applicationId' => env('IMG_ID'), 'secret' => env('IMG_SECRET')]); $date = Carbon::now(); $date->year = $year; $date->month = $month; $date->startOfMonth(); $end = $date->copy()->endOfMonth(); while ($date->lte($end)) { $random = uPhoto::random(); $link = $random->links['html']; $image = $random->urls['thumb']; Photo::create(['date' => $date->toDateString(), 'link' => $link, 'image' => $image]); $date->addDays(1); } return redirect('view/' . $year . '/' . $month); }