namespace seekat\API;
+use seekat\{
+ API, Exception\InvalidArgumentException, Exception\UnexpectedValueException
+};
use http\{
- Header,
- Message\Body
+ Header, Message\Body
};
-use InvalidArgumentException;
-use UnexpectedValueException;
-
class ContentType
{
/**
"diff" => "self::fromData",
"patch" => "self::fromData",
"text/plain"=> "self::fromData",
+ "application/octet-stream" => "self::fromStream",
];
/**
return $api;
}
+ /**
+ * @param API $api
+ * @param string $type
+ * @return API
+ */
+ static function apply(API $api, string $type) : API {
+ $part = "[^()<>@,;:\\\"\/\[\]?.=[:space:][:cntrl:]]+";
+ if (preg_match("/^$part\/$part\$/", $type)) {
+ $that = $api->withHeader("Accept", $type);
+ } else {
+ switch (substr($type, 0, 1)) {
+ case "+":
+ case ".":
+ case "":
+ break;
+ default:
+ $type = ".$type";
+ break;
+ }
+ $vapi = static::version();
+ $that = $api->withHeader("Accept", "application/vnd.github.v$vapi$type");
+ }
+ return $that;
+ }
+
/**
* @param Body $json
* @return mixed
return $decoded;
}
+
+ /**
+ * @param Body $stream
+ * @return resource stream
+ */
+ private static function fromStream(Body $stream) {
+ return $stream->getResource();
+ }
+
/**
* @param Body $data
* @return string