Skip to content

Commit 91e935e

Browse files
committed
ExceptionThrowerService added.
1 parent 7eb1422 commit 91e935e

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

src/org/nameapi/client/services/ServiceFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require_once(__DIR__.'/BaseService.php');
88
require_once(__DIR__.'/Host.php');
9+
require_once(__DIR__.'/development/DevelopmentServiceFactory.php');
910
require_once(__DIR__.'/system/SystemServiceFactory.php');
1011
require_once(__DIR__.'/parser/ParserServiceFactory.php');
1112
require_once(__DIR__.'/genderizer/GenderizerServiceFactory.php');
@@ -51,6 +52,7 @@ class ServiceFactory {
5152
*/
5253
private $baseUrl;
5354

55+
private $developmentServiceFactory;
5456
private $systemServiceFactory;
5557
private $parserServiceFactory;
5658
private $genderizerServiceFactory;
@@ -83,6 +85,16 @@ public function __construct($apiKey, Context $context, Host $host=null, $apiVers
8385
}
8486

8587

88+
/**
89+
* @return development\DevelopmentServiceFactory
90+
*/
91+
public function developmentServices() {
92+
if ($this->developmentServiceFactory==null) {
93+
$this->developmentServiceFactory = new development\DevelopmentServiceFactory($this->apiKey, $this->context, $this->baseUrl);
94+
}
95+
return $this->developmentServiceFactory;
96+
}
97+
8698
/**
8799
* @return system\SystemServiceFactory
88100
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace org\nameapi\client\services\development;
4+
5+
use org\nameapi\client\services\development\exceptionthrower\ExceptionThrowerService;
6+
use org\nameapi\ontology\input\context\Context;
7+
8+
require_once(__DIR__.'/exceptionthrower/ExceptionThrowerService.php');
9+
10+
11+
/**
12+
* Provides access to the system-related services.
13+
*/
14+
class DevelopmentServiceFactory {
15+
16+
private $apiKey;
17+
private $context;
18+
private $baseUrl;
19+
private $exceptionThrowerService;
20+
21+
/**
22+
*/
23+
public function __construct($apiKey, Context $context, $baseUrl) {
24+
$this->apiKey = $apiKey;
25+
$this->context = $context;
26+
$this->baseUrl = $baseUrl;
27+
}
28+
29+
/**
30+
* @return ExceptionThrowerService
31+
* @since v5.0
32+
*/
33+
public function exceptionThrower() {
34+
if ($this->exceptionThrowerService==null) {
35+
$this->exceptionThrowerService = new ExceptionThrowerService($this->apiKey, $this->context, $this->baseUrl);
36+
}
37+
return $this->exceptionThrowerService;
38+
}
39+
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace org\nameapi\client\services\development\exceptionthrower;
4+
5+
use org\nameapi\client\fault\ServiceException;
6+
use org\nameapi\client\services\BaseService;
7+
use org\nameapi\ontology\input\context\Context;
8+
9+
10+
/**
11+
* This is the service class for the web service offered at
12+
* http://api.nameapi.org/rest/v5.0/development/exceptionthrower
13+
*
14+
* <p>The use is for development only; to see what happens when the server throws exceptions, and how they arrive
15+
* at your end.</p>
16+
*
17+
* HOW TO USE:
18+
* $exceptionThrower = $myServiceFactory->developmentServices()->exceptionThrowerService();
19+
* $exceptionThrower = $ping->throwException();
20+
*/
21+
class ExceptionThrowerService extends BaseService {
22+
23+
24+
private static $RESOURCE_PATH = "development/exceptionthrower";
25+
26+
public function __construct($apiKey, Context $context, $baseUrl) {
27+
parent::__construct($apiKey, $context, $baseUrl);
28+
}
29+
30+
/**
31+
* @param string $exceptionType One of 'AccessDeniedNoSuchAccount', 'InvalidInput', 'InternalServerError'
32+
* @param int $exceptionChance 0-100 where 100 means always
33+
* @return string 'OK' in case the remote service does not throw.
34+
* @throws ServiceException
35+
*/
36+
public function throwException($exceptionType, $exceptionChance) {
37+
$queryParams = array(
38+
'exceptionType' => $exceptionType,
39+
'exceptionChance' => $exceptionChance,
40+
);
41+
$headerParams = array();
42+
43+
list($response, $httpResponseData) = $this->restHttpClient->callApiGet(
44+
ExceptionThrowerService::$RESOURCE_PATH,
45+
$queryParams, $headerParams
46+
);
47+
if ($response !== 'OK') {
48+
throw $this->unmarshallingFailed($response, $httpResponseData);
49+
}
50+
return $response;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)