require "consumer_key.php";
require "access_token.php";
require "api_url_base.php";
require "error.php";
try {
    $oauth = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->enableDebug();
    $oauth->setToken($access_token, $access_secret);
} catch (OAuthException $E) {
    Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
    $orderId = 12345;
    // CHANGEME
    $data = array("orderId" => $orderId);
    $data_string = json_encode($data);
    $oauth->fetch($api_url_base . "/orders/{$orderId}/v1", null, OAUTH_HTTP_METHOD_GET, array("Accept" => "application/json"));
    $response = $oauth->getLastResponse();
    $json = json_decode($response);
    if (null == $json) {
        PrintJsonLastError();
        var_dump($response);
    } else {
        print_r($json);
    }
} catch (OAuthException $E) {
    Error("fetch exception", $E->getMessage(), null, $oauth->getLastResponseInfo(), $E->debugInfo);
}
?>

// NOTE - You must have special access to use this endoint. To request access, please submit the form here - https://www.shapeways.com/contact/contact-form?email_to=service%2Bbizdev@shapeways.com
require "consumer_key.php";
require "access_token.php";
require "api_url_base.php";
require "error.php";
try {
    $oauth = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->enableDebug();
    $oauth->setToken($access_token, $access_secret);
} catch (OAuthException $E) {
    Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
    $items = array(array('modelId' => 1234, 'materialId' => 95, 'quantity' => 1, 'productDimensionChoiceCombo' => 0));
    $data = array("firstName" => "John", "lastName" => "Doe", "country" => "United States", "state" => "NY", "city" => "New York", "address1" => "123 Street Name", "address2" => "Apt 1", "address3" => "Company Name", "zipCode" => "11111", "phoneNumber" => "11111111111", "items" => $items, "paymentVerificationId" => "ABCD", "paymentMethod" => "credit_card", "shippingOption" => "Cheapest");
    $data_string = json_encode($data);
    $oauth->fetch($api_url_base . "/orders/v1", $data_string, OAUTH_HTTP_METHOD_POST, array("Accept" => "application/json"));
    $response = $oauth->getLastResponse();
    $json = json_decode($response);
    if (null == $json) {
        PrintJsonLastError();
        var_dump($response);
    } else {
        print_r($json);
    }
} catch (OAuthException $E) {
    Error("fetch exception", $E->getMessage(), null, $oauth->getLastResponseInfo(), $E->debugInfo);
}
?>

#!/usr/bin/php
<?php 
require "consumer_key.php";
require "access_token.php";
require "api_url_base.php";
require "error.php";
try {
    $oauth = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->enableDebug();
    $oauth->setToken($access_token, $access_secret);
} catch (OAuthException $E) {
    Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
    $oauth->fetch($api_url_base . "/materials/v1", null, OAUTH_HTTP_METHOD_GET, array("Accept" => "application/json"));
    $response = $oauth->getLastResponse();
    $json = json_decode($response);
    if (null == $json) {
        PrintJsonLastError();
        var_dump($response);
    } else {
        print_r($json);
    }
} catch (OAuthException $E) {
    Error("fetch exception", $E->getMessage(), null, $oauth->getLastResponseInfo(), $E->debugInfo);
}
?>

require "consumer_key.php";
require "access_token.php";
require "api_url_base.php";
require "error.php";
try {
    $oauth = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->enableDebug();
    $oauth->setToken($access_token, $access_secret);
} catch (OAuthException $E) {
    Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
    $modelId = 1234567;
    # CHANGEME
    $modelVersion = 0;
    # CHANGEME
    $oauth->fetch($api_url_base . "/models/{$modelId}/files/{$modelVersion}/v1?file=1", null, OAUTH_HTTP_METHOD_GET, array("Accept" => "application/json"));
    $response = $oauth->getLastResponse();
    $json = json_decode($response);
    if (null == $json) {
        PrintJsonLastError();
        var_dump($response);
    } else {
        print_r($json);
    }
} catch (OAuthException $E) {
    Error("fetch exception", $E->getMessage(), null, $oauth->getLastResponseInfo(), $E->debugInfo);
}
?>

<?php

if (isset($_POST['token'])) {
    try {
        $oauth_client = new Oauth("key", "secret");
        $oauth_client->enableDebug();
        $oauth_client->setToken($_POST['token'], $_POST['token_secret']);
        $oauth_client->fetch("http://192.168.187.132/oauth/api/user");
        echo "API RESULT : " . $oauth_client->getLastResponse();
    } catch (OAuthException $E) {
        echo $E->debugInfo;
    }
} else {
    ?>
	<form method="post">
		Access token : <input type="text" name="token" value="<?php 
    echo $_REQUEST['token'];
    ?>
" /> <br />
		Access token secret : <input type="text" name="token_secret" value="<?php 
    echo $_REQUEST['token_secret'];
    ?>
" /> <br />
		<input type="submit" value="do An api call" />
	</form>
	<?php 
}