コード例 #1
0
ファイル: API.class.php プロジェクト: performics/ga-cli-api
 /**
  * Creates a location and returns the new location as returned from the
  * API.
  *
  * @param Google\MyBusiness\Location $location
  * @param Google\MyBusiness\Account $account = null
  * @param boolean $dryRun = false
  */
 public function createLocation(Location $location, Account $account = null, $dryRun = false)
 {
     $ownerAccountID = $location->getOwnerAccountID();
     if (strlen($ownerAccountID)) {
         $account = new Account();
         $account->setID($ownerAccountID);
     } elseif ($account) {
         self::_validateID($account);
     } else {
         $account = $this->_getCachedAccount();
     }
     if ($location->getID() !== null) {
         throw new InvalidArgumentException('A new location may not already contain an ID.');
     }
     /* Even if the creation of new locations is disabled, we'll still allow
        dry runs. */
     if (!GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS && !$dryRun) {
         throw new RuntimeException('Cannot create new locations unless the ' . 'GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS setting is ' . 'defined as true.');
     }
     $requestBody = array('location' => $location->toREST(), 'languageCode' => $location->getLanguageCode(), 'validateOnly' => $dryRun, 'requestId' => $location->getHash());
     $request = new APIRequest($account->getName() . '/locations');
     $request->setPayload(json_encode($requestBody));
     $this->_parseCallback = '_parseLocationResponse';
     return $this->_makeRequest($request);
 }