Capture status code 0 on API updates, pluck() requires 2 args, enable adding attributes to new models
This commit is contained in:
parent
0076ecef31
commit
4be82315c5
@ -122,6 +122,7 @@ final class API
|
|||||||
$response = curl_exec($request);
|
$response = curl_exec($request);
|
||||||
|
|
||||||
switch($x=curl_getinfo($request,CURLINFO_HTTP_CODE)) {
|
switch($x=curl_getinfo($request,CURLINFO_HTTP_CODE)) {
|
||||||
|
case 0:
|
||||||
case 400:
|
case 400:
|
||||||
case 401:
|
case 401:
|
||||||
case 403:
|
case 403:
|
||||||
@ -132,6 +133,10 @@ final class API
|
|||||||
}
|
}
|
||||||
|
|
||||||
curl_close($request);
|
curl_close($request);
|
||||||
|
|
||||||
|
if (! $response)
|
||||||
|
throw new \Exception(sprintf('%s:Request to [%s] returned no data?',self::LOGKEY,$url),['code'=>$x]);
|
||||||
|
|
||||||
return json_decode(self::CURLOPT_HEADER ? substr($response,curl_getinfo($request,CURLINFO_HEADER_SIZE)) : $response);
|
return json_decode(self::CURLOPT_HEADER ? substr($response,curl_getinfo($request,CURLINFO_HEADER_SIZE)) : $response);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -63,7 +63,10 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
|||||||
case 'first':
|
case 'first':
|
||||||
return $this->_data->{$name}();
|
return $this->_data->{$name}();
|
||||||
case 'pluck':
|
case 'pluck':
|
||||||
return $this->_data->map(function($item) use ($args) { return $item->{$args[0]}; });
|
if (count($args) !== 2)
|
||||||
|
throw new \BadMethodCallException(sprintf('Pluck requires to arguments %s::%s()',get_class($this),$name));
|
||||||
|
|
||||||
|
return $this->_data->map(function($item) use ($args) { return [$item->{$args[1]} => $item->{$args[0]}]; })->flatMap(function($item) { return $item; });
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()',get_class($this),$name));
|
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()',get_class($this),$name));
|
||||||
|
@ -29,7 +29,7 @@ trait CompareAttributes
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __set($key,$value) {
|
public function __set($key,$value) {
|
||||||
if (array_key_exists($key,$this->attributes) && (! $this->isSame($key,$value)))
|
if (! array_key_exists($key,$this->attributes) || (! $this->isSame($key,$value)))
|
||||||
parent::__set($key,$value);
|
parent::__set($key,$value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user