setCountry() public method

Sets and validates the country
public setCountry ( string $country ) : GenericConfiguration
$country string
return GenericConfiguration
コード例 #1
0
 protected function setUp()
 {
     if (isset($this->conf) && isset($this->apaiIO)) {
         return $this;
     }
     $this->conf = new GenericConfiguration();
     $this->conf->setCountry($this->amazonConf['country'])->setAccessKey($this->amazonConf['amazon_ws_api_key'])->setSecretKey($this->amazonConf['amazon_ws_api_secret_key'])->setAssociateTag($this->amazonConf['amazon_ws_api_associate_tag']);
     $this->apaiIO = new ApaiIO($this->conf);
     return $this;
 }
コード例 #2
0
 public function testCustomConfigurationPassed()
 {
     $configuration = new GenericConfiguration();
     $configuration->setCountry('de')->setAccessKey('ABC')->setSecretKey('DEF')->setAssociateTag('apaiIOTest')->setRequest(new Request());
     $request = RequestFactory::createRequest($configuration);
     $this->assertSame($configuration, \PHPUnit_Framework_Assert::readAttribute($request, 'configuration'));
 }
コード例 #3
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('SimpleAPA', function () {
         $conf = new GenericConfiguration();
         $conf->setCountry('de')->setAccessKey(Config::get('simpleapa.AccessKey'))->setSecretKey(Config::get('simpleapa.SecretKey'))->setAssociateTag(Config::get('simpleapa.AssociateTag'))->setRequest('\\ApaiIO\\Request\\Soap\\Request')->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
         return new SimpleAPA(new ApaiIO($conf));
     });
 }
コード例 #4
0
 public function connect(PaaConfigInterface $config)
 {
     $conf = new GenericConfiguration();
     try {
         $conf->setCountry($config->getCountry())->setAccessKey($config->getAccessKey())->setSecretKey($config->getSecretKey())->setAssociateTag($config->getAssociateTag());
     } catch (\Exception $e) {
         echo $e->getMessage();
         die;
     }
     $this->service = new ApaiIO($conf);
 }
コード例 #5
0
ファイル: EmailController.php プロジェクト: gerardo15/4sale
 public function testamazon()
 {
     $conf = new GenericConfiguration();
     $conf->setCountry('com')->setAccessKey('AKIAIUHJDBWAEKOQI2KQ')->setSecretKey('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')->setAssociateTag('IDTAG')->setRequest('\\ApaiIO\\Request\\Soap\\Request')->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
     $search = new Search();
     $search->setCategory('All');
     $search->setKeywords('Iphone 6s');
     $search->setResponsegroup(array('Offers', 'Images'));
     $apaiIo = new ApaiIO($conf);
     $response = $apaiIo->runOperation($search);
     //return $response["Items"]["Item"][0]["ItemAttributes"]["Title"];
     return $response;
     //test
 }
コード例 #6
0
function GetProductInfoByTitle($title)
{
    $conf = new GenericConfiguration();
    try {
        $conf->setCountry('com')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG);
    } catch (\Exception $e) {
        echo $e->getMessage();
    }
    $apaiIO = new ApaiIO($conf);
    $search = new Search();
    // $lookup->setItemId('B0040PBK32,B00MEKHLLA');
    $search->setCategory('Books');
    $search->setKeywords($title);
    $formattedResponse = $apaiIO->runOperation($search);
    $dom = new DOMDocument();
    $dom->loadXML($formattedResponse);
    $arrResponse = xml_to_array($dom);
    return $arrResponse;
}
コード例 #7
0
ファイル: sample1.php プロジェクト: njbhatt18/Amazon_API
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'bootstrap.php';
require_once 'Config.php';
use ApaiIO\Request\RequestFactory;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Search;
use ApaiIO\ResponseTransformer\ObjectToArray;
use ApaiIO\Operations\Lookup;
use ApaiIO\Operations\SimilarityLookup;
use ApaiIO\Operations\CartCreate;
use ApaiIO\ApaiIO;
use ApaiIO\Operations\BrowseNodeLookup;
use ApaiIO\Operations\CartAdd;
$conf = new GenericConfiguration();
try {
    $conf->setCountry('de')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG);
} catch (\Exception $e) {
    echo $e->getMessage();
}
$apaiIO = new ApaiIO($conf);
$search = new Search();
$search->setCategory('DVD');
$search->setActor('Bruce Willis');
$search->setKeywords('Stirb Langsam');
$search->setPage(3);
$search->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($search);
echo $formattedResponse;
exit;
// var_dump($formattedResponse);
// $cartCreate = new CartCreate();
コード例 #8
0
 public function testCountrySetter()
 {
     $object = new GenericConfiguration();
     $object->setCountry('DE');
     $this->assertEquals('de', $object->getCountry());
 }
コード例 #9
0
ファイル: index.php プロジェクト: nickolasnikolic/his
});
$app->get('/amazon/node/:browsenode', function ($browsenode) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $browseNodeLookup = new BrowseNodeLookup();
    $browseNodeLookup->setNodeId($browsenode);
    $apaiIo = new ApaiIO($conf);
    $response = $apaiIo->runOperation($browseNodeLookup);
    echo json_encode(simplexml_load_string($response));
});
$app->get('/amazon/lookup/:asin', function ($asin) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $apaiIo = new ApaiIO($conf);
    $lookup = new Lookup();
    $lookup->setItemId($asin);
    $lookup->setResponseGroup(array('Large'));
    // More detailed information
    $response = $apaiIo->runOperation($lookup);
    echo json_encode(simplexml_load_string($response));
});
$app->get('/amazon/similar/:asin', function ($asin) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $apaiIo = new ApaiIO($conf);
    $similaritylookup = new SimilarityLookup();
    $similaritylookup->setItemId($asin);
    $response = $apaiIo->runOperation($similaritylookup);
    echo json_encode(simplexml_load_string($response));
});
$app->run();
コード例 #10
0
ファイル: GuzzleRequestTest.php プロジェクト: exeu/apai-io
 public function testSchemeSwitch()
 {
     $body = $this->prophesize('\\Psr\\Http\\Message\\StreamInterface');
     $body->getContents()->shouldBeCalledTimes(1)->willReturn('ABC');
     $response = $this->prophesize('\\Psr\\Http\\Message\\ResponseInterface');
     $response->getBody()->shouldBeCalledTimes(1)->willReturn($body->reveal());
     $client = $this->prophesize('\\GuzzleHttp\\ClientInterface');
     $client->send(Argument::that(function ($request) {
         if (!$request instanceof RequestInterface) {
             return false;
         }
         $uri = $request->getUri();
         $this->assertSame('https', $uri->getScheme());
         return true;
     }))->shouldBeCalledTimes(1)->willReturn($response->reveal());
     $request = new GuzzleRequest($client->reveal());
     $request->setScheme('HTTPS');
     $operation = new Lookup();
     $operation->setItemId('1');
     $config = new GenericConfiguration();
     $config->setAccessKey('abc');
     $config->setAssociateTag('def');
     $config->setCountry('DE');
     $config->setSecretKey('ghi');
     $config->setAccessKey('jkl');
     $request->perform($operation, $config);
 }
コード例 #11
0
ファイル: SimpleLookup.php プロジェクト: exeu/apai-io
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'bootstrap.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Config.php';
use ApaiIO\ApaiIO;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Lookup;
$conf = new GenericConfiguration();
$client = new \GuzzleHttp\Client();
$request = new \ApaiIO\Request\GuzzleRequest($client);
try {
    $conf->setCountry('de')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG)->setRequest($request)->setResponseTransformer(new \ApaiIO\ResponseTransformer\XmlToDomDocument());
} catch (\Exception $e) {
    echo $e->getMessage();
}
$apaiIO = new ApaiIO($conf);
$lookup = new Lookup();
$lookup->setItemId('B0040PBK32,B00MEKHLLA');
$lookup->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($lookup);
var_dump($formattedResponse);
コード例 #12
0
 /**
  * @Route(
  *    path = "/search/searchByText/{text}",
  *    name = "searchByText",
  *    defaults={"text" = "012345678901"}
  * )
  */
 public function searchByTextAction(Request $request)
 {
     /* TODO: DISPLAYING A MESSAGE WHEN NOTHING HAS BEEN FOUND */
     /* DISPLAYING THE INPUT FORM */
     $textQuery = array('text' => '');
     $form = $this->createFormBuilder($textQuery)->setAction($this->generateUrl('searchByText'))->setMethod('GET')->add('text', TextType::class, array('label' => 'Keywords', 'attr' => array('class' => 'form-control')))->add('submit', SubmitType::class, array('label' => 'Look for possible equivalent items', 'attr' => array('class' => 'btn btn-default')))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted()) {
         // Form has been submitted or some text has been passed in the URL
         $data = $form->getData();
         if ($data['text'] != '') {
             $text = $data['text'];
         }
         // ... perform some action, such as saving the task to the database
         //$resString = print_r($data);
         //return(new Response($resString));
         /*
         searching by text,
         if found displaying what has been found
         */
         // TODO:
         // moving configuration data outside in a configuration file
         $conf = new GenericConfiguration();
         $conf->setCountry('com')->setAccessKey('AKIAJD57F37W2KGLXEVQ')->setSecretKey('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')->setAssociateTag('quercusroburn-20')->setRequest('\\ApaiIO\\Request\\Soap\\Request');
         $query = new Search();
         $query->setKeywords($text);
         $query->setCategory('Music');
         $query->setResponseGroup(array('ItemAttributes', 'Images', 'Tracks'));
         // More detailed information
         $apaiIo = new ApaiIO($conf);
         $response = $apaiIo->runOperation($query);
         $logger = $this->get('logger');
         $records = array();
         if (property_exists($response, 'Items')) {
             // handlig the case when one item only is returned,
             // in that case $response->Items->Item is not an array!!!
             $results = array();
             if (is_array($response->Items->Item)) {
                 $results = $response->Items->Item;
             } else {
                 $results[] = $response->Items->Item;
             }
             foreach ($results as $item) {
                 $logger->info('----------------------------');
                 $record = new Record();
                 // ASIN
                 $logger->info("ASIN: {$item->ASIN}");
                 $record->setAsin($item->ASIN);
                 // TODO:
                 // now getting UPC just for testing purposes,
                 // this should be stopped...
                 if (property_exists($item->ItemAttributes, 'UPC')) {
                     $logger->info('UPC: ' . $item->ItemAttributes->UPC);
                 } else {
                     $logger->info('NO UPC!');
                 }
                 // Artist
                 // Structure changes if several artists are listed
                 if (property_exists($item->ItemAttributes, 'Artist')) {
                     if (!is_array($item->ItemAttributes->Artist)) {
                         $record->setArtist($item->ItemAttributes->Artist);
                     } else {
                         $logger->info('Here it is the array: ' . print_r($item->ItemAttributes->Artist, true) . ' - Seen as: ' . gettype($item->ItemAttributes->Artist) . ' - size: ' . sizeof($item->ItemAttributes->Artist));
                         $artist = 'Various artists (';
                         for ($i = 1; $i < sizeof($item->ItemAttributes->Artist); $i++) {
                             $artist .= $item->ItemAttributes->Artist[$i];
                             if ($i < sizeof($item->ItemAttributes->Artist) - 1) {
                                 $artist .= ', ';
                             }
                         }
                         $artist .= ')';
                         $record->setArtist($artist);
                         $logger->info('Values: ' . join(' - ', $item->ItemAttributes->Artist));
                     }
                     $logger->info('Artist: ' . $record->getArtist());
                 }
                 // title
                 $record->setTitle($item->ItemAttributes->Title);
                 $logger->info('Title: ' . $record->getTitle());
                 // label
                 if (property_exists($item->ItemAttributes, 'Brand')) {
                     $record->setRecordLabel($item->ItemAttributes->Brand);
                 } else {
                     if (property_exists($item->ItemAttributes, 'Label')) {
                         $record->setRecordLabel($item->ItemAttributes->Label);
                     } else {
                         //
                     }
                 }
                 $logger->info('Label: ' . $record->getRecordLabel());
                 // Year
                 if (property_exists($item->ItemAttributes, 'ReleaseDate')) {
                     $record->setYear(substr($item->ItemAttributes->ReleaseDate, 0, 4));
                     $logger->info('Label: ' . $record->getYear());
                 } else {
                     $logger->info('\'ReleaseDate\' not available, so dunno how to get the year...');
                 }
                 // Media count
                 if (property_exists($item->ItemAttributes, 'NumberOfItems')) {
                     $record->setMediaCount($item->ItemAttributes->NumberOfItems);
                     $logger->info('Media count: ' . $record->getMediaCount());
                 } else {
                     if (property_exists($item->ItemAttributes, 'NumberOfDiscs')) {
                         $record->setMediaCount($item->ItemAttributes->NumberOfDiscs);
                         $logger->info('Media count: ' . $record->getMediaCount());
                     } else {
                         //$logger->info(print_r($item->ItemAttributes, true));
                         $logger->info('Number of media not available. Now what?! Tentatively I guess the value \'1\'.');
                         $record->setMediaCount('1');
                         $item->ItemAttributes->NumberOfItems = '1';
                     }
                 }
                 // Media type
                 $record->setMediaType($item->ItemAttributes->Binding);
                 $logger->info('Media type: ' . $record->getMediaType());
                 // Cover image (it may be unavailable)
                 if (property_exists($item, 'LargeImage')) {
                     $record->setCoverImageUrl($item->LargeImage->URL);
                     $logger->info('Cover image URL: ' . $record->getCoverImageUrl());
                 }
                 // each media item has a track list
                 $trackLists = array();
                 if (property_exists($item, 'Tracks')) {
                     // Tracks info is not for granted...
                     // When number of media/items is greater than 1, but
                     // the tracks list is just one
                     // (it happened at least once with B000B66OVW, see EX03 below)
                     // then ->Tracks->Disc is not an array at it should be
                     // when more than one media are actually present
                     $oneListOnly = 0;
                     if (!is_array($item->Tracks->Disc)) {
                         $logger->info('The web service reported ' . $record->getMediaCount() . ' media, but all tracks are in just one list.');
                         $oneListOnly = 1;
                     }
                     if ($record->getMediaCount() < 2 || $oneListOnly) {
                         // one item only, one list
                         if (property_exists($item->Tracks, 'Disc')) {
                             $totalTracks = sizeof($item->Tracks->Disc->Track);
                             for ($i = 0; $i < $totalTracks; $i++) {
                                 $tracksLists[0][] = $item->Tracks->Disc->Track[$i]->_;
                             }
                         } else {
                             $logger->info('Couldn\'t find "Disc"...   ' . print_r($item->Tracks, true));
                         }
                     } else {
                         for ($j = 0; $j < $record->getMediaCount(); $j++) {
                             $totalTracks = sizeof($item->Tracks->Disc[$j]->Track);
                             for ($i = 0; $i < $totalTracks; $i++) {
                                 $tracksLists[$j][] = $item->Tracks->Disc[$j]->Track[$i]->_;
                             }
                         }
                     }
                     $record->setTracksLists($tracksLists);
                 } else {
                     // Tracks info is not available (no property "Tracks" in the object)
                     $logger->info('Tracks info is not available');
                 }
                 // Appending the record to the list of possible records
                 $records[] = $record;
             }
         }
         // TODO:
         // saving the array of results in session
         $session = new Session();
         //$session->start();
         $session->set('results', $records);
         $logger->info('Session ID: ' . $session->getId());
         // Returning the list of the results
         // TODO:
         // handling in the template the id of each record, so that in can be passed
         // afterwards for insertion and recovered from session without re-fetching
         // its data
         return $this->render('AppBundle:Record:results.html.twig', array('records' => $records));
     }
     // The form has not been submitted, displaying the form
     return $this->render('AppBundle:Record:searchByText.html.twig', array('form' => $form->createView()));
 }
コード例 #13
0
ファイル: index.php プロジェクト: HEAR/2016-db.print
:!:  !:!  :!:  !:!  :!:  :!:       :!:  !:!  :!:  :!:  !:!    :!:
 :::: ::   :: ::::  :::   ::       ::   :::   ::   ::   ::     ::
:: :  :   :: : ::   :::   :         :   : :  :    ::    :      :
*/
// se créer un compte gratuit
// https://aws.amazon.com/fr/api-gateway/pricing/
// https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
namespace Acme\Demo;

require __DIR__ . '/vendor/autoload.php';
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Search;
use ApaiIO\ApaiIO;
include_once 'param.php';
$conf = new GenericConfiguration();
$conf->setCountry('fr')->setAccessKey(AMAZON_API_KEY)->setSecretKey(AMAZON_API_SECRET_KEY)->setAssociateTag(AMAZON_ASSOCIATE_TAG)->setRequest('\\ApaiIO\\Request\\Soap\\Request')->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
// ->setResponseTransformer('\ApaiIO\ResponseTransformer\ObjectToArray');
$apaiIO = new ApaiIO($conf);
// http://exeu.github.io/apai-io/
// http://exeu.github.io/apai-io/basic-usage.html
$search = new Search();
$search->setCategory('Books');
// DVD
// $search->setActor('Bruce Willis');
// http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html
$search->setKeywords('Le seigneur des anneaux');
$search->setResponsegroup(array('Images', 'EditorialReview'));
$formattedResponse = $apaiIO->runOperation($search);
file_put_contents('amazon.json', json_encode($formattedResponse));
file_put_contents('image.jpg', file_get_contents($formattedResponse['Items']['Item'][0]["LargeImage"]['URL']));
var_dump($formattedResponse['Items']['Item'][0]["EditorialReviews"]["EditorialReview"]["Content"]);