public function testDeleteTestObject() { $data = LeanClient::post("/classes/TestObject", array("name" => "alice", "story" => "in wonderland")); $this->assertArrayHasKey("objectId", $data); LeanClient::delete("/classes/TestObject/{$data['objectId']}"); $obj = LeanClient::get("/classes/TestObject/{$data['objectId']}"); $this->assertEmpty($obj); }
/** * Issue a batch request * * @param array $requests Array of requests in batch op * @param string $sessionToken Session token of a LeanUser * @param array $headers Optional headers * @param bool $useMasterkey Use master key or not, optional * @return array JSON decoded associated array * @see ::request */ public static function batch($requests, $sessionToken = null, $headers = array(), $useMasterKey = false) { $response = LeanClient::post("/batch", array("requests" => $requests), $sessionToken, $headers, $useMasterKey); if (count($requests) != count($response)) { throw new CloudException("Number of resquest and response " . "mismatch in batch operation!"); } return $response; }
public function testBatchGetNotFound() { $obj = array("name" => "alice"); $resp = LeanClient::post("/classes/TestObject", $obj); $this->assertNotEmpty($resp["objectId"]); $req[] = array("path" => "/1.1/classes/TestObject/{$resp['objectId']}", "method" => "GET"); $req[] = array("path" => "/1.1/classes/TestObject/nonexistent_id", "method" => "GET"); $resp2 = LeanClient::batch($req); $this->assertNotEmpty($resp2[0]["success"]); $this->assertEmpty($resp2[1]["success"]); // empty when not found LeanClient::delete("/classes/TestObject/{$resp['objectId']}"); }
/** * Save file on the cloud * * @throws CloudException */ public function save() { if (!$this->isDirty()) { return; } $data = array("name" => $this->getName(), "ACL" => $this->get("ACL"), "mime_type" => $this->getMimeType(), "metaData" => $this->getMeta()); if ($this->isExternal()) { $data["url"] = $this->getUrl(); $resp = LeanClient::post("/files/{$this->getName()}", $data); $this->mergeAfterSave($resp); } else { $key = static::genFileKey(); $key .= "." . pathinfo($this->getName(), PATHINFO_EXTENSION); $data["key"] = $key; $resp = LeanClient::post("/qiniu", $data); $token = $resp["token"]; unset($resp["token"]); $this->mergeAfterSave($resp); LeanClient::uploadToQiniu($token, $this->_source, $key, $this->getMimeType()); } }
public function testUserLogin() { $data = array("username" => "testuser", "password" => "5akf#a?^G", "phone" => "18612340000"); $resp = LeanClient::post("/users", $data); $this->assertNotEmpty($resp["objectId"]); $this->assertNotEmpty($resp["sessionToken"]); $id = $resp["objectId"]; $resp = LeanClient::get("/users/me", array("session_token" => $resp["sessionToken"])); $this->assertNotEmpty($resp["objectId"]); LeanClient::delete("/users/{$id}", $resp["sessionToken"]); // Raise 211: Could not find user. $this->setExpectedException("LeanCloud\\CloudException", null, 211); $resp = LeanClient::get("/users/me", array("session_token" => "non-existent-token")); }
/** * Verify mobile phone by SMS code * * @param string $smsCode */ public static function verifyMobilePhone($smsCode) { LeanClient::post("/verifyMobilePhone/{$smsCode}", null); }