Skip to content

Commit 824e745

Browse files
authored
Added necessary API methods
1 parent 8ac0fac commit 824e745

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

index.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ function findConfigurationById($id) {
3232
throw new Exception("Unable to find a Configuration with id(" . $id . ")");
3333
}
3434

35+
function findConfigurationByName($name) {
36+
$response = $this->executeRequest("configurations/name/" . $name);
37+
38+
$this->handleError($response);
39+
$configurations = $response->body->data;
40+
41+
if (count($configurations) > 0) {
42+
return $configurations[0];
43+
}
44+
45+
throw new Exception("Unable to find a Configuration with name(" . $id . ")");
46+
}
47+
48+
function findConfigurationByPath($path) {
49+
$response = $this->executeRequest("configurations/path/" . $path);
50+
51+
$this->handleError($response);
52+
53+
return $response->body->data;
54+
}
55+
3556
function executeRequest($path) {
3657
return Httpful\Request::get($this->apiUrl . "/" . $path)
3758
->addHeader("Authorization", "Bearer " . $this->appId . ":" . $this->appSecret)
@@ -40,15 +61,19 @@ function executeRequest($path) {
4061

4162
function handleError($response) {
4263
if ($response->body->success == false) {
64+
print_r($response);
65+
4366
throw new Exception("Failed to fetch configuration");
4467
}
4568
}
4669
}
4770

4871
// pls remove this below
4972
$nonfig = new Nonfig("f1afd7c6-c570-4fc0-a08a-5ed65bf9811e", "cT99KHl4kT17ewFotCef");
50-
$config = $nonfig->findConfigurationById("8400a3a0-9c14-47cc-b598-f5037fd5a9ce");
73+
$configId = $nonfig->findConfigurationById("8400a3a0-9c14-47cc-b598-f5037fd5a9ce");
74+
$configName = $nonfig->findConfigurationByName("/feature_flags");
75+
$configPath = $nonfig->findConfigurationByPath("i18n");
5176

52-
print_r($config);
77+
print_r($configPath);
5378

5479
?>

0 commit comments

Comments
 (0)