Skip to content

Commit 603fb55

Browse files
committed
initial phase of rest of the endpoints complete
1 parent 7e82137 commit 603fb55

12 files changed

+860
-44
lines changed

composer.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
"minimum-stability": "stable",
55
"license": "Apache-2.0",
66
"keywords": ["kubernetes", "api", "client", "restful", "http"],
7-
"version": "0.1.24",
87
"authors": [
98
{
109
"name": "Faruk Brbovic",
1110
"email": "fbrbovic@devstub.com",
1211
"homepage": "http://www.devstub.com"
1312
}
1413
],
14+
"repositories": [
15+
{
16+
"type": "vcs",
17+
"url": "https://github.com/devstub/jsonmapper.git"
18+
}
19+
],
1520
"require": {
1621
"php": ">=5.4.0",
1722
"guzzlehttp/guzzle": "5.0.3",
18-
"netresearch/jsonmapper": "v0.4.1"
23+
"netresearch/jsonmapper": "dev-issue_8"
1924
},
2025
"require-dev": {
2126
"phpunit/phpunit": "~4.0"

src/KubernetesAPIClient/Client.php

+98-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
*/
2424

2525
namespace DevStub\KubernetesAPIClient;
26+
use Binarygoo\KubernetesAPIClient\Endpoint\v1beta1\ReplicationControllers;
27+
use DevStub\KubernetesAPIClient\Endpoint\v1beta1\Endpoints;
28+
use DevStub\KubernetesAPIClient\Endpoint\v1beta1\Minions;
29+
use DevStub\KubernetesAPIClient\Entity\v1beta1\ReplicationController;
2630
use DevStub\KubernetesAPIClient\Exception\ClientException;
2731
use DevStub\KubernetesAPIClient\Exception\ConfigException;
2832

@@ -74,7 +78,7 @@ public function config($config = null) {
7478
/**
7579
* Returns the Pods api endpoint object.
7680
*
77-
* @return \DevStub\KubernetesAPIClient\Endpoint\v1
81+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\Pods
7882
*/
7983
public function pods() {
8084
if ($this->_podsEndpointObject === null) {
@@ -91,28 +95,115 @@ public function pods() {
9195
return $this->_podsEndpointObject;
9296
}
9397

98+
/**
99+
* Returns the Replication Controllers api endpoint object
100+
*
101+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\ReplicationControllers
102+
*/
94103
public function replicationControllers() {
95-
// TODO
104+
if ($this->_podsEndpointObject === null) {
105+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\ReplicationControllers";
106+
if (class_exists($podsClass)) {
107+
$this->_podsEndpointObject = new $podsClass($this->_config);
108+
}
109+
else {
110+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
111+
}
112+
113+
}
114+
115+
return $this->_podsEndpointObject;
96116
}
97117

118+
/**
119+
* Returns the Endpoints api endpoint object
120+
*
121+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\Endpoints
122+
*/
98123
public function endpoints() {
99-
// TODO
124+
if ($this->_podsEndpointObject === null) {
125+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\Endpoints";
126+
if (class_exists($podsClass)) {
127+
$this->_podsEndpointObject = new $podsClass($this->_config);
128+
}
129+
else {
130+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
131+
}
132+
133+
}
134+
135+
return $this->_podsEndpointObject;
100136
}
101137

138+
/**
139+
* Returns the Services api endpoint object
140+
*
141+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\Services
142+
*/
102143
public function services() {
103-
// TODO
144+
if ($this->_podsEndpointObject === null) {
145+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\Services";
146+
if (class_exists($podsClass)) {
147+
$this->_podsEndpointObject = new $podsClass($this->_config);
148+
}
149+
else {
150+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
151+
}
152+
153+
}
154+
155+
return $this->_podsEndpointObject;
104156
}
105157

158+
/**
159+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\Minions
160+
*/
106161
public function minions() {
107-
// TODO
162+
if ($this->_podsEndpointObject === null) {
163+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\Minions";
164+
if (class_exists($podsClass)) {
165+
$this->_podsEndpointObject = new $podsClass($this->_config);
166+
}
167+
else {
168+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
169+
}
170+
171+
}
172+
173+
return $this->_podsEndpointObject;
108174
}
109175

176+
/**
177+
* @return \DevStub\KubernetesAPIClient\Endpoint\v1beta1\Events
178+
*/
110179
public function events() {
111-
// TODO
180+
if ($this->_podsEndpointObject === null) {
181+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\Events";
182+
if (class_exists($podsClass)) {
183+
$this->_podsEndpointObject = new $podsClass($this->_config);
184+
}
185+
else {
186+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
187+
}
188+
189+
}
190+
191+
return $this->_podsEndpointObject;
112192
}
113193

114194
public function bindings() {
115-
// TODO
195+
if ($this->_podsEndpointObject === null) {
196+
$podsClass = "\\DevStub\\KubernetesAPIClient\\Endpoint\\".$this->_config->getAPIVersion()."\\Bindings";
197+
if (class_exists($podsClass)) {
198+
$this->_podsEndpointObject = new $podsClass($this->_config);
199+
}
200+
else {
201+
throw new ClientException("API Version :".$this->_config->getAPIVersion()." is not currently supported with this client");
202+
}
203+
204+
}
205+
206+
return $this->_podsEndpointObject;
116207
}
117208

118209
}

src/KubernetesAPIClient/Endpoint/BaseEndpoint.php

+50
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,54 @@ protected function _prepareCreate($path, $inputParam, $classUsed, $callBackArray
109109

110110
}
111111

112+
/**
113+
* @param $path
114+
* @param $id
115+
* @param $inputParam
116+
* @param $classUsed
117+
* @param $callBackArray
118+
* @param $responseAdapter
119+
*
120+
* @return object|null
121+
*/
122+
protected function _prepareUpdate($path, $id, $inputParam, $classUsed, $callBackArray, &$responseAdapter) {
123+
124+
if ($id !== null) {
125+
$path .= "/".$id;
126+
}
127+
else {
128+
throw new ClientException("Id needs to be set ");
129+
}
130+
131+
if (is_string($inputParam)) {
132+
133+
$responseAdapter = $this->_adapter->sendPUTRequest($path,$inputParam);
134+
return null;
135+
136+
}
137+
else if (is_object($inputParam)) {
138+
if (!($inputParam instanceof $classUsed)) {
139+
throw new ClientException("Invalid type, provided object must be an instance of $classUsed");
140+
}
141+
142+
$responseAdapter = $this->_adapter->sendPUTRequest($path,$inputParam);
143+
return null;
144+
145+
}
146+
else if ($inputParam === null ) {
147+
148+
/** @var $inputParam BaseEntity */
149+
$inputParam = new $classUsed();
150+
$inputParam->_setEntityCallback( $callBackArray);
151+
$inputParam->_setEntityResponseObjectRef($responseAdapter);
152+
$inputParam->_setEntityCallbackId($id);
153+
154+
return $inputParam;
155+
}
156+
else {
157+
throw new ClientException("Invalid input type provided");
158+
}
159+
160+
}
161+
112162
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* PHP CLient for Kubernetes API
4+
*
5+
* Copyright 2014 binarygoo Inc. / Devstub.com All rights reserved.
6+
*
7+
* @author Faruk brbovic <fbrbovic@devstub.com>
8+
* @link http://www.devstub.com/
9+
* @copyright 2014 binarygoo / devstub.com
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*
23+
*/
24+
25+
namespace DevStub\KubernetesAPIClient\Endpoint\v1beta1;
26+
27+
28+
use DevStub\KubernetesAPIClient\Endpoint\BaseEndpoint;
29+
use DevStub\KubernetesAPIClient\Entity\v1beta1\Binding;
30+
31+
class Bindings extends BaseEndpoint {
32+
33+
/**
34+
* creates a new Binding
35+
*
36+
* If $binding is left as null then a new Binding object will be returned allowing you to set the properties via method chaining.
37+
*
38+
* @param \DevStub\KubernetesAPIClient\Adapter\AdapterResponse $responseAdapter
39+
* @param Binding|null|string $binding
40+
*
41+
* @return Binding|bool|null
42+
*/
43+
public function create( $binding = null, &$responseAdapter = null) {
44+
45+
46+
return $this->_prepareCreate("bindings",
47+
$binding,
48+
"\\DevStub\\KubernetesAPIClient\\Entity\\v1beta1\\Binding",
49+
array($this, __METHOD__),
50+
$responseAdapter);
51+
}
52+
53+
/**
54+
* Retrieve a list of bindings or a specific binding
55+
*
56+
* @param null|string $bindingId
57+
* @param \DevStub\KubernetesAPIClient\Adapter\AdapterResponse $responseAdapter
58+
*
59+
* @return \DevStub\KubernetesAPIClient\Adapter\AdapterResponse
60+
*/
61+
public function get( $bindingId = null, &$responseAdapter = null) {
62+
63+
$path = "bindings";
64+
65+
if ($bindingId !== null) {
66+
$path .= "/".$bindingId;
67+
}
68+
69+
$responseAdapter = $this->_adapter->sendGETRequest($path);
70+
71+
return $responseAdapter;
72+
}
73+
74+
/**
75+
* Delete a binding
76+
*
77+
* @param string $bindingId
78+
* @param \DevStub\KubernetesAPIClient\Adapter\AdapterResponse $responseAdapter
79+
*
80+
* @return \DevStub\KubernetesAPIClient\Adapter\AdapterResponse
81+
*/
82+
public function delete($bindingId, &$responseAdapter = null) {
83+
84+
$path = "bindings/".$bindingId;
85+
86+
$responseAdapter = $this->_adapter->sendDELETERequest($path);
87+
88+
return $responseAdapter;
89+
}
90+
91+
/**
92+
* Update a binding.
93+
*
94+
* If $binding is left null then you will be able to setup a new fresh Binding object via method chaining.
95+
*
96+
*
97+
* @param $bindingId
98+
* @param \DevStub\KubernetesAPIClient\Entity\v1beta1\Binding $binding
99+
* @param \DevStub\KubernetesAPIClient\Adapter\AdapterResponse $responseAdapter
100+
*
101+
* @return Binding|bool|null
102+
*/
103+
public function update($bindingId, $binding = null, &$responseAdapter = null) {
104+
105+
106+
return $this->_prepareUpdate("bindings",
107+
$bindingId,
108+
$binding,
109+
"\\DevStub\\KubernetesAPIClient\\Entity\\v1beta1\\Binding",
110+
array($this, __METHOD__),
111+
$responseAdapter);
112+
}
113+
114+
}

0 commit comments

Comments
 (0)