コード例 #1
0
 /**
  * Makes a call to a Cloud function
  *
  * @param string $name Cloud function name
  * @param array  $data Parameters to pass
  * @param boolean $useMasterKey Whether to use the Master Key
  *
  * @return mixed
  */
 public static function run($name, $data = array(), $useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $response = ParseClient::_request('POST', '/1/functions/' . $name, $sessionToken, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey);
     return ParseClient::_decode($response['result']);
 }
コード例 #2
0
ファイル: ParseSession.php プロジェクト: louk/One-Nice-Thing
 /**
  * Retrieves the Session object for the currently logged in user.
  *
  * @param boolean $useMasterKey If the Master Key should be used to override security.
  *
  * @return ParseSession
  */
 public static function getCurrentSession($useMasterKey = false)
 {
     $token = ParseUser::getCurrentUser()->getSessionToken();
     $response = ParseClient::_request('GET', '/1/sessions/me', $token, null, $useMasterKey);
     $session = new ParseSession();
     $session->_mergeAfterFetch($response);
     $session->handleSaveResult();
     return $session;
 }
コード例 #3
0
ファイル: ParseAnalytics.php プロジェクト: uday21/order
 /**
  * Tracks the occurrence of a custom event with additional dimensions.
  * Parse will store a data point at the time of invocation with the given
  * event name.
  *
  * Dimensions will allow segmentation of the occurrences of this custom
  * event. Keys and values should be strings, and will throw
  * otherwise.
  *
  * To track a user signup along with additional metadata, consider the
  * following:
  * <pre>
  * $dimensions = array(
  *  'gender' => 'm',
  *  'source' => 'web',
  *  'dayType' => 'weekend'
  * );
  * ParseAnalytics::track('signup', $dimensions);
  * </pre>
  *
  * There is a default limit of 4 dimensions per event tracked.
  *
  * @param string $name       The name of the custom event
  * @param array  $dimensions The dictionary of segment information
  *
  * @throws \Exception
  * @return mixed
  */
 public static function track($name, $dimensions = array())
 {
     $name = trim($name);
     if (strlen($name) === 0) {
         throw new Exception('A name for the custom event must be provided.');
     }
     foreach ($dimensions as $key => $value) {
         if (!is_string($key) || !is_string($value)) {
             throw new Exception('Dimensions expected string keys and values.');
         }
     }
     return ParseClient::_request('POST', '/1/events/' . $name, null, static::_toSaveJSON($dimensions));
 }
コード例 #4
0
ファイル: ParsePush.php プロジェクト: cocarson/MLink
 /**
  * Sends a push notification.
  *
  * @param array $data The data of the push notification.  Valid fields
  *   are:
  *     channels - An Array of channels to push to.
  *     push_time - A Date object for when to send the push.
  *     expiration_time -  A Date object for when to expire
  *         the push.
  *     expiration_interval - The seconds from now to expire the push.
  *     where - A ParseQuery over ParseInstallation that is used to match
  *         a set of installations to push to.
  *     data - The data to send as part of the push
  * @param boolean $useMasterKey Whether to use the Master Key for the request
  *
  * @throws \Exception, ParseException
  * @return mixed
  */
 public static function send($data, $useMasterKey = false)
 {
     if (isset($data['expiration_time']) && isset($data['expiration_interval'])) {
         throw new \Exception('Both expiration_time and expiration_interval can\'t be set.');
     }
     if (isset($data['where'])) {
         if ($data['where'] instanceof ParseQuery) {
             $data['where'] = $data['where']->_getOptions()['where'];
         } else {
             throw new \Exception('Where parameter for Parse Push must be of type ParseQuery');
         }
     }
     if (isset($data['push_time'])) {
         $data['push_time'] = ParseClient::_encode($data['push_time'], false)['iso'];
     }
     if (isset($data['expiration_time'])) {
         $data['expiration_time'] = ParseClient::_encode($data['expiration_time'], false)['iso'];
     }
     return ParseClient::_request('POST', '/1/push', null, json_encode($data), $useMasterKey);
 }
コード例 #5
0
ファイル: ParsePush.php プロジェクト: jimlai1005/PTFast
 /**
  * Sends a push notification.
  *
  * @param array   $data         The data of the push notification.    Valid fields
  *                              are:
  *                              channels - An Array of channels to push to.
  *                              push_time - A Date object for when to send the push.
  *                              expiration_time -    A Date object for when to expire
  *                              the push.
  *                              expiration_interval - The seconds from now to expire the push.
  *                              where - A ParseQuery over ParseInstallation that is used to match
  *                              a set of installations to push to.
  *                              data - The data to send as part of the push
  * @param boolean $useMasterKey Whether to use the Master Key for the request
  *
  * @throws \Exception, ParseException
  *
  * @return mixed
  */
 public static function send($data, $useMasterKey = false)
 {
     if (isset($data['expiration_time']) && isset($data['expiration_interval'])) {
         throw new \Exception('Both expiration_time and expiration_interval can\'t be set.');
     }
     if (isset($data['where'])) {
         if ($data['where'] instanceof ParseQuery) {
             $data['where'] = $data['where']->_getOptions()['where'];
         } else {
             throw new \Exception('Where parameter for Parse Push must be of type ParseQuery');
         }
     }
     if (isset($data['push_time'])) {
         //Local push date format is different from iso format generally used in Parse
         //Schedule does not work if date format not correct
         $data['push_time'] = ParseClient::getLocalPushDateFormat($data['push_time']);
     }
     if (isset($data['expiration_time'])) {
         $data['expiration_time'] = ParseClient::_encode($data['expiration_time'], false)['iso'];
     }
     return ParseClient::_request('POST', '/1/push', null, json_encode($data), $useMasterKey);
 }
コード例 #6
0
ファイル: ParseUser.php プロジェクト: louk/One-Nice-Thing
 /**
  * Requests a password reset email to be sent to the specified email
  * address associated with the user account.    This email allows the user
  * to securely reset their password on the Parse site.
  *
  * @param string $email
  *
  * @return null
  */
 public static function requestPasswordReset($email)
 {
     $json = json_encode(['email' => $email]);
     ParseClient::_request('POST', '/1/requestPasswordReset', null, $json);
 }
コード例 #7
0
ファイル: ParseQuery.php プロジェクト: raxjethvaa/HTML
 /**
  * Execute a find query and return the results.
  *
  * @param boolean $useMasterKey
  *
  * @return array
  */
 public function find($useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $queryString = $this->buildQueryString($this->_getOptions());
     $result = ParseClient::_request('GET', '/1/classes/' . $this->className . '?' . $queryString, $sessionToken, null, $useMasterKey);
     $output = array();
     foreach ($result['results'] as $row) {
         $obj = ParseObject::create($this->className, $row['objectId']);
         $obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys);
         $output[] = $obj;
     }
     return $result;
 }
コード例 #8
0
 /**
  * You can change your app's name, as well as change your app's settings.
  *
  * @param string $application_id
  * @param array  $data
  *
  * @throws ParseException
  *
  * @return array
  */
 public static function updateApp($application_id, array $data)
 {
     $result = ParseClient::_request('PUT', 'apps/' . $application_id, null, json_encode($data), false, true);
     return $result;
 }
コード例 #9
0
 /**
  * Creates
  */
 public function __construct()
 {
     $result = ParseClient::_request("GET", "/1/config");
     $this->setConfig($result['params']);
 }
コード例 #10
0
ファイル: ParseObject.php プロジェクト: uday21/order
 /**
  * Save Object and unsaved children within.
  *
  * @param $target
  * @param bool   $useMasterKey Whether to use the Master Key.
  *
  * @return null
  *
  * @throws ParseException
  */
 private static function deepSave($target, $useMasterKey = false)
 {
     $unsavedChildren = array();
     $unsavedFiles = array();
     static::findUnsavedChildren($target, $unsavedChildren, $unsavedFiles);
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     foreach ($unsavedFiles as &$file) {
         $file->save();
     }
     $objects = array();
     // Get the set of unique objects among the children.
     foreach ($unsavedChildren as &$obj) {
         if (!in_array($obj, $objects, true)) {
             $objects[] = $obj;
         }
     }
     $remaining = $objects;
     while (count($remaining) > 0) {
         $batch = array();
         $newRemaining = array();
         foreach ($remaining as $key => &$object) {
             if (count($batch) > 40) {
                 $newRemaining[] = $object;
                 continue;
             }
             if ($object->canBeSerialized()) {
                 $batch[] = $object;
             } else {
                 $newRemaining[] = $object;
             }
         }
         $remaining = $newRemaining;
         if (count($batch) === 0) {
             throw new Exception("Tried to save a batch with a cycle.");
         }
         $requests = array();
         foreach ($batch as $obj) {
             $json = $obj->getSaveJSON();
             $method = 'POST';
             $path = '/1/classes/' . $obj->getClassName();
             if ($obj->getObjectId()) {
                 $path .= '/' . $obj->getObjectId();
                 $method = 'PUT';
             }
             $requests[] = array('method' => $method, 'path' => $path, 'body' => $json);
         }
         if (count($requests) === 1) {
             $req = $requests[0];
             $result = ParseClient::_request($req['method'], $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey);
             $batch[0]->mergeAfterSave($result);
         } else {
             $result = ParseClient::_request('POST', '/1/batch', $sessionToken, json_encode(array("requests" => $requests)), $useMasterKey);
             $errorCollection = array();
             foreach ($batch as $key => &$obj) {
                 if (isset($result[$key]['success'])) {
                     $obj->mergeAfterSave($result[$key]['success']);
                 } else {
                     if (isset($result[$key]['error'])) {
                         $response = $result[$key];
                         $error = $response['error']['error'];
                         $code = isset($response['error']['code']) ? $response['error']['code'] : -1;
                         $errorCollection[] = array('error' => $error, 'code' => $code, 'object' => $obj);
                     } else {
                         $errorCollection[] = array('error' => 'Unknown error in batch save.', 'code' => -1, 'object' => $obj);
                     }
                 }
             }
             if (count($errorCollection)) {
                 throw new ParseAggregateException("Errors during batch save.", $errorCollection);
             }
         }
     }
 }
コード例 #11
0
ファイル: ParseCloud.php プロジェクト: borisavilov/Web
 /**
  * Makes a call to a Cloud function
  *
  * @param string $name Cloud function name
  * @param array  $data Parameters to pass
  * @param boolean $useMasterKey Whether to use the Master Key
  *
  * @return mixed
  */
 public static function run($name, $data = array(), $useMasterKey = false)
 {
     $response = ParseClient::_request('POST', '/1/functions/' . $name, null, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey);
     return ParseClient::_decode($response['result']);
 }
コード例 #12
0
ファイル: ParseConfig.php プロジェクト: aglo35/vr_beta
 /**
  * Creates.
  */
 public function __construct()
 {
     $result = ParseClient::_request('GET', 'config');
     $this->setConfig($result['params']);
 }
コード例 #13
0
ファイル: ParseHooks.php プロジェクト: aglo35/vr_beta
 /**
  * Delete a trigger webhook.
  *
  * @param string $className
  * @param string $triggerName
  *
  * @return array
  */
 public function deleteTrigger($className, $triggerName)
 {
     $result = ParseClient::_request('PUT', 'hooks/triggers/' . $className . '/' . $triggerName, null, json_encode(['__op' => 'Delete']), true);
     return $result;
 }