Пример #1
0
 /**
  * Test that the clearing of errors works correctly
  * @covers \DuoAuth\Error::add
  * @covers \DuoAuth\Error::clear
  */
 public function testClearErrors()
 {
     \DuoAuth\Error::add('foo1', 'test1');
     $return = \DuoAuth\Error::clear();
     $all = \DuoAuth\Error::get();
     $this->assertEmpty($all);
     $this->assertTrue($return);
 }
Пример #2
0
 /**
  * Populate the object with data from the response
  *
  * @param object $response Guzzle response object
  */
 public function setData($response)
 {
     if ($response->getStatusCode() == '200') {
         $this->setSuccess(true);
     }
     $body = json_decode($response->getBody(true));
     if (isset($body->response)) {
         $this->setBody($body->response);
     } else {
         $this->setBody($body);
         // check for a "stat" of "FAIL"
         $body = $this->getBody();
         if (isset($body->stat) && $body->stat == 'FAIL') {
             \DuoAuth\Error::add($body->message);
             $this->setSuccess(false);
         }
     }
 }
Пример #3
0
 /**
  * Send the request to the API
  *
  * @return string|boolean Parsed json if successful, false if not
  */
 public function send()
 {
     $path = 'https://' . $this->getHostname() . $this->getPath();
     $method = strtolower($this->getMethod());
     $client = $this->getClient();
     $hash = $this->buildHashHeader();
     $params = $this->getParams();
     ksort($params);
     if ($method == 'get') {
         $path .= '?' . http_build_query($params);
     }
     // Guzzle doesn't add the date header, so we put it in manually
     $request = $client->{$method}($path, array('Date' => date('r')), $params)->setAuth($this->getIntKey(), $hash);
     $response = new \DuoAuth\Response();
     try {
         $response->setData($request->send());
         return $response;
     } catch (\Exception $e) {
         \DuoAuth\Error::add($e->getMessage());
         $this->setError($e->getMessage());
         return $response;
     }
 }