Example #1
0
 function call($httpMethod, $service_name, $service_method, $params = array())
 {
     if (!$this->client->getBearer()) {
         $options = ['form_params' => ['grant_type' => 'client_credentials', 'client_id' => $this->client->getClientId(), 'client_secret' => $this->client->getClientSecret()], 'http_errors' => false];
         $response = $this->http_client->request('POST', $this->end_point_oauth, $options);
         if ($response->getStatusCode() != 200) {
             throw new Exception('Can\'t fetch access token');
         }
         $json = json_decode($response->getBody());
         $this->client->setBearer($json->access_token, $json->expires_in);
     }
     $path = self::getPath($service_name, $service_method);
     $first_get = false;
     foreach ($params as $name => $value) {
         $search = '{' . $name . '}';
         if (stripos($path, $search)) {
             $path = str_ireplace($search, $value, $path);
         } else {
             if (mb_strtoupper($httpMethod) == 'GET') {
                 $path .= (!$first_get ? '?' : '&') . $name . '=' . $value;
                 $first_get = true;
             }
         }
     }
     return $this->http_client->request($httpMethod, $this->end_point . $path, ['headers' => $this->getHeaders()]);
 }
 public function testSetClientSecret()
 {
     $client = new Client(array('client_id' => self::CLIENT_ID, 'client_secret' => self::CLIENT_SECRET));
     $client->setClientSecret('dummy');
     $this->assertEquals($client->getClientSecret(), 'dummy', 'Expect the Client secret to be dummy.');
 }