Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active June 4, 2021 03:08
Show Gist options
  • Select an option

  • Save peterjaap/057b22110f2f0f17d7c48510a64323b1 to your computer and use it in GitHub Desktop.

Select an option

Save peterjaap/057b22110f2f0f17d7c48510a64323b1 to your computer and use it in GitHub Desktop.

Revisions

  1. peterjaap revised this gist Apr 24, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions packit4me.php
    Original file line number Diff line number Diff line change
    @@ -36,8 +36,6 @@
    $data = 'bins=' . implode(':', $bin) . '&items=' . $itemString;
    $previewData = $data . '&binId=' . $bin['id'];

    var_dump($previewData);

    $params = array('http' => array(
    'method' => 'POST',
    'content' => $data
  2. peterjaap revised this gist Apr 24, 2018. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions packit4me.php
    Original file line number Diff line number Diff line change
    @@ -5,22 +5,20 @@
    $bin = [
    'id' => 0,
    'maxweight' => 50,
    'length' => 5,
    'width' => 5,
    'depth' => 5
    'dimensions' => '5x5x5'
    ];

    $items = [];
    $items[] = [
    'binId' => 0,
    'id' => 0,
    'weight' => 15,
    'dimensions' => '5x5x5',
    'dimensions' => '1x1x1',
    ];
    $items[] = [
    'binId' => 0,
    'id' => 1,
    'weight' => 5,
    '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:MyAgent/1.0\r\n",
    "User-Agent:peterjaap-packit4me/1.0\r\n",
    'method' => 'POST',
    'content' => $previewData
    ));
  3. peterjaap revised this gist Apr 24, 2018. 1 changed file with 35 additions and 2 deletions.
    37 changes: 35 additions & 2 deletions packit4me.php
    Original 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";
    $data = "bins=0:50:5x5x5&items=0:0:15:1x1x1,0:1:15:3x3x3,0:2:5:2x5x1";
    $previewData = $data . '&&binId=0';
    $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',
  4. peterjaap created this gist Apr 24, 2018.
    41 changes: 41 additions & 0 deletions packit4me.php
    Original 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);