Development

Changeset 4769

You must first sign up to be able to contribute.

Changeset 4769

Show
Ignore:
Timestamp:
08/01/07 00:28:57 (1 year ago)
Author:
Jonathan.Wage
Message:

sfISBNPlugin: General development.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfISBNPlugin/lib/BasesfISBN.class.php

    r4736 r4769  
    1818class BasesfISBN 
    1919{ 
    20   protected $amazonAWS        = null, 
    21             $sellers          = array('CommissionJunction'); 
     20  protected $amazonECS        = null, 
     21            $apis             = array('CommissionJunction'); 
    2222   
    2323  public function __construct() 
     
    3030    } 
    3131     
    32     $this->amazonAWS = new sfAmazonECS($config['access_key_id']); 
     32    $this->amazonECS = new sfAmazonECS($config['access_key_id']); 
    3333  } 
    3434   
    35   public function getISBN($isbn
     35  public function getAmazonECS(
    3636  { 
    37     $result = $this->amazonAWS->ItemLookup($isbn, null, null, 'Large'); 
     37    return $this->amazonECS; 
     38  } 
     39   
     40  public function findByISBN($isbn) 
     41  { 
     42    // Convert from 10 to 13 if necessary 
     43    $isbn = sfISBNNumber::convert($isbn, 10, 13); 
    3844     
    39     return $result->Items->Item; 
     45    $result = $this->amazonECS->ItemLookup($isbn, 'ISBN', 'Books', 'Large'); 
     46     
     47    if( isset($result->Items->Item) ) 
     48    { 
     49      return $result->Items->Item; 
     50    } 
    4051  } 
    4152   
     
    4657    $params['Sort'] = $sort; 
    4758     
    48     $result = $this->amazonAWS->ItemSearch($keywords, 'Books', $page, 'Large', $params); 
     59    $result = $this->amazonECS->ItemSearch($keywords, 'Books', $page, 'Large', $params); 
    4960     
    5061    if( isset($result->Items) ) 
     
    5667  } 
    5768   
    58   public function getOffers($isbn
     69  public function getOffers($isbn, $apis = array(), $params = array()
    5970  { 
    60     $isbnInfo = $this->getIsbn($isbn); 
     71    $isbnInfo = $this->findByISBN($isbn); 
    6172     
    6273    $offers = array(); 
    63     $offers['amazon'] = $isbnInfo->Offers; 
     74    $amazonOffers = isset($isbnInfo->Offers->Offer) ? $isbnInfo->Offers->Offer:array(); 
     75    $offers['Amazon'] = !is_array($amazonOffers) ? array($amazonOffers):$amazonOffers; 
    6476     
    65     foreach($this->sellers AS $seller
     77    foreach($this->apis AS $api
    6678    { 
    67       $sellerDriver = self::getSellerDriver($seller); 
     79      // If an array of apis was passed then lets skip all apis that are not in the array 
     80      // This is so you can specify what all apis you wish to get the offers from 
     81      if( !empty($apis) && !in_array($api, $apis) ) 
     82      { 
     83        continue; 
     84      } 
    6885       
    69       $offers[$seller] = $sellerDriver->getOffers($isbn); 
     86      $apiDriver = self::getApiDriver($api); 
     87       
     88      $apiParams = isset($params[$api]) ? $params[$api]:array(); 
     89       
     90      $offers[$api] = $apiDriver->getOffers($isbn, $apiParams); 
    7091    } 
    7192     
     
    7394  } 
    7495   
    75   static protected function getSellerDriver($seller
     96  static protected function getApiDriver($api
    7697  { 
    77     $className = 'sfISBN'.$seller.'Driver'; 
    78     $sellerConfig = sfInflector::underscore($seller); 
     98    $className = 'sfISBN'.$api.'Driver'; 
     99    $apiConfig = sfInflector::underscore($api); 
    79100     
    80     return new $className(sfConfig::get('app_isbn_'.$sellerConfig)); 
     101    return new $className(sfConfig::get('app_isbn_'.$apiConfig)); 
    81102  } 
    82103} 
  • plugins/sfISBNPlugin/lib/sfISBNCommissionJunctionDriver.class.php

    r4736 r4769  
    2727  } 
    2828   
    29   public function getOffers($isbn
     29  public function getOffers($isbn, $params = array()
    3030  { 
    31     $result = $this->commissionJunction->bookLookup($isbn); 
     31    // Make sure the isbn is 10 digits if 13 is passed 
     32    $isbn = sfISBNNumber::convert($isbn, 13, 10); 
    3233     
    33     return $result->out->products->Product; 
     34    $result = $this->commissionJunction->bookLookup($isbn, $params); 
     35     
     36    if( isset($result->out->products->Product) ) 
     37    { 
     38      $offers = $result->out->products->Product; 
     39      $offers = !is_array($offers) ? array($offers):$offers; 
     40       
     41      return $offers; 
     42    } else { 
     43      return array(); 
     44    } 
    3445  } 
    3546} 
  • plugins/sfISBNPlugin/lib/sfISBNNumber.class.php

    r4736 r4769  
    1818class sfISBNNumber 
    1919{ 
     20  static public function convert($isbn, $from, $to) 
     21  { 
     22    if( self::getISBNType($isbn) == 13 AND $from == 13 AND $to == 10 ) 
     23    { 
     24      $isbn = self::thirteenToTen($isbn); 
     25    } 
     26     
     27    if( self::getISBNType($isbn) == 10 AND $from == 10 AND $to == 13 ) 
     28    { 
     29      $isbn = self::tenToThirteen($isbn); 
     30    } 
     31     
     32    return $isbn; 
     33  } 
     34   
    2035  static public function thirteenToTen($isbn13) 
    2136  {