本文整理汇总了PHP中Httpful\Request::ini方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::ini方法的具体用法?PHP Request::ini怎么用?PHP Request::ini使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Httpful\Request
的用法示例。
在下文中一共展示了Request::ini方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例3: 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);
}
示例4: 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;
}
示例5: sendRequest
private function sendRequest($endpoint, $method = Http::GET, $payload = null)
{
$template = Request::init()->method($method)->sendsType(Mime::JSON);
if (isset($this->auth_header)) {
$template->addHeader('Authorization', 'Basic ' . $this->auth_header);
}
Request::ini($template);
$r = null;
switch ($method) {
case Http::GET:
$r = Request::get(self::API_HOST . $endpoint . '?' . http_build_query($payload))->send();
break;
case Http::POST:
$r = Request::post(self::API_HOST . $endpoint)->body(json_encode($payload))->send();
break;
default:
throw new \Exception("Method not implemented.");
break;
}
if ($r->hasErrors() || isset($r->body->status_code) && $r->body->status_code != 200) {
throw new \Exception($r);
}
return $r;
}
示例6: testIni
function testIni()
{
// Test setting defaults/templates
// Create the template
$template = Request::init()->method(Http::POST)->withStrictSsl()->expectsType(Mime::HTML)->sendsType(Mime::FORM);
Request::ini($template);
$r = Request::init();
$this->assertTrue($r->strict_ssl);
$this->assertEquals(Http::POST, $r->method);
$this->assertEquals(Mime::HTML, $r->expected_type);
$this->assertEquals(Mime::FORM, $r->content_type);
// Test the default accessor as well
$this->assertTrue(Request::d('strict_ssl'));
$this->assertEquals(Http::POST, Request::d('method'));
$this->assertEquals(Mime::HTML, Request::d('expected_type'));
$this->assertEquals(Mime::FORM, Request::d('content_type'));
Request::resetIni();
}
示例7: search
public function search()
{
if (!Session::has('api_settings')) {
return array('status' => 0);
}
$api_settings = Session::get('api_settings');
$first_time = $api_settings['current'] == 0;
$url = sprintf("https://%s:%s@%s/api/v1/messages/search?q=%s", $api_settings['username'], $api_settings['password'], $api_settings['host'], $api_settings['query_string']);
if (!$first_time) {
$url .= sprintf("&from=%s&size=100", $api_settings['current']);
}
$http_template = RequestClient::init()->method('GET')->withoutStrictSsl()->withoutAutoParsing();
RequestClient::ini($http_template);
$res = RequestClient::get($url)->send();
if (!$res->hasErrors() && $res->hasBody()) {
$data = json_decode($res->body, true);
if ($first_time) {
$total = intval($data['search']['results']);
$api_settings['total'] = $total;
}
$count = 0;
foreach ($data['tweets'] as $tweet) {
$flat = $this->array_flat($tweet);
Storage::disk('local')->append($api_settings['file_name'], json_encode($flat, JSON_UNESCAPED_UNICODE) . ',');
$count++;
}
$api_settings['current'] += $count;
Session::put('api_settings', $api_settings);
return array('status' => 1, 'total' => $api_settings['total'], 'current' => $api_settings['current']);
}
return array('status' => 0);
}
示例8: send
/**
* Initiates the HTTP request using the provided method (GET, POST, PUT, DELETE)
* and returns the response XML as an Httpful\Request.
*
* @param string $method
*
* @throws MyPlexDataException
*
* @return HttpfulRequest
*/
public function send($method)
{
HttpfulRequest::ini($this->template);
try {
$response = HttpfulRequest::$method($this->endPoint)->send();
} catch (ConnectionErrorException $e) {
throw new MyPlexDataException('Unable to connect to endPoint: ' . $e->getMessage(), 0, $e);
} catch (\Exception $e) {
throw new MyPlexDataException('Error in response from server: ' . $e->getMessage(), 0, $e);
}
$this->errorCheck($response);
return $response;
}
示例9: setTemplate
/**
* Method to set template of request
*/
private function setTemplate($method)
{
// Register a new mime type handler if we expect a Json, so the response is decoded as an array.
// Extracted from: http://stackoverflow.com/a/22597037
if ($this->mimeType == 'json') {
$jsonHandler = new JsonHandler(array('decode_as_array' => true));
Httpful::register('application/json', $jsonHandler);
}
// Create template
$template = Request::init()->method($this->getMethod($method))->expects($this->mimeType)->sendsType(Mime::FORM);
// Add custom headers to request
if ($this->headers !== null && is_array($this->headers) && !empty($this->headers)) {
$template->addHeaders($this->headers);
}
// Set the template
Request::ini($template);
}
示例10: set_template
/**
* Applies a Request template.
* If you don't specify the $template parameter, the default template will be applied.
*
* @param \Httpful\Request $template
*/
public function set_template($template)
{
$this->template = $template instanceof Request ? $template : Request::init();
Request::ini($this->template);
}
示例11: createTemplate
public function createTemplate()
{
$this->_template = Request::init()->withXProjectId($this->_project_id)->withXProjectKey($this->_project_key);
Request::ini($this->_template);
}
示例12: __construct
public function __construct($app_key = null, $secret = null, $base_uri = null)
{
$this->set_app_key($app_key);
$this->set_secret($secret);
if ($base_uri != null) {
self::$base_uri = $base_uri;
}
$template = Request::init()->withoutStrictSsl()->expectsJson()->sendsType(Mime::JSON)->addHeader('yotpo_api_connector', 'PHP-' . Yotpo::VERSION);
// Set it as a template
Request::ini($template);
}