/** * Commit batch * * @throws \Exception */ public function commit() { $response = $this->api->put('/v4/batch', ['batch-id' => $this->getBatchId()]); if (!isset($response['success']) || !$response['success']) { throw new \Exception("Response was not successful."); } $this->isCommitted = true; }
/** * Creates and returns a new token/api_key combination for the * specified user ID. Returns an array with the two values. Note * that for an existing user ID, this will generate a new pair, * replacing the old values and making them no longer valid for * API access. */ public static function create_token($user_id) { $a = self::query()->where('user_id', $user_id)->single(); if ($a && !$a->error) { $a->token = md5(uniqid(mt_rand(), 1)); $a->api_key = md5(uniqid(mt_rand(), 1)); } else { $a = new Api(array('token' => md5(uniqid(mt_rand(), 1)), 'api_key' => md5(uniqid(mt_rand(), 1)), 'user_id' => $user_id)); } while (!$a->put()) { $a->token = md5(uniqid(mt_rand(), 1)); } return array($a->token, $a->api_key); }
/** * Creates and returns a new token/api_key combination for the * specified user ID. Returns an array with the two values. Note * that for an existing user ID, this will generate a new pair, * replacing the old values and making them no longer valid for * API access. */ public static function create_token($user_id) { $a = Api::query()->where('user_id', $user_id)->fetch(); if (count($a) > 0) { $a = $a[0]; $a->token = md5(uniqid(mt_rand(), 1)); $a->api_key = md5(uniqid(mt_rand(), 1)); } else { $a = new Api(array('token' => md5(uniqid(mt_rand(), 1)), 'api_key' => md5(uniqid(mt_rand(), 1)), 'user_id' => $user_id)); } while (!$a->put()) { $a->token = md5(uniqid(mt_rand(), 1)); } return array($a->token, $a->api_key); }
public function action_view() { $id = (int) $this->request->param('id'); $user_id = Auth::get_id(); $message = Api::get('user-messages.get_by_id', array('id' => $id, 'uid' => $user_id, 'fields' => 'author,title,is_read,created_on,text,is_starred'))->as_object(); if (!$message->response) { throw new HTTP_Exception_404('Message not found'); } if ($this->request->method() === Request::POST) { $this->auto_render = FALSE; $post = $this->request->post(); $post['from_user_id'] = $user_id; $post['parent_id'] = $id; return $this->_send(Api::put('user-messages', $post), $id); } $read = Api::post('user-messages.mark_read', array('id' => $id, 'uid' => $user_id)); $messages = Api::get('user-messages.get', array('uid' => $user_id, 'fields' => 'author,from_user_id,title,is_read,created_on,text,is_starred', 'pid' => $id))->as_object(); $this->template->content = View::factory('messages/view', array('tpl' => View::factory('messages/item'), 'message' => $message->response, 'messages' => $messages->response, 'from_user' => ORM::factory('user', $message->response->from_user_id))); $this->set_title($message->response->title); }
<?php require __DIR__ . '/credentials.php'; require __DIR__ . '/../facturama/Api.php'; $facturma = new Api(USER, PASSWORD); $clientId = 'TGpJ_Ko32_ZSEPBcZXRnRw2'; /*$params = [ 'id' => $clientId ];*/ $body = ["Id" => $clientId, "Address" => ["Street" => "St One", "ExteriorNumber" => "15", "InteriorNumber" => "12", "Neighborhood" => "Lower Manhattan, ", "ZipCode" => "sample string 5", "Locality" => "sample string 6", "Municipality" => "sample string 7", "State" => "sample string 8", "Country" => "MX"], "Rfc" => "XEXX010101000", "Name" => "Test Test 2", "Email" => "*****@*****.**"]; //$result = $facturma->put('Client/' . $clientId, $body, $params); $result = $facturma->put('Client/' . $clientId, $body); printf('<pre>%s<pre>', var_export($result, true));