| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | class IGSNRestRequest { |
| 27: | |
| 28: | private $baseurl; |
| 29: | private $username; |
| 30: | private $password; |
| 31: | private $method; |
| 32: | private $header; |
| 33: | private $payload; |
| 34: | private $endpoint; |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function __construct($baseurl, $username, $password, $endpoint) { |
| 44: | $this->baseurl = $baseurl; |
| 45: | $this->username = $username; |
| 46: | $this->password = $password; |
| 47: | $this->endpoint = $endpoint; |
| 48: | $this->header = array("Content-type: application/xml;charset=UTF-8", "Accept: application/xml", "Authorization: Basic " . base64_encode($username . ":" . $password)); |
| 49: | } |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function registerIGSNGFZ($igsn, $regmetadata, $descripmetadata) { |
| 58: | $mintcode = $this->mintdoi($igsn); |
| 59: | if ($mintcode == 201) { |
| 60: | $regcode = $this->upload_regmetadata($regmetadata); |
| 61: | if ($regcode == 201) { |
| 62: | $metadata = $this->upload_metadata($descripmetadata, $igsn); |
| 63: | if ($metadata == 201) { |
| 64: | echo "Sucuess IGSN registered"; |
| 65: | return 0; |
| 66: | } else { |
| 67: | echo "Error IGSN Sample Metadata not stored "; |
| 68: | return 3; |
| 69: | } |
| 70: | } else { |
| 71: | echo "Error IGSN regmetadatdata & metadata not stored "; |
| 72: | return 2; |
| 73: | } |
| 74: | } else { |
| 75: | echo "Error IGSN not even minted "; |
| 76: | return 1; |
| 77: | } |
| 78: | echo "This should never happen!"; |
| 79: | return 9; |
| 80: | } |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | public function registerPlainIGSN($igsn, $regmetadata) { |
| 89: | $mintcode = $this->mintdoi($igsn); |
| 90: | if ($mintcode == 201) { |
| 91: | $regcode = $this->upload_regmetadata($regmetadata); |
| 92: | if ($regcode == 201) { |
| 93: | echo "Sucuess IGSN registered"; |
| 94: | return 0; |
| 95: | } else { |
| 96: | echo "Error IGSN regmetadatdata"; |
| 97: | return 2; |
| 98: | } |
| 99: | } else { |
| 100: | echo "Error IGSN not even minted "; |
| 101: | return 1; |
| 102: | } |
| 103: | echo "This should never happen!"; |
| 104: | return 9; |
| 105: | } |
| 106: | |
| 107: | public function updateAllMetadata($igsn, $regmetadata, $descripmetada) { |
| 108: | $regcode = $this->upload_regmetadata($regmetadata); |
| 109: | if ($regcode == 201) { |
| 110: | $metadata = $this->upload_metadata($descripmetada, $igsn); |
| 111: | if ($metadata == 201) { |
| 112: | echo "Sucuess IGSN Metadata updated"; |
| 113: | return 0; |
| 114: | } else { |
| 115: | echo "Error IGSN Sample Metadata not stored "; |
| 116: | return 2; |
| 117: | } |
| 118: | } else { |
| 119: | |
| 120: | echo "Error IGSN regmetadatdata & metadata not stored "; |
| 121: | return 3; |
| 122: | } |
| 123: | echo "This should never happen!"; |
| 124: | return 9; |
| 125: | } |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | public function mintdoi($igsn) { |
| 133: | $this->url = $this->endpoint . "igsn"; |
| 134: | $this->method = "POST"; |
| 135: | $this->payload = "igsn=10273/" . $igsn . "\n" . "url=" . $this->baseurl . $igsn; |
| 136: | $result = $this->httprequest(); |
| 137: | var_dump($result); |
| 138: | $resulthttp_code = $result["header"]["http_code"]; |
| 139: | echo "mint"; |
| 140: | var_dump($resulthttp_code); |
| 141: | return($resulthttp_code); |
| 142: | } |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | public function upload_regmetadata($regmetadata) { |
| 151: | echo(gettype($regmetadata)); |
| 152: | $this->url = $this->endpoint . "metadata"; |
| 153: | $this->method = "POST"; |
| 154: | $this->payload = $regmetadata; |
| 155: | $result = $this->httprequest(); |
| 156: | $resulthttp_code = $result["header"]["http_code"]; |
| 157: | echo "reg"; |
| 158: | var_dump($resulthttp_code); |
| 159: | var_dump($result); |
| 160: | return($resulthttp_code); |
| 161: | } |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | public function upload_metadata($igsnmetadata, $igsn) { |
| 172: | $this->url = $this->endpoint . "igsnmetadata/10273/" . $igsn; |
| 173: | $this->method = "POST"; |
| 174: | $this->payload = $igsnmetadata; |
| 175: | $result = $this->httprequest(); |
| 176: | $resulthttp_code = $result["header"]["http_code"]; |
| 177: | echo "meta"; |
| 178: | var_dump($result); |
| 179: | var_dump($resulthttp_code); |
| 180: | return($resulthttp_code); |
| 181: | } |
| 182: | |
| 183: | public function fetchIGSNlist() { |
| 184: | $this->url = $this->endpoint . "igsn"; |
| 185: | $this->method = "GET"; |
| 186: | $result = $this->httprequest(); |
| 187: | $resultContentString = $result["content"]; |
| 188: | $resultContent = explode("\n", $resultContentString); |
| 189: | return $resultContent; |
| 190: | } |
| 191: | |
| 192: | public function fetchRegMeta($igsn) { |
| 193: | $this->url = $this->endpoint . "metadata/" . $igsn; |
| 194: | $this->method = "GET"; |
| 195: | $result = $this->httprequest(); |
| 196: | |
| 197: | if(strcasecmp($result["content"], 'no metadata for the IGSN')===0){ |
| 198: | return false; |
| 199: | } |
| 200: | $resultXML = simplexml_load_string($result["content"]); |
| 201: | return $resultXML; |
| 202: | } |
| 203: | |
| 204: | public function fetchIGSNMeta($igsn) { |
| 205: | $this->url = $this->endpoint . "igsnmetadata/" . $igsn; |
| 206: | $this->method = "GET"; |
| 207: | $result = $this->httprequest(); |
| 208: | $resultXMLString = $result["content"]; |
| 209: | if(strcasecmp($result["content"], 'no IGSN metadata for the IGSN')===0){ |
| 210: | echo 'no Metadata file'; |
| 211: | return false; |
| 212: | } |
| 213: | $resultXML = simplexml_load_string($result["content"]); |
| 214: | return $resultXML; |
| 215: | |
| 216: | } |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: | |
| 223: | |
| 224: | |
| 225: | public function resloveigsn($igsn) { |
| 226: | $this->url = $this->endpoint . "igsn/10273/" . $igsn; |
| 227: | $this->method = "GET"; |
| 228: | $result = $this->httprequest(); |
| 229: | $resulthttp_code = $result["header"]["http_code"]; |
| 230: | |
| 231: | |
| 232: | return($resulthttp_code); |
| 233: | } |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | public function registerparent($parent) { |
| 242: | $result = $this->resloveigsn($parent); |
| 243: | $resulthttp_code = $result["header"]["http_code"]; |
| 244: | var_dump($resulthttp_code); |
| 245: | } |
| 246: | |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | |
| 252: | public function httprequest() { |
| 253: | $ch = curl_init(); |
| 254: | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 255: | curl_setopt($ch, CURLOPT_URL, $this->url); |
| 256: | if (isset($this->header)) |
| 257: | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header); |
| 258: | |
| 259: | switch ($this->method) { |
| 260: | case "GET": |
| 261: | |
| 262: | curl_setopt($ch, CURLOPT_HTTPGET, true); |
| 263: | break; |
| 264: | case "POST": |
| 265: | curl_setopt($ch, CURLOPT_POST, true); |
| 266: | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->payload); |
| 267: | break; |
| 268: | case "PUT": |
| 269: | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 270: | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
| 271: | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->payload); |
| 272: | break; |
| 273: | case "DELETE": |
| 274: | |
| 275: | break; |
| 276: | default: |
| 277: | echo 'No methode in Header for' . $this->igsn; |
| 278: | } |
| 279: | |
| 280: | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 281: | |
| 282: | $result["content"] = curl_exec($ch); |
| 283: | $result["errcode"] = curl_errno($ch); |
| 284: | $result["errmsg"] = curl_error($ch); |
| 285: | $result["header"] = curl_getinfo($ch); |
| 286: | curl_close($ch); |
| 287: | return $result; |
| 288: | } |
| 289: | |
| 290: | |
| 291: | |
| 292: | } |
| 293: | |