/** * Fetch file object by id * * Note it fetches descriptive data from LeanCloud, but not file content. * The content should be fetched from file URL. * * @return File */ public static function fetch($objectId) { $file = new File(""); $resp = Client::get("/files/{$objectId}"); $file->mergeAfterFetch($resp); return $file; }
/** * Doing a CQL query to retrive objects * * It returns an array that contains: * * * className - Class name of the query * * results - List of objects * * count - Number of objects when it's a count query * * @param string $cql CQL statement * @param array $pvalues Positional values to replace in CQL * @return array * @link https://leancloud.cn/docs/cql_guide.html */ public static function doCloudQuery($cql, $pvalues = array()) { $data = array("cql" => $cql); if (!empty($pvalues)) { $data["pvalues"] = json_encode(Client::encode($pvalues)); } $resp = Client::get('/cloudQuery', $data); $objects = array(); foreach ($resp["results"] as $val) { $obj = Object::create($resp["className"], $val["objectId"]); $obj->mergeAfterFetch($val); $objects[] = $obj; } $resp["results"] = $objects; return $resp; }
public function testDeleteTestObject() { $data = Client::post("/classes/TestObject", array("name" => "alice", "story" => "in wonderland")); $this->assertArrayHasKey("objectId", $data); Client::delete("/classes/TestObject/{$data['objectId']}"); $obj = Client::get("/classes/TestObject/{$data['objectId']}"); $this->assertEmpty($obj); }
public function testUserLogin() { $data = array("username" => "testuser", "password" => "5akf#a?^G", "phone" => "18612340000"); $resp = Client::post("/users", $data); $this->assertNotEmpty($resp["objectId"]); $this->assertNotEmpty($resp["sessionToken"]); $id = $resp["objectId"]; $resp = Client::get("/users/me", array("session_token" => $resp["sessionToken"])); $this->assertNotEmpty($resp["objectId"]); Client::delete("/users/{$id}", $resp["sessionToken"]); // Raise 211: Could not find user. $this->setExpectedException("LeanCloud\\CloudException", null, 211); $resp = Client::get("/users/me", array("session_token" => "non-existent-token")); }
/** * Log-in user by mobile phone and SMS code. * * Log-in user with SMS code, which can be requested by * `requestLoginSmsCode`. It will set current user. * * @param string $phoneNumber Registered mobile phone number * @param string $smsCode * @return User */ public static function logInWithSmsCode($phoneNumber, $smsCode) { $params = array("mobilePhoneNumber" => $phoneNumber, "smsCode" => $smsCode); $resp = Client::get("/login", $params); $user = new static(); $user->mergeAfterFetch($resp); static::saveCurrentUser($user); return $user; }