/**
  * Fetch token from Watson and Save it locally.
  *
  * @param bool $incrementThrottle
  *
  * @return void
  */
 public function fetchToken($incrementThrottle = false)
 {
     //Increment throttle if needed
     if ($incrementThrottle) {
         $this->incrementThrottle();
     }
     //Reset Client
     $this->setClient($this->getAuthorizationEndpoint());
     //Get the token response
     $response = $this->get('v1/token', ['url' => $this->endpoint]);
     //Extract
     $token = json_decode($response->getBody()->getContents(), true);
     //Reset client
     $this->setClient($this->endpoint);
     //Update token
     $this->token->updateToken($token['token']);
 }
 /**
  * Test to see if the Update token method works.
  *
  * @return void
  */
 public function testUpdateTokenMethod()
 {
     $payload = ['token' => 'sometoken', 'expires_in' => 3600, 'created' => Carbon::now()->format('U')];
     $token = new Token('username3', $payload);
     $this->assertEquals('sometoken', $token->getToken());
     $this->assertTrue($token->updateToken('newToken'));
     $this->assertEquals('newToken', $token->getToken());
     $this->assertFileExists($this->getTokenStoragePath('token-username3.json'));
     $this->deleteTestTokenFile('token-username3');
 }