protected function load() { $result = $this->api->get($this->method, array_merge($this->params, array('limit' => $this->limit, 'offset' => $this->offset)))->getResult(); $this->meta = $result['_meta'] ?: array('limit' => $this->limit, 'offset' => $this->offset, 'count' => 0); $this->results = $result['results']->getArrayCopy() ?: array(); if ($this->meta['limit'] < $this->limit) { $this->limit = $this->meta['limit']; } if (empty($this->results)) { $this->finished = true; } }
public function run() { $reqId = (int) $this->httpRequest->postData('id'); $reqsData = json_decode($this->httpRequest->postData('data'), true); if (json_last_error() !== JSON_ERROR_NONE) { //Try with stripslashes() $reqsData = json_decode(stripslashes($this->httpRequest->postData('data')), true); if (json_last_error() !== JSON_ERROR_NONE) { $errMsg = '#' . json_last_error(); if (function_exists('json_last_error_msg')) { $errMsg .= ' ' . json_last_error_msg(); } throw new \RuntimeException('Malformed JSON-encoded request (' . $errMsg . ')', 400); } } $responses = array(); foreach ($reqsData as $requestData) { $apiCall = new Api(); $apiCall->emulate($requestData, $this->httpRequest); $apiCall->run(); $responses[] = $apiCall->httpResponse()->content(); } $resp = new ApiGroupResponse(); $resp->setResponses($responses); $resp->setId($reqId); $this->httpResponse->addHeader('Content-Type: application/json'); if ($resp->cacheable()) { $this->httpResponse->setCacheable(); } $this->httpResponse->setContent($resp); }
public function run() { if (!$this->_canRun) { return; } $channelId = $this->_getChannel(); $option['oldest'] = $this->_getMessageInterval(); $api = new Api(); //Get the latest 100 messages in the past minute $data = array_merge($option, array('channel' => $channelId, 'inclusive' => 1.0)); $result = $api->getChannelMessages($data); if (!$result->ok || empty($result->messages)) { return; } //Apply filters $filteredMessages = $api->filterMessages($result->messages, $this->_wordTriggers, $this->_excludedUsers); if (count($filteredMessages)) { $userList = new SlackUserCollection(); $selectedUsers = array(); foreach ($filteredMessages as $msg) { $member = $userList->getMemberById($msg->user); $selectedUsers[$member->id] = $userList->getName($member); } $userStr = implode(', ', $selectedUsers); $message = "hey " . $userStr . " " . $this->_getMessage(); $data = array('channel' => $channelId, 'text' => $message, 'username' => $this->_user, 'parse' => 'full', 'link_names' => 1); if ($this->_userIcon) { $data['icon_url'] = $this->_userIcon; } $this->_postMessage($data); } }
/** * Return url for javascript widget. * If no version is provided method will use default(current) version * * @param string $version Version of Uploadcare.com widget * @return string */ public function getScriptSrc($version = null) { if (!$version) { $version = self::version; } return sprintf($this->api->getCdnUri() . '/widget/%s/uploadcare/uploadcare.full.min.js', $version); }
public function testCreateUrl() { $expectedUrl = "http://test.webpay.com/foo/csob.do?MERCHANTNUMBER=1234&OPERATION=CREATE_ORDER&ORDERNUMBER=1234&AMOUNT=980&CURRENCY=978&DEPOSITFLAG=0&URL=http%3A%2F%2Ffoo.bar&DIGEST=Y%2BEFNoZgv0N%2B06PkOXe7v6lg4jilLcYKhWA9NDZgh2Y51vRf0Tt5N8KbPqHsWaNXUoDZ598OJgqC5NeG7km%2FiNh29uyQvYQuXaFEjA77QVWUZz6MgrI2VZU7XObyhC%2FETJ5UruAcxgpUAwCnAnWSz374%2BPzkfuS1OHxQEK4UFEam3kns06fbyR2mloa4a6xduiRt9j%2Buy6YXGoe%2FycxrOUfUPug79XZRjF7gmUgAnIvCIUcqD%2BT2mlUmG7BtzuD2pCTyV3RV47lHhO5gLGBN1VFBDm%2BNO6zqM4WTkz9ZtJmsjbzTWX3MEmQgHiiJ9mDd%2FgWY1ipWFWz%2F7TQeZEwctg%3D%3D"; $request = new PaymentRequest(1234, 9.800000000000001, PaymentRequest::EUR, 0, 'http://foo.bar'); $api = new Api(1234, 'http://test.webpay.com/foo/csob.do', new Signer(__DIR__ . '/keys/test_key.pem', 'changeit', __DIR__ . '/keys/test_cert.pem')); $this->assertEquals($expectedUrl, $api->createPaymentRequestUrl($request)); }
public function testGetStatus() { $this->mockHttpRequest('{"created_at": "Sat Mar 28 23:26:14 +0000 2009", "id": 1409441792}'); $result = $this->api->getStatus(4.375138887628472E+17); $this->assertInstanceOf('League\\Twitter\\Status', $result); $this->assertEquals('1409441792', $result->getId()); }
/** * Fetch profile details by business data * * @param Batch $batch The batch to add this to * @param string[] $parameters The parameters for request * @throws \Exception */ public function fetchProfileDetailsByBusinessData(Batch $batch, $parameters) { if ($batch->hasBeenCommitted()) { throw new \Exception("Attempting to add task to a batch which has already been comitted!"); } $parameters['batch-id'] = $batch->getBatchId(); $this->api->post('/v4/ld/fetch-profile-details-by-business-data', $parameters); }
public function run() { header('Content-Type: text/xml'); $api = new Api(); if ($_GET['operation'] == 'searchRetrieve') { echo $api->searchRetrieveRequest($_GET); } }
function callHook() { global $url; global $default; global $controller; $queryString = array(); if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $urlArray = array_filter($urlArray); $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); } else { $action = 'index'; // Default Action } $queryString = $urlArray; } $controllerName = ucfirst($controller) . 'Controller'; // Check to see if the controller exists if (!file_exists('../application/controllers/' . $controllerName . '.php')) { if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') { // Serve up some JSON $dispatch = new Api(); $dispatch->response('Endpoint not found', 404); } else { // Serve up some HTML $dispatch = new ErrorController(); call_user_func_array(array($dispatch, 'notFound'), []); exit; } } $dispatch = new $controllerName($controller, $action); if ((int) method_exists($controllerName, $action)) { call_user_func_array(array($dispatch, "beforeAction"), $queryString); call_user_func_array(array($dispatch, $action), $queryString); call_user_func_array(array($dispatch, "afterAction"), $queryString); } else { // We should check the Accept header type to server up the correct 404 if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') { // Serve up some JSON $dispatch = new Api(); $dispatch->response('Endpoint not found', 404); } else { // Serve up some HTML $dispatch = new ErrorController(); call_user_func_array(array($dispatch, 'notFound'), []); exit; } } }
protected function _postMessage($data) { if (Setting::DEV_TEST) { echo "Posting: {$data['text']} to {$data['channel']} by {$data['username']} \n"; } else { $api = new Api(); $api->postMessage($data); } }
/** * 生成要请求给支付宝的参数数组 * @param $para_temp 请求前的参数数组 * @return 要请求的参数数组字符串 */ function buildRequestParaToString($para_temp) { //待请求参数数组 $para = $this->buildRequestPara($para_temp); $api = new Api(); //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 $request_data = $api->createLinkstringUrlencode($para); return $request_data; }
/** * Returns <script> sections to include Uploadcare widget * * @param string $version Uploadcare version * @return string */ public function getScriptTag($version = null, $async = false) { $async_attr = $async ? 'async="true"' : ''; $result = <<<EOT <script>UPLOADCARE_PUBLIC_KEY = "{$this->api->getPublicKey()}";</script> <script {$async_attr} src="{$this->getScriptSrc($version)}" charset="UTF-8"></script> EOT; return $result; }
public static function getRelatedFromApi(Api $api) { $ret = array(); $pm = new PolicyManager(); $am = new AuthManager(); $allPolicies = $pm->getAllPolicies(true); $relatedPolicies = array(); $policyPropsArr = array(); $allAuths = $am->getAllAuths(true); $relatedAuthIds = array(); $relatedAuths = array(); $authPropsArr = array(); foreach ($allPolicies as $policy) { /** * @var Policy $policy */ $apiIds = $policy->getApiIds(); foreach ($apiIds as $apiId) { if ($apiId === $api->getId()) { $relatedPolicies[] = $policy; } } } foreach ($relatedPolicies as $policy) { $props = $policy->getProperties(); if (!empty($props)) { $policyPropsArr[$policy->getId()] = array_keys($props); } foreach ($policy->getAuthIds() as $authBucket) { if ($authBucket && $authBucket->getAuthIds()) { $relatedAuthIds = array_unique(array_merge($relatedAuthIds, $authBucket->getAuthIds())); } } } foreach ($allAuths as $auth) { /** * @var $auth Auth */ if (in_array($auth->getId(), $relatedAuthIds)) { $relatedAuths[] = $auth; } } foreach ($relatedAuths as $auth) { $props = $auth->getProperties(); if (!empty($props)) { $authPropsArr[$auth->getId()] = array_keys($props); } } if (!empty($policyPropsArr)) { $ret["policy"] = $policyPropsArr; } if (!empty($authPropsArr)) { $ret["auth"] = $authPropsArr; } return json_encode($ret); }
protected function fire(InputInterface $input, OutputInterface $output) { foreach (['username', 'file', 'num'] as $option) { if (is_null($input->getOption($option))) { throw new Exception("Missing argument: {$option}"); } } $username = $input->getOption('username'); $relationships = $this->getRelationships($username); $api = new Api($username); $md5 = md5_file(app_path($input->getOption('file'))); $toFollow = load($input->getOption('file')); $num = (int) $input->getOption('num'); $state = $this->getState($username, $md5); $initialPosition = $state->position; $this->info("Follow: from account {$username}\t File: {$md5}"); $this->info(sprintf("Starting from position: {$initialPosition}\t Out of: %s", count($toFollow))); $this->info(sprintf("Number to follow: %s", $num)); $this->info(sprintf("Relationships update for %s: %s", $username, date(DATE_RFC822, $relationships->time->sec))); $this->info('-----'); $n = 0; $position = $initialPosition; while ($n < $num) { if ($position >= count($toFollow)) { $this->error('File is over'); break; } list($userId, $userSrc) = $toFollow[$position]; if (in_array($userId, $relationships->followings)) { $this->line("Skipped {$userId}\tAlready following"); } elseif (in_array($userId, $relationships->followers)) { $this->line("Skipped {$userId}\tAlready a follower"); } else { if ($input->getOption('force')) { $response = $api->follow($userId); $response = json_decode($response->response); $this->line(sprintf("Followed {$userId} \tsrc: {$userSrc} \t Username: %s", $response->screen_name)); } else { $this->line("Follow {$userId} \tsrc: {$userSrc}"); } // Store to archive $follow = array('username' => $username, 'md5' => $md5, 'time' => new MongoDate(), 'src' => $userSrc, 'userId' => $userId); if (isset($response)) { $follow['response'] = $response; } $this->db->follows->insert($follow); // Clean stuff unset($response); // Increment $n $n++; } // @todo: don't follow previously followed people $position++; } $this->saveState($username, $md5, $position); }
public static function api($name = null, $options = array()) { Lib::load('api'); if (empty($name)) { $api = new Api(); $api->config($options); return $api; } return Api::getInstance($name, $options); }
public static function make_api() { $api = new Api('Cohen', 'hello_world', 'A demo function.'); $api->add_property('user_name', 'Your Name'); $api->set_path('cohen.php'); $apis = array(); $apis[] = $api; $results = array('classname' => 'Cohen', 'apis' => $apis); return $results; }
public static function run() { Bootstrap::setup(); $app = new App(); if (Util::has_request_param("action")) { $api = new Api($app); $api->apply(); } else { define("FALLBACK", $app->get_fallback()); normalized_require_once("page"); } }
/** * @expectedException \AdamStipak\Webpay\PaymentResponseException */ public function testPaymentHasErrorInVerifyPaymentResponse() { $merchantNumber = 123456789; $params = ['OPERATION' => 'operation', 'ORDERNUMBER' => 'ordernumber', 'MERORDERNUMBER' => 'merordernum', 'PRCODE' => 1, 'SRCODE' => 2, 'RESULTTEXT' => 'resulttext']; $signer = new Signer(__DIR__ . '/keys/test_key.pem', 'changeit', __DIR__ . '/keys/test_cert.pem'); $digest = $signer->sign($params); $params['MERCHANTNUMBER'] = $merchantNumber; $digest1 = $signer->sign($params); $response = new PaymentResponse($params['OPERATION'], $params['ORDERNUMBER'], $params['MERORDERNUMBER'], $params['PRCODE'], $params['SRCODE'], $params['RESULTTEXT'], $digest, $digest1); $api = new Api($merchantNumber, 'http://foo.bar', $signer); $api->verifyPaymentResponse($response); }
/** * Return url for javascript widget. * If no version is provided method will use default(current) version * * @param string $version Version of Uploadcare.com widget * @return string */ public function getScriptSrc($version = null, $full = true) { if (!$version) { $version = self::version; } if ($full) { $tail = "uploadcare.full.min.js"; } else { $tail = "uploadcare.min.js"; } return sprintf($this->api->getCdnUri() . '/widget/%s/uploadcare/' . $tail, $version); }
public static function fromDeploymentUuid($uuid, $cachePath = '/tmp') { $sessionBuilder = function ($expt) { return new CookieSession($expt->uuid); }; $api = new Api($uuid, '//api.mynaweb.com/'); $loader = function ($deploymentUuid) use($api) { return json_encode($api->getDeployment()); }; $cache = new FileCache($cachePath, $loader); return new CachingClient($uuid, $sessionBuilder, $cache); }
protected function fire(InputInterface $input, OutputInterface $output) { $usernames = $input->getArgument('usernames'); $api = new Api(); foreach ($usernames as $username) { $followers = $api->followersIds($username); $followings = $api->followingsIds($username); $this->db->relationships->insert(array('username' => $username, 'time' => new MongoDate(), 'followers' => $followers, 'followings' => $followings)); if (!$output->isQuiet()) { $this->info(sprintf("Synced %s:\t Following %s\t Followers %s", $username, count($followings), count($followers))); } } }
public function list_serveur() { $apk = "YLVnWI9vwB5nYEg0"; $endpoint = "ovh-eu"; $ask = "bDPjuf931jLDmhMMbTLSfatartv43rzB"; $csk = "is8M5oyHUJNR7UfxB5ToF6wQWAcMPfxn"; $ovh = new Api($apk, $ask, $endpoint, $csk); $liste_server = array(); while ($liste_server) { $ovh->get("/vps"); } return $liste_server; }
public function testHandlesGetRequestToLocateContainer() { $request = $this->getMockBuilder(HttpRequest::class)->disableOriginalConstructor()->getMock(); $requestUrl = $this->getMockBuilder(HttpRequestUrl::class)->disableOriginalConstructor()->getMock(); $requestUrl->method('getFirstComponent')->willReturn('containers'); $requestUrl->method('getSecondComponent')->willReturn('the-tracking-number'); $request->method('isGet')->willReturn(true); $request->method('getUrl')->willReturn($requestUrl); $trackingNumber = ContainerTrackingNumber::fromString('the-tracking-number'); $location = Location::fromCoordinates(Latitude::fromFloat(10.0), Longitude::fromFloat(20.0)); $this->reader->expects($this->once())->method('locateContainer')->with($trackingNumber)->willReturn($location); $this->assertEquals('{"latitude":10,"longitude":20}', $this->api->handle($request)); }
public function buildFromCategory($categoryTitle) { $api = new Api($this->lang); $response = $api->completeQuery(['generator' => 'categorymembers', 'gcmtitle' => $categoryTitle, 'gcmnamespace' => '0', 'prop' => 'info', 'gcmlimit' => '100']); if (!array_key_exists('query', $response)) { throw new HttpException('Not Found', 404); } $pages = $response['query']['pages']; $titles = []; foreach ($pages as $page) { $titles[] = $page['title']; } return $this->buildFromTitles($titles, $categoryTitle); }
/** * 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 updateMemberData($finalPath) { $fileHandler = fopen($finalPath, 'w'); $api = new Api(); $users = $api->getUserList(); if ($users->ok && $users->members) { $sortedMember = array(); foreach ($users->members as $obj) { $sortedMember[$obj->id] = $obj; } $cacheString = json_encode($sortedMember); fputs($fileHandler, $cacheString); } fclose($fileHandler); }
public function __construct() { parent::__construct(); $this->paper_id = intval($this->data['paper_id']); $this->paper_section = intval($this->data['paper_section']); $this->article_id = intval($this->data['article_id']); }
public function __construct() { parent::__construct(); $this->paper_id = intval($this->data['paper_id']); $this->num = intval($this->data['num']); $this->articledao = M('ssat_article'); }
/** * Constructor */ function __construct() { parent::__construct(); $this->EE->load->model('template_model'); // initialize the reserved names array $this->_load_reserved_groups(); }