本文整理汇总了PHP中API::get方法的典型用法代码示例。如果您正苦于以下问题:PHP API::get方法的具体用法?PHP API::get怎么用?PHP API::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNewItemAttachment
public function testNewItemAttachment()
{
$response = API::get("items/new?itemType=attachment");
$this->assert400($response);
$response = API::get("items/new?itemType=attachment&linkMode=invalidLinkMode");
$this->assert400($response);
$response = API::get("items/new?itemType=attachment&linkMode=linked_url");
$this->assert200($response);
$json = json_decode($response->getBody());
$this->assertNotNull($json);
$this->assertObjectHasAttribute('url', $json);
$response = API::get("items/new?itemType=attachment&linkMode=linked_file");
$this->assert200($response);
$json = json_decode($response->getBody());
$this->assertNotNull($json);
$this->assertObjectNotHasAttribute('url', $json);
}
示例2: Donation
}
$donations = new Donation();
$donation_id = $donations->add($QUERY);
if ($donation_id) {
showSuccess("Donation inserted succesfully : Donation ID '.{$donation_id}.'", array("donation" => array("id" => $donation_id)));
} else {
showError("Failure in insterting dontaion at server. Try again after some time.");
}
});
$api->get('/donation/get_donations_for_approval/{poc_id}', function ($poc_id) {
$donation = new Donation();
$donations_for_approval = $donation->getDonationsForApproval($poc_id);
if ($donations_for_approval) {
showSuccess(count($donations_for_approval) . " donation(s) waiting for approval", array('donations' => $donations_for_approval));
} else {
$error = $donation->error;
if (!$error) {
$error = "Can't find any donations that need approval for this user";
}
showError($error);
}
});
$api->get('/donation/{donation_id}/approve/{poc_id}', function ($donation_id, $poc_id) {
$donation = new Donation();
$donation->approveDonation($donation_id, $poc_id);
showSuccess("Donation approved", array('donation_id' => $donation_id));
});
$api->request("/user/login", function () {
global $QUERY;
$user = new User();
$phone = i($QUERY, 'phone');
示例3: testNewAttachmentItemModTimeOnLinkedURL
/**
* @depends testNewEmptyBookItem
*/
public function testNewAttachmentItemModTimeOnLinkedURL($newItemData)
{
$parentKey = $newItemData['key'];
$response = API::get("items/new?itemType=attachment&linkMode=linked_url");
$json = json_decode($response->getBody());
$json->mtime = "1332807793000";
$response = API::userPost(self::$config['userID'], "items/{$parentKey}/children?key=" . self::$config['apiKey'], json_encode(array("items" => array($json))), array("Content-Type: application/json"));
$this->assert400($response);
$this->assertEquals("'mtime' is valid only for imported attachment items", $response->getBody());
}
示例4: testEditCategoryWithNullWithPost
public function testEditCategoryWithNullWithPost()
{
$test = new API($this);
$test->put('/categories/2', 'icon__is_null');
$test->expect('1');
$test->get('/categories/2');
$test->expect('{"id":"2","name":"article","icon":null}');
}
示例5: getRelationById
/**
* @param $objectName
* @return mixed
* @throws Exception
*/
public function getRelationById($objectName)
{
if (!isset(static::$relationList[$objectName])) {
throw new Exception("unknown relation : " . $objectName);
}
if (!isset($this->_relations[$objectName])) {
$repo = API::get(static::$relationList[$objectName]['class']);
$fieldName = static::$relationList[$objectName]['field'];
$this->_relations[$objectName] = $repo->find($this->{$fieldName});
}
return $this->_relations[$objectName];
}
示例6: foreach
if (isset($_GET["platform"])) {
$platform = $_GET["platform"];
// If OAuth 1 use oauth_token + oauth_verifier
if (in_array($platform, $platforms["oauth1"])) {
$code = "{$_GET["oauth_token"]}:{$_GET["oauth_verifier"]}";
// If OAuth 2 use code + state
} else {
$code = "{$_GET["code"]}:{$_GET["state"]}";
}
$authDetails = $http->post("/v1/auth/social", ["session_id" => $fakeSessionID, "code" => $code, "platform" => $platform]);
if ($authDetails) {
$auth = $http->post("/v1/auth", ["client_id" => "oauthclientid", "client_secret" => "blahblahblah", "grant_type" => "password", "username" => $authDetails->user_id, "password" => $authDetails->token]);
}
var_dump($auth);
} else {
$socialLoginUrls = $http->get("/v1/auth/social/urls", ["session_id" => $fakeSessionID]);
?>
<h1>Logins</h1>
<ul>
<?php
foreach ($socialLoginUrls as $platform => $url) {
?>
<li><a href="<?php
echo $url;
?>
"><?php
echo $platform;
?>
</a></li>
示例7: testSanitizerToStripTags
public function testSanitizerToStripTags()
{
$test = new API($this);
$test->put('/categories/2', '{"name":"<script>alert();</script>"}');
$test->expect('1');
$test->get('/categories/2');
$test->expect('{"id":"2","name":"alert();","icon":null}');
}
示例8: getChannelUpdates
/**
* Send the HTTP request, return the
*
* @param string $root
* @return array
*/
protected function getChannelUpdates(string $root) : array
{
$state = State::instance();
if (IDE_HACKS) {
$state->hail = new Hail(new Client());
}
foreach ($this->getChannelURLs() as $url) {
$initiated = new \DateTime('now');
$response = $state->hail->postSignedJSON($url . API::get('fetch_keys') . '/' . $root, $this->channelPublicKey);
try {
// We use a separate method for parsing this update:
return $this->parseChannelUpdateResponse($response, $initiated);
} catch (CouldNotUpdate $ex) {
// Log the error message:
$this->log($ex->getMessage(), LogLevel::ALERT, \Airship\throwableToArray($ex));
// continue;
}
}
// When all else fails, TransferException
throw new TransferException(\__("All else has failed."));
}
示例9: groupCreateAttachmentItem
public function groupCreateAttachmentItem($groupID, $linkMode, $parentKey = false, $context = false)
{
self::loadConfig();
$response = API::get("items/new?itemType=attachment&linkMode={$linkMode}");
$json = json_decode($response->getBody());
if ($parentKey) {
$url = "items/{$parentKey}/children";
} else {
$url = "items";
}
$response = API::groupPost($groupID, $url . "?key=" . self::$config['apiKey'], json_encode(array("items" => array($json))), array("Content-Type: application/json"));
if ($context) {
$context->assert201($response);
}
$xml = API::getXMLFromResponse($response);
$data = API::parseDataFromItemEntry($xml);
if ($context) {
$json = json_decode($data['content']);
$context->assertEquals($linkMode, $json->linkMode);
}
return $xml;
}
示例10: testForJsonpCallbackOnList
public function testForJsonpCallbackOnList()
{
$test = new API($this);
$test->get('/posts?filter[]=id,eq,1&callback=test_jsonp_fn&transform=1');
$test->expect('test_jsonp_fn({"posts":[{"id":"1","user_id":"1","category_id":"1","content":"blog started"}]});');
}
示例11: fetchTreeUpdates
/**
* Fetch all of the updates from the remote server.
*
* @param Channel $chan
* @param string $url
* @param string $root Which Merkle root are we starting at?
* @return TreeUpdate[]
*/
protected function fetchTreeUpdates(Channel $chan, string $url, string $root) : array
{
try {
return $this->parseTreeUpdateResponse($chan, $this->hail->getSignedJSON($url . API::get('fetch_keys') . '/' . $root, $chan->getPublicKey()));
} catch (SignatureFailed $ex) {
$state = State::instance();
if (IDE_HACKS) {
$state->logger = new Ledger();
}
$state->logger->alert('Signature failed!', \Airship\throwableToArray($ex));
}
return [];
}
示例12: testMissingIntermediateTable
public function testMissingIntermediateTable()
{
$test = new API($this);
$test->get('/users,posts,tags');
$test->expect('{"users":{"columns":["id","username"],"records":[["1","user1"],["2","user2"]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[["1","1","1","blog started"],["2","1","2","\\u20ac Hello world, \\u039a\\u03b1\\u03bb\\u03b7\\u03bc\\u1f73\\u03c1\\u03b1 \\u03ba\\u1f79\\u03c3\\u03bc\\u03b5, \\u30b3\\u30f3\\u30cb\\u30c1\\u30cf"],["5","1","1","#1"],["6","1","1","#2"],["7","1","1","#3"],["8","1","1","#4"],["9","1","1","#5"],["10","1","1","#6"],["11","1","1","#7"],["12","1","1","#8"],["13","1","1","#9"],["14","1","1","#10"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[["1","1","1"],["2","1","2"],["3","2","1"],["4","2","2"]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[["1","funny"],["2","important"]]}}');
}
示例13: failed
/*
Create Customer - Bradly
*/
$result = $API->post('customer', $Bradly, "Creating Bradly");
if ($result->error) {
failed("Didn't return customer: " . $result->message . "\n" . json_encode($result->data));
}
foreach ($Bradly as $key => $value) {
$API->test($result->data->{$key}, $value, $key);
}
$Bradly['id'] = $result->data->id;
logMessage("Bradly ID: " . $Bradly['id']);
/*
Get Customer - Warren
*/
$result = $API->get('customer/' . $Warren['id'], "Getting Warren - ID: " . $Warren['id']);
if ($result->error) {
failed("Didn't return customer: " . $result->message . "\n" . json_encode($result->data));
}
foreach ($Warren as $key => $value) {
$API->test($result->data->{$key}, $value, $key);
}
/*
Update Customer - Warren
Set City to Warrnambool
*/
$Warren['city'] = 'Warrnambool';
$result = $API->put('customer/' . $Warren['id'], array('city' => $Warren['city']), "Updating Warren - City: " . $Warren['city']);
if ($result->error) {
failed("Didn't return customer: " . $result->message . "\n" . json_encode($result->data));
}
示例14: Exception
$app->notFound(function () {
throw new Exception("This endpoint does not exist", 404);
});
/*======================================================================================================================
* ROUTES
* Main endpoints of the API
* The HTTP method is determined by the method called by the $app object (ie. "$app->post()")
* The first parameter is the url path from the api
*
* EXAMLPE: GET https://api.soccerwars.xyz/users/2 will map to the route
* $app->get('/users/:id', function($id) ... Where $id will have the value '2'
=====================================================================================================================*/
/* API root
**********************************************************************************************************************/
$app->get('/', function () use($app) {
$app->render_json(["message" => "SoccerWars API v0.1"]);
});
/* Check login credentials
**********************************************************************************************************************/
$app->post('/login', function () use($app) {
$data = json_decode($app->request->getBody(), true);
if ($user_id = User::Login($data['email'], $data['password'])) {
$user = User::Get($user_id);
// Activate account if it's the first login and forbid inactive accounts
if ($user->status == 'pending') {
$user->setStatus('active');
} else {
if ($user->status != 'active') {
throw new Exception("This account is not active", 401);
}
}