当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::init方法代码示例

本文整理汇总了PHP中Httpful\Request::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::init方法的具体用法?PHP Request::init怎么用?PHP Request::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Httpful\Request的用法示例。


在下文中一共展示了Request::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param array $config
  */
 public function __construct($config = array())
 {
     $this->config = array_merge(array('base_uri' => null, 'username' => null, 'password' => null, 'mime' => null, 'timeout' => null), (array) $config);
     $this->base_uri = $this->config['base_uri'];
     $template = Request::init()->mime($this->config['mime']);
     if ($this->config['username']) {
         $template->authenticateWith($this->config['username'], $this->config['password']);
     }
     Request::ini($template);
 }
开发者ID:paliari,项目名称:rest-client-php-facade,代码行数:13,代码来源:ClientFacade.php

示例2: __construct

 /**
  * Construt a Request
  * 
  * @param Auth $auth SkyHub Auth information to send on headers
  */
 public function __construct(Auth $auth)
 {
     $this->auth = $auth;
     $this->jsonHandler = new \SkyHub\Handlers\JsonHandler();
     $this->jsonHandler->init(array());
     Httpful::register(\Httpful\Mime::JSON, $this->jsonHandler);
     // creates a request template, every request must have the auth headers
     $this->requestTemplate = HttpfulRequest::init()->expectsJson()->addHeader('X-User-Email', $this->auth->getEmail())->addHeader('X-User-Token', $this->auth->getToken());
     HttpfulRequest::ini($this->requestTemplate);
 }
开发者ID:glauberportella,项目名称:skyhub-php,代码行数:15,代码来源:Request.php

示例3: navigate

 public function navigate($link, $data = null, $queryParams = null)
 {
     $url = $this->url . $link->Uri;
     $request = \Httpful\Request::init()->addHeader("Authorization", $this->getAuthorizationToken())->method($link->Method)->uri($url)->addHeader("Accept", $link->Type)->contentType(findMimeTypeUsingUrl($url));
     if (($link->Method === "POST" || $link->Method === "PUT") && $data !== null) {
         if (property_exists($link, 'VersionNumber')) {
             $request->addHeader($this->ifNoneMatch, $link->VersionNumber);
         }
         $request->body(json_encode($data));
     }
     $response = $request->send();
     $result = null;
     if ($response->hasErrors()) {
         $result = $response->body;
         throw new \NFleetException($result);
     } else {
         if ($link->Method === "GET") {
             $result = $response->body;
             if (isset($response->headers['etag'])) {
                 $result->VersionNumber = $response->headers['etag'];
             }
         } elseif ($link->Method === "POST" || $link->Method === "PUT") {
             $result = $this->createResponseData($response->headers['location'], $response->headers['Content-Type']);
         }
     }
     return $result;
 }
开发者ID:nfleet,项目名称:php-sdk,代码行数:27,代码来源:Api.php

示例4: performRequest

 /**
  * @param $route
  * @param $type
  * @param $data
  * @return array
  * @throws AcendaException
  * @throws Httpful\Exception\ConnectionErrorException
  */
 public function performRequest($route, $type, $data)
 {
     $httpful = Httpful\Request::init();
     if (!$this->bypass_ssl) {
         $httpful = $httpful->withStrictSSL();
     }
     $data_json = is_array($data) ? json_encode($data) : $data;
     $url = $this->store_url . (!empty($this->token['access_token']) ? "/api" . $route . "?access_token=" . $this->token['access_token'] : $route);
     switch (strtoupper($type)) {
         case 'GET':
             //Append the query.
             $url .= "&query=" . $data_json;
             $response = $httpful->get($url)->send();
             break;
         case 'PUT':
             $response = $httpful->put($url, $data_json)->sendsJson()->send();
             break;
         case 'POST':
             $response = $httpful->post($url, $data_json)->sendsJson()->send();
             break;
         default:
             throw new AcendaException('Verb ' . $type . ' Not Understood');
     }
     //Default in this switch is failure. All failures should fall through to default.
     switch ($response->code) {
         case 200:
         case 201:
             return $this->requestSuccess($response);
         default:
             return $this->requestFailure($response);
     }
 }
开发者ID:branall1,项目名称:acenda-php-sdk,代码行数:40,代码来源:Client.php

示例5: prepareRequestTemplate

 /**
  * Prepare request template with default values. All those can be simply 
  * changed by calling appropriate methods on the request, which will override
  * the template set here. Here we set Basic Auth and Accept header to be 
  * used in all requests.
  * 
  */
 protected function prepareRequestTemplate()
 {
     // Create the Request template.
     static::$requestTemplate = Request::init()->method(Http::GET)->basicAuth(static::$settings->isvuUsername, static::$settings->isvuPassword)->addHeader('Accept', static::$settings->defaultAcceptHeader);
     // Set it as a template.
     Request::ini(static::$requestTemplate);
 }
开发者ID:cicnavi,项目名称:pirac,代码行数:14,代码来源:Dispatcher.php

示例6: post

 /**
  * Post Request
  *
  * @param string $uri
  * @return \Httpful\Response
  */
 public function post($uri, $params = array())
 {
     if ($params) {
         $uri .= "?" . http_build_query($params);
     }
     $this->output("POST : " . $uri);
     return new \Httpful\Response("", "HTTP/1.1 200 OK\r\n", \Httpful\Request::init());
 }
开发者ID:svilborg,项目名称:php-roku,代码行数:14,代码来源:HttpConsole.php

示例7: __construct

 /**
  * GitHubRestClient constructor.
  * @param $request Request
  */
 public function __construct($request = null)
 {
     if (null != $request) {
         $this->request = $request;
     } else {
         $this->request = Request::init();
     }
 }
开发者ID:jgiovaresco,项目名称:repocount,代码行数:12,代码来源:GitHubRestClient.php

示例8: __construct

 /**
  * @param $client_id Developer ID, usually in form of user@domain.com
  * @param $client_secret Developer key provided by Acenda.
  * @param $store_url The URL of the store we are working with.
  * @param $plugin_name Friendly name for localeconv(oid)gs etc. I don't think this is implemented.
  * @param $bypass_ssl Rather the SSL verification should be strict or not.
  * @throws AcendaException
  */
 public function __construct($client_id, $client_secret, $store_name, $bypass_ssl = false)
 {
     $this->httpful = Httpful\Request::init();
     if (!$bypass_ssl) {
         $this->httpful = $this->httpful->withStrictSSL();
     }
     Authentication::init($client_id, $client_secret, $this->httpful);
     $this->generateStoreUrl($store_name);
 }
开发者ID:torreycommerce,项目名称:acenda-php-sdk,代码行数:17,代码来源:Client.php

示例9: request

 /**
  * Make a JSON request
  * 
  * @param string 	$method 	GET, POST, PUT, DELETE, etc.
  * @param array 	$segments 	for example array('account', 'all')
  * @param array 	$data 		the post / put data
  */
 public static function request($method, $segments, $data = array())
 {
     $url = implode('', static::url($segments, $data));
     $config = static::config();
     $response = Request::init($method)->uri($url)->mime('json')->basicAuth($config['username'], $config['password'])->send();
     if ($response->code === 404) {
         throw new Exception('API method "' . $url . '" does not exist.');
     }
     if ($response->code === 401) {
         throw new Exception('Unauthorized to use this API method "' . $url . '".');
     }
     return new Response($response->code, $response->body);
 }
开发者ID:reith2004,项目名称:components,代码行数:20,代码来源:json.php

示例10: testListUserRepositories

    public function testListUserRepositories()
    {
        $this->mockRequest->expects($this->once())->method('expectsJson')->willReturn($this->mockRequest);
        $this->mockRequest->expects($this->once())->method('uri')->with($this->equalTo('https://api.github.com/users/jgiovaresco/repos'))->willReturn($this->mockRequest);
        $this->mockRequest->expects($this->once())->method('send')->willReturn(new \Httpful\Response('[{
						"id": 123,
						"name": ".vim"
					},{
						"id": 124,
						"name": "repocount"
					}]', "HTTP/1.1 200 OK\n\t\t\t\t\tContent-Type: application/json\n\t\t\t\t\tConnection: keep-alive\n\t\t\t\t\tTransfer-Encoding: chunked\r\n", $req = \Httpful\Request::init()->sendsAndExpects(\Httpful\Mime::JSON)));
        $repositories = $this->gitHubRestClient->listUserRepositories(Employee::builder()->withId('123')->withUsername('jgiovaresco')->build());
        expect($repositories)->to->have->length(2);
        expect($repositories[0]->name())->to->equal('.vim');
        expect($repositories[1]->name())->to->equal('repocount');
    }
开发者ID:jgiovaresco,项目名称:repocount,代码行数:16,代码来源:GitHubRestClientTest.php

示例11: callback

 /**
  * Call LendingClub and gather all loans
  *
  * @return callable
  * @throws \Httpful\Exception\ConnectionErrorException
  */
 public function callback()
 {
     $uri = 'https://api.lendingclub.com/api/investor/1/loans/listing';
     /** @var \PhpAmqpLib\Message\AMQPMessage $args */
     return function ($args) use($uri) {
         $request = Request::init('GET');
         $auth_key = json_decode($args->body)[0];
         $request->uri($uri);
         $request->addHeader('Accept', 'application/json');
         $request->addHeader('Content-Type', 'application/json');
         $request->addHeader('Authorization', $auth_key);
         /** @var \Httpful\Response $response */
         $response = $request->send();
         echo $response->code . PHP_EOL;
         // Perform DB operation with response
     };
 }
开发者ID:javabudd,项目名称:RabbitApp,代码行数:23,代码来源:LendingClubWorker.php

示例12: makeRequest

 /**
  * send off the request to Shopify, encoding the data as JSON
  *
  * @param  string $method
  * @param  string $page
  * @param  array $data
  *
  * @return array
  */
 public function makeRequest($method, $page, $data = [])
 {
     $url = $this->url . "/" . $page;
     if ($method == 'GET' && !empty($data)) {
         $url .= '?' . http_build_query($data);
     }
     $r = Request::init($method)->uri($url);
     if ($data && $method != 'GET') {
         $r->body(json_encode($data), 'application/json');
     }
     $r = $r->send();
     if ($r->code !== 200) {
         return ['error' => $r->body, 'url' => $url, 'request' => '', 'status' => $r->code, 'response' => $r->body];
     } else {
         return json_decode(json_encode($r->body), true);
     }
 }
开发者ID:mochaka,项目名称:laravel-shopify,代码行数:26,代码来源:Shopify.php

示例13: makeRequest

 public static function makeRequest($method, $uri, $many = false, $payload = array())
 {
     if (empty($method)) {
         throw new \InvalidArgumentException('method');
     }
     if (empty($uri)) {
         throw new \InvalidArgumentException('uri');
     }
     $uri = str_replace('{resource}', self::getResourceName(), $uri);
     $request = \Httpful\Request::init($method)->uri(self::API_URL . $uri)->addHeader('Authorization', "Token " . self::API_KEY)->addHeader('Accept', 'application/json')->sendsJson();
     if (!empty($payload)) {
         if ($method == \Httpful\Http::GET) {
             $query_str = http_build_query($payload, null, '&');
             $query_str = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query_str);
             $request = $request->uri($request->uri . '?' . $query_str);
         } else {
             $request = $request->body($payload);
         }
     }
     $response = $request->send();
     if ($response->code >= 500) {
         throw new \Exception("{$response->code}: Internal server error. Check server logs.");
     } else {
         if ($response->code >= 400) {
             $details = is_object($response->body) ? print_r($response->body, true) : 'Check server logs.';
             throw new \Exception("{$response->code}: {$details}", $response->code);
         }
     }
     if ($many) {
         $resources = array();
         foreach ($response->body->results as $json_res) {
             $resources[] = (array) $json_res;
         }
         if (isset($response->body->next)) {
             $next_url = $response->body->next;
             if ($next_url) {
                 $next_url = substr($next_url, strlen(self::API_URL));
                 $resources = array_merge($resources, self::makeRequest($method, $next_url, $many));
             }
         }
         return $resources;
     } else {
         return (array) $response->body;
     }
 }
开发者ID:carriercomm,项目名称:pytin-php-bind,代码行数:45,代码来源:resource.php

示例14: call

 /**
  * Makes a call to the API.
  *
  * This method will make the actial API call by the given arguments. It
  * will return the response on success (200) or will throw an exception
  * on failure.
  *
  * @param string $method The HTTP method to use (e.g. Http::GET, Http::POST, etc.).
  * @param string $resourcePath The path to the resource (e.g. contacts/john@example.com/)
  * @param string $payload The data that is sent to the service. Not used for GET or DELETE.
  * @return \Httpful\Response The response object from the service.
  * @throws \Gan\ApiException
  */
 public function call($method, $resourcePath, $payload = null)
 {
     $uri = $this->baseUri . $resourcePath;
     Request::ini($this->requestTemplate);
     $request = Request::init($method)->uri($uri);
     if ($payload) {
         $request->body($payload);
     }
     try {
         $response = $request->send();
     } finally {
         Request::resetIni();
     }
     if (floor($response->code / 100) != 2) {
         throw new ApiException($response);
     }
     return $response;
 }
开发者ID:getanewsletter,项目名称:api-php,代码行数:31,代码来源:Api.php

示例15: __construct

 /**
  * Creates an HTTP Request manager with additional header support for Plex.
  * Endpoint is the URL to request from, with optional proxy parameter.
  * expectEmptyResponse when set to true does not try and parse the result as XML.
  *
  * @param string     $endPoint
  * @param bool|Proxy $proxy
  */
 public function __construct($endPoint, $proxy = false, $expectEmptyResponse = false)
 {
     $this->endPoint = $endPoint;
     $this->template = HttpfulRequest::init();
     if ($expectEmptyResponse) {
         $this->template->withoutAutoParse();
     } else {
         $this->template->expectsXml();
     }
     if ($proxy) {
         $this->template->useProxy($proxy->host, $proxy->port, $proxy->authType);
     }
     foreach ($this->headers as $header => $value) {
         if ($value) {
             $this->setHeader($header, $value);
         }
     }
 }
开发者ID:cheezykins,项目名称:phpmyplexclient,代码行数:26,代码来源:Request.php


注:本文中的Httpful\Request::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。