public function testFromJson() { $data = array('multicast_id' => 12, 'success' => 1, 'failure' => 2, 'canonical_ids' => 3, 'results' => array(array('message_id' => 1241))); $response = Response::fromJson(json_encode($data), Notification::factory(array(new Device('test')), 'testing')); $this->assertEquals(12, $response->getMulticastId()); $this->assertEquals(1, $response->getNumSuccessful()); $this->assertEquals(2, $response->getNumFailures()); $this->assertEquals(3, $response->getNumCanonicalIds()); foreach ($response->getResults() as $result) { $this->assertInstanceOf('Gcm\\DeviceResult', $result); } }
/** * Calls the reCAPTCHA siteverify API to verify whether the user passes * CAPTCHA test. * * @param string $response The value of 'g-recaptcha-response' in the submitted form. * @param string $remoteIp The end user's IP address. * @return Response Response from the service. */ public function verify($response, $remoteIp = null) { // Discard empty solution submissions if (empty($response)) { $recaptchaResponse = new Response(false, array('missing-input-response')); return $recaptchaResponse; } $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); $rawResponse = $this->requestMethod->submit($params); return Response::fromJson($rawResponse); }
/** * @dataProvider provideJson */ public function testFromJson($json, $success, $errorCodes) { $response = Response::fromJson($json); $this->assertEquals($success, $response->isSuccess()); $this->assertEquals($errorCodes, $response->getErrorCodes()); }
/** * Check a StopForumSpam.com response, with side effects of populating the object's properties. * * @param $json Raw JSON input string * @return bool */ public function userIsValid($json) { $response = new Response(); $response->fromJson($json); $result = true; if (($result = $this->categoryIsValid($response->username)) === false) { $this->trigger = "username"; } else { if (($result = $this->categoryIsValid($response->email)) === false) { $this->trigger = "email"; } else { if (($result = $this->categoryIsValid($response->ip)) === false) { $this->trigger = "ip"; } } } $this->accepted = $result; return $result; }
/** * Calls the reCAPTCHA siteverify API to verify whether the user passes * CAPTCHA test. * * @param string $response The value of 'g-recaptcha-response' in the submitted form. * @param string $remoteIp The end user's IP address. * @return Response Response from the service. */ public function verify($response, $remoteIp = null) { // Discard empty solution submissions if (empty($response)) { $recaptchaResponse = new Response(false, array('missing-input-response')); return $recaptchaResponse; } $q = []; $q['secret'] = $this->secret; $q['response'] = $response; $q['remoteip'] = $remoteIp; try { $recaptchaResponse = $this->client->request("POST", null, ['form_params' => $q]); } catch (\GuzzleHttp\Exception\RequestException $ex) { $recaptchaResponse = $ex->getResponse(); } return Response::fromJson($recaptchaResponse->getBody()->getContents()); }