2017 © Pedro Peláez
 

library fetchapp

A PHP library for access to version 2.0 of the FetchApp API

image

fetchapp/fetchapp

A PHP library for access to version 2.0 of the FetchApp API

  • Thursday, July 21, 2016
  • by prcapps
  • Repository
  • 4 Watchers
  • 2 Stars
  • 324 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 3 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

fetchapp-php-2.0

A PHP library for version 2.0 of the FetchApp API, (*1)

Getting Account Information


use FetchApp\API\FetchApp; // Create a new FetchApp instance $fetch = new FetchApp(); // Set the Authentication data (needed for all requests) $fetch->setAuthenticationKey("demokey"); $fetch->setAuthenticationToken("demotoken"); try{ // Let's grab our Account data to make sure that everything is working! $account = $fetch->getAccountDetails();// That was easy! // Let's write some of the available Data to the page! echo $account->getAccountID(); echo $account->getAccountName(); echo $account->getBillingEmail(); echo $account->getEmailAddress(); echo $account->getURL(); echo $account->getItemDownloadLimit(); echo $account->getOrderExpirationInHours(); } catch (Exception $e){ // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set. echo $e->getMessage(); }

Getting Order Information

Getting All Orders

use FetchApp\API\FetchApp;
use FetchApp\API\OrderStatus;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");;
try{
    // Let's grab our Orders!
    $orders = $fetch->getOrders(); // Grabs all orders (potentially HUGE!)
                    // or
    $orders = $fetch->getOrders(OrderStatus::All, 50, 4); // Grabs orders of all types, 50 per page, page 4.
                    // or
    $orders = $fetch->getOrders(OrderStatus::Expired); // Grabs all expired orders.
                    // or
    $orders = $fetch->getOrders(OrderStatus::Open); // Grabs all open orders
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}
// Now let's print our results!
foreach ($orders as $order) {
    echo $order->getOrderID().PHP_EOL;
    echo $order->getVendorID().PHP_EOL;
    echo $order->getFirstName().PHP_EOL;
    echo $order->getLastName().PHP_EOL;
    echo $order->getEmailAddress().PHP_EOL;
    echo $order->getTotal().PHP_EOL;
    echo $order->getCurrency().PHP_EOL;
    echo $order->getStatus().PHP_EOL;
    echo $order->getProductCount().PHP_EOL;
    echo $order->getDownloadCount().PHP_EOL;
    $expirationDate = $order->getExpirationDate();
    // Since ExpirationDate is a DateTime, we need to print it with a format.
    echo $expirationDate->format('F j, Y').PHP_EOL;
    echo $order->getDownloadLimit().PHP_EOL;
    echo $order->getCustom1().PHP_EOL;
    echo $order->getCustom2().PHP_EOL;
    echo $order->getCustom3().PHP_EOL;
    $creationDate = $order->getCreationDate();
    // Since CreationDate is a DateTime, we need to print it with a format.
    echo $creationDate->format('F j, Y').PHP_EOL;
}

Getting a Single Order

use FetchApp\API\FetchApp;
use FetchApp\API\OrderStatus;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");
try{
    // Let's grab our Orders!
    $order = $fetch->getOrder("B007");
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}
// Now let's print our result!
echo $order->getOrderID().PHP_EOL;
echo $order->getVendorID().PHP_EOL;
echo $order->getFirstName().PHP_EOL;
echo $order->getLastName().PHP_EOL;
echo $order->getEmailAddress().PHP_EOL;
echo $order->getTotal().PHP_EOL;
echo $order->getCurrency().PHP_EOL;
echo $order->getStatus().PHP_EOL;
echo $order->getProductCount().PHP_EOL;
echo $order->getDownloadCount().PHP_EOL;
$expirationDate = $order->getExpirationDate();
// Since ExpirationDate is a DateTime, we need to print it with a format.
echo $expirationDate->format('F j, Y').PHP_EOL;
echo $order->getDownloadLimit().PHP_EOL;
echo $order->getCustom1().PHP_EOL;
echo $order->getCustom2().PHP_EOL;
echo $order->getCustom3().PHP_EOL;
$creationDate = $order->getCreationDate();
// Since CreationDate is a DateTime, we need to print it with a format.
echo $creationDate->format('F j, Y').PHP_EOL;

Creating an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new Order();
    $order->setOrderID("B008");
    $order->setFirstName("James");
    $order->setLastName("Bond");
    $order->setEmailAddress("007@mi6.com");
    $order->setVendorID("M002");
    $order->setCurrency(Currency::GBP);
    $order->setCustom1("Herp");
    $order->setCustom3("Derp");
    $order->setExpirationDate(new DateTime("2015/12/24"));
    $order->setDownloadLimit(12);

    $items = array();
    // Add items to the item array
    $order_item = new OrderItem();
    $order_item->setSKU('TestSKU');
    array_push($items, $order_item);

    $response = $order->create($items, false);
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Updating an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $order->setOrderID("B008");
    $order->setFirstName("James");
    $order->setLastName("Bond");
    $order->setEmailAddress("007@mi6.com");
    $order->setVendorID("M002");
    $order->setCurrency(Currency::GBP);
    $order->setCustom1("Herp");
    $order->setCustom3("Derp");
    $order->setExpirationDate(new DateTime("2015/12/24"));
    $order->setDownloadLimit(12);
    $items = $order->getItems(); // Get the existing order items

    $response = $order->update($items, false);
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Deleting an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $response = $order->delete();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get statistics for an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;
use FetchApp\API\OrderStatistic;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $statistics = $order->getStatistics();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get Downloads for an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;
use FetchApp\API\OrderDownload;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $downloads = $order->getDownloads();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Expire an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $response = $order->expire();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Re-send a download email for an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $response = $order->sendDownloadEmail();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Getting Product Information

Getting All Products

use FetchApp\API\FetchApp;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");;
try{
    // Let's grab our Products!
    $products = $fetch->getProducts(); // Grabs all products (potentially HUGE!)
                    // or
    $products = $fetch->getProducts(50, 4); // Grabs products, 50 per page, page 4.
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}
// Now let's print our results!
foreach ($products as $product) {
    echo $product->getProductID().PHP_EOL;
    echo $product->getName().PHP_EOL;    
    echo $product->getSKU().PHP_EOL;    
}

Getting a Single Product

use FetchApp\API\FetchApp;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");
try{
    // Let's grab our Product!
    $product = $fetch->getProduct(123);
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}
// Now let's print our result!
echo $product->getProductID().PHP_EOL;
    echo $product->getName().PHP_EOL;    
    echo $product->getSKU().PHP_EOL;   

Creating a Product

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Product;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new Product();
    $product->setSKU(123);
    $product->setName("Test Product");
    $product->setPrice(3.00);
    $product->setCurrency(Currency::GBP);

    $files = array();
    // Add files to the file array

    $response = $product->create($files, false);
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Updating a Product

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Product;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new FetchApp->getProduct(123);
    $product->setSKU(123);
    $product->setName("Test Product");
    $product->setPrice(3.00);
    $product->setCurrency(Currency::GBP);

    $urls = array(array("url" => "http://s3.aws/download.mp3", "name" => "audio"));
    $response = $product->update($urls, false);
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Deleting a Product

use FetchApp\API\FetchApp;
use FetchApp\API\Product;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new FetchApp->getProduct(123);
    $response = $product->delete();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get files for a Product

use FetchApp\API\FetchApp;
use FetchApp\API\Product;
use FetchApp\API\FileDetail;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new FetchApp->getProduct(123);
    $files = $product->getFiles();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get statistics for a Product

use FetchApp\API\FetchApp;
use FetchApp\API\Product;
use FetchApp\API\ProductStatistic;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new FetchApp->getProduct(123);
    $statistics = $product->getStatistics();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get Downloads for a Product

use FetchApp\API\FetchApp;
use FetchApp\API\Product;
use FetchApp\API\OrderDownload;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $product = new FetchApp->getProduct(123);
    $downloads = $product->getDownloads();
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Getting OrderItem Information

Get all OrderItems for an Order

use FetchApp\API\Currency;
use FetchApp\API\FetchApp;
use FetchApp\API\Order;
use FetchApp\API\OrderItem;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $items = $order->getItems(); // Get the existing order items
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get files for an OrderItem

use FetchApp\API\FetchApp;
use FetchApp\API\OrderItem;
use FetchApp\API\FileDetail;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $items = $order->getItems(); // Get the existing order items
    foreach($items as $orderitem):
        $files = $orderitem->getFiles();
    endforeach;
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Get Downloads for an OrderItem

use FetchApp\API\FetchApp;
use FetchApp\API\OrderItem;
use FetchApp\API\OrderDownload;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");

try{
    $order = new FetchApp->getOrder(123);
    $items = $order->getItems(); // Get the existing order items
    foreach($items as $orderitem):
        $downloads = $orderitem->getDownloads();
    endforeach;
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Getting Download Information

Getting All Downloads for an Account

use FetchApp\API\FetchApp;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");;
try{
    // Let's grab our Downloads!
    $downloads = $fetch->getDownloads(); // Grabs all downloads
                    // or
    $downloads = $fetch->getDownloads(50, 4); // Grabs downloads, 50 per page, page 4.
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

Getting File Information

Getting All Files for an Account

use FetchApp\API\FetchApp;

// Create a new FetchApp instance
$fetch = new FetchApp();

// Set the Authentication data (needed for all requests)
$fetch->setAuthenticationKey("demokey");
$fetch->setAuthenticationToken("demotoken");;
try{
    // Let's grab our Files!
    $files = $fetch->getFiles(); // Grabs all files
                    // or
    $files = $fetch->getFiles(50, 4); // Grabs files, 50 per page, page 4.
}
catch (Exception $e){
    // This will occur on any call if the AuthenticationKey and AuthenticationToken are not set.
    echo $e->getMessage();
}

The Versions

21/07 2016

dev-master

9999999-dev

A PHP library for access to version 2.0 of the FetchApp API

  Sources   Download

by Brendon Dugan
by Patrick Conant
by Michael Larkin