Ejemplo n.º 1
0
 /**
  * Send data to remote JSON-RPC service over HTTP.
  *
  * @throws \Josser\Exception\TransportFailureException
  * @param mixed $data
  * @return string
  */
 public function send($data)
 {
     try {
         $response = $this->guzzle->post(null, ['body' => $data, 'headers' => ['Content-Type' => 'application/json']]);
         return $response->getBody()->getContents();
     } catch (\Exception $e) {
         $error = sprintf('JSON-RPC http connection failed. Remote service at "%s" is not responding.', $this->guzzle->getBaseUrl());
         throw new TransportFailureException($error, null, $e);
     }
 }
 /**
  * SharePoint Site constructor
  *
  * @access  public
  * @param   \GuzzleHttp\Client $http   Guzzle HTTP client
  * @param   array              $config SharePoint Site configuration
  * @throws  SPException
  * @return  SPSite
  */
 public function __construct(Client $http, array $config)
 {
     $this->config = array_replace_recursive(['acs' => static::ACS], $config);
     // set Guzzle HTTP client
     $this->http = $http;
     // set Site Hostname and Path
     $components = parse_url($this->http->getBaseUrl());
     if (!isset($components['scheme'], $components['host'], $components['path'])) {
         throw new SPException('The SharePoint Site URL is invalid');
     }
     $this->hostname = $components['scheme'] . '://' . $components['host'];
     $this->path = rtrim($components['path'], '/');
 }
Ejemplo n.º 3
0
 public function __construct($id, $token, Client $client = null)
 {
     if (!$client) {
         $client = new Client(['base_url' => self::ENDPOINT]);
     }
     if (!$client->getBaseUrl()) {
         throw new Exception\ClientException('API client is not configured with a base URL');
     }
     if (!ctype_xdigit($id) || !ctype_xdigit($token)) {
         throw new Exception\ClientException('User credentials are invalid');
     }
     $client->setDefaultOption('headers', ['Auth' => "Bearer {$id} {$token}", 'User-Agent' => 'WIU PHP Client/1.0']);
     $this->client = $client;
 }
Ejemplo n.º 4
0
 public function testCanSpecifyBaseUrlUriTemplate()
 {
     $client = new Client(['base_url' => ['http://foo.com/{var}/', ['var' => 'baz']]]);
     $this->assertEquals('http://foo.com/baz/', $client->getBaseUrl());
 }
Ejemplo n.º 5
0
 /**
  * Implements \JsonSerializable::jsonSerialize.
  */
 public function jsonSerialize()
 {
     return ['url' => $this->client->getBaseUrl(), 'username' => $this->username, 'password' => $this->password, 'authToken' => $this->authToken, 'accessToken' => $this->accessToken, 'refreshToken' => $this->refreshToken, 'settings' => $this->settings];
 }
Ejemplo n.º 6
0
 public function getBaseUri()
 {
     return $this->client->getBaseUrl();
 }
Ejemplo n.º 7
0
 /**
  * @param Client $client
  */
 protected function copyClientDefaults(Client $client)
 {
     $this->request->setUrl($client->getBaseUrl() . $this->request->getUrl());
     $this->request->addHeaders($client->getDefaultOption('headers'));
 }