/**
* Create user cache.
*
* @param string $user Twitter screen name
* @return bool If successful true
* @throws CacheException Any errors
*/
public function create($user)
{
try {
$path = config("cache.path") . "/{$user}";
$json_file = "{$path}/data.json";
if (!$this->exists($user)) {
mkdir($path);
}
if (!file_exists($json_file)) {
touch($json_file);
}
$response = $this->twistOAuth->get("users/show", ["id" => $user]);
$image_url = str_replace("_normal", "", $response->profile_image_url_https);
$info = new SplFileInfo($image_url);
$curl = new Curl();
$curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION);
$curl->download($image_url, "{$path}/icon.{$info->getExtension()}");
$curl->close();
$data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()];
$json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
(new SplFileObject($json_file, "w"))->fwrite($json);
return true;
} catch (RuntimeException $e) {
$this->_catch($e);
}
}