Skip to content

Commit 4d86881

Browse files
committed
Overriding update() for Service resource; getting rid of update logic in PersistentResource.
1 parent 703941c commit 4d86881

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/OpenCloud/CDN/Resource/Service.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class Service extends PersistentResource
3030
protected static $url_resource = 'services';
3131
protected static $json_name = 'service';
3232

33-
const UPDATE_METHOD = 'PATCH';
34-
3533
protected $id;
3634
protected $name;
3735
protected $domains;
@@ -99,4 +97,19 @@ protected function createJson()
9997
$createJson = parent::createJson();
10098
return $createJson->{self::$json_name};
10199
}
100+
101+
/**
102+
* Update this resource
103+
*
104+
* @param array $params
105+
* @return \Guzzle\Http\Message\Response
106+
*/
107+
public function update($params = array())
108+
{
109+
$json = $this->generateJsonPatch($params);
110+
111+
return $this->getClient()
112+
->patch($this->getUrl(), $this->getPatchHeaders(), $json)
113+
->send();
114+
}
102115
}

lib/OpenCloud/Common/Resource/PersistentResource.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
abstract class PersistentResource extends BaseResource
3131
{
32-
const UPDATE_METHOD = 'PUT';
33-
3432
/**
3533
* Create a new resource
3634
*
@@ -82,13 +80,7 @@ public function update($params = array())
8280
$this->checkJsonError();
8381

8482
// send the request
85-
return $this->makeUpdateRequest($json);
86-
}
87-
88-
protected function makeUpdateRequest($json)
89-
{
90-
$updateMethod = ('PATCH' === static::UPDATE_METHOD) ? 'patch' : 'post';
91-
return $this->getClient()->$updateMethod($this->getUrl(), self::getJsonHeader(), $json)->send();
83+
return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send();
9284
}
9385

9486
/**

0 commit comments

Comments
 (0)