Last active
June 4, 2021 03:08
-
-
Save peterjaap/057b22110f2f0f17d7c48510a64323b1 to your computer and use it in GitHub Desktop.
Revisions
-
peterjaap revised this gist
Apr 24, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,8 +36,6 @@ $data = 'bins=' . implode(':', $bin) . '&items=' . $itemString; $previewData = $data . '&binId=' . $bin['id']; $params = array('http' => array( 'method' => 'POST', 'content' => $data -
peterjaap revised this gist
Apr 24, 2018 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,22 +5,20 @@ $bin = [ 'id' => 0, 'maxweight' => 50, 'dimensions' => '5x5x5' ]; $items = []; $items[] = [ 'binId' => 0, 'id' => 0, 'weight' => 15, 'dimensions' => '1x1x1', ]; $items[] = [ 'binId' => 0, 'id' => 1, 'weight' => 15, 'dimensions' => '3x3x3', ]; $items[] = [ @@ -38,6 +36,8 @@ $data = 'bins=' . implode(':', $bin) . '&items=' . $itemString; $previewData = $data . '&binId=' . $bin['id']; var_dump($previewData); $params = array('http' => array( 'method' => 'POST', 'content' => $data @@ -56,7 +56,7 @@ $previewParams = array('http' => array( 'header' => "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: ".strlen($previewData)."\r\n". "User-Agent:peterjaap-packit4me/1.0\r\n", 'method' => 'POST', 'content' => $previewData )); -
peterjaap revised this gist
Apr 24, 2018 . 1 changed file with 35 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,41 @@ $url = "http://www.packit4me.com/api/call/raw"; $previewUrl = "http://www.packit4me.com/api/call/preview"; $bin = [ 'id' => 0, 'maxweight' => 50, 'length' => 5, 'width' => 5, 'depth' => 5 ]; $items = []; $items[] = [ 'binId' => 0, 'id' => 0, 'weight' => 15, 'dimensions' => '5x5x5', ]; $items[] = [ 'binId' => 0, 'id' => 1, 'weight' => 5, 'dimensions' => '3x3x3', ]; $items[] = [ 'binId' => 0, 'id' => 2, 'weight' => 5, 'dimensions' => '2x5x1', ]; $itemStringParts = []; foreach ($items as $item) { $itemStringParts[] = implode(':', $item); } $itemString = implode(',', $itemStringParts); $data = 'bins=' . implode(':', $bin) . '&items=' . $itemString; $previewData = $data . '&binId=' . $bin['id']; $params = array('http' => array( 'method' => 'POST', -
peterjaap created this gist
Apr 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <?php $url = "http://www.packit4me.com/api/call/raw"; $previewUrl = "http://www.packit4me.com/api/call/preview"; $data = "bins=0:50:5x5x5&items=0:0:15:1x1x1,0:1:15:3x3x3,0:2:5:2x5x1"; $previewData = $data . '&&binId=0'; $params = array('http' => array( 'method' => 'POST', 'content' => $data )); $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with url"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from url"); } $previewParams = array('http' => array( 'header' => "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: ".strlen($previewData)."\r\n". "User-Agent:MyAgent/1.0\r\n", 'method' => 'POST', 'content' => $previewData )); $ctx = stream_context_create($previewParams); $fp = fopen($previewUrl, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with url"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from url"); } echo str_replace('/resources/', 'http://www.packit4me.com/resources/', $response);