Skip to content

Instantly share code, notes, and snippets.

@saranyan
saranyan / Headers.txt
Created February 7, 2012 18:30
PHP and Ruby sample to send Avro messages to X.commerce fabric
AUTHORIZATION : Bearer QkEAARgyi3MPFsmP8St6L2Yc07DkYKQRt5MNo/7caN75haGqDTFDNH/meyYIpKa19Qt1rw==
X_XC_MESSAGE_GUID : f72b7e90-f7ee-4964-901b-6e2427a7c680
X_XC_PUBLISHER : TUQAAXOrYY3iyGbbL6IvNPGWJMaw4CrLBE7QTXIUFuJgo6gBIWPrCwOkXfhMLTbOJXAepw==
X_XC_SCHEMA_URI : https://ocl.xcommercecloud.com/marketplace/profile/deleted/1.0.0
X_XC_SCHEMA_VERSION : 1.0.0
X_XC_TENANT_ID : VEkAAalGt+ye8hDbMXeh8BAquNa72oifsoQNEtjQ9mTzZ8czA7M0+AcJQvDVVsN51DUgNw==
@saranyan
saranyan / environment.properties
Created February 7, 2012 19:23
Developer package contents
#XFabric properties
xfabric.endpoint=https://api.sandbox.x.com/fabric
xfabric.message.content.type=avro/binary
#capability emulator properties
emulator.port=9090
emulator.tenant.token=<PUT EMULATOR SPECIFIC TENANT BEARER TOKEN HERE>
#Enduser(test) capability - aka scratchpad - properties
scratchpad.port=9091
@saranyan
saranyan / mangento_google_data.php
Created March 6, 2012 23:49
Populate Magento installation with GPS Feed data for convenience
<?php
//Based and modified from
//http://www.idriss.us/web-development/php/programmatically-creating-products-magento-14x/
// This function gets product information from the Google product search site using the supplied API key and query string
function getGoogleProducts($apikey, $query)
{
// model URL - https://www.googleapis.com/shopping/search/v1/public/products/?key=KEY&q=QUERY&country=US
$url = "https://www.googleapis.com/shopping/search/v1/public/products/?key=".$apikey."&q=".$query."&country=US";
@saranyan
saranyan / Xcommerce_All.xml
Created March 7, 2012 18:41
Magento Config file for module
<?xml version="1.0"?>
<config>
<modules>
<Xcommerce_Cse>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Xcommerce_Cse>
</modules>
</config>
@saranyan
saranyan / config.xml
Created March 7, 2012 18:58
Magento sample config file
<?xml version="1.0"?>
<config>
<modules>
<Xcommerce_Cse>
<version>0.1.0</version>
</Xcommerce_Cse>
</modules>
<global>
<models>
@saranyan
saranyan / AdminController.php
Created March 7, 2012 19:03
Admin controller Magento Sample
<?php
class Xcommerce_Cse_AdminController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout()
->_addContent($this->getLayout()->createBlock('cse/listProducts'))
->renderLayout();
}
@saranyan
saranyan / ListProducts.php
Created March 7, 2012 19:09
Block Code Magento Sample to publish to X.commerce fabric
<?php
class Xcommerce_Cse_Block_ListProducts extends Mage_Core_Block_Template
{
protected function _toHtml()
{
$message = Mage::helper('cse/data')->generateAvroCseMessage();
// Initialize a cURL session
$ch = curl_init();
try {
@saranyan
saranyan / Data.php
Created March 7, 2012 19:11
Helper code to publish Magento products into Avro binary
<?php
include_once 'avro.php';
class Xcommerce_Cse_Helper_Data extends Mage_Core_Helper_Abstract
{
public function generateAvroCseMessage() {
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');
$cse_product_details = array();
foreach ($collection as $p) {
@saranyan
saranyan / get_message_schema.php
Created March 30, 2012 15:08
HT build a X.commerce capability PingPong
<?php
//get schema for ping
$schema_uri = "https://api.x.com/ocl/message/ping/1.0.0";
$content = file_get_contents($schema_uri);
$schema = AvroSchema::parse($content);
@saranyan
saranyan / process_message.php
Created March 30, 2012 15:52
HT build a X.commerce capability PingPong
<?php
$schema_uri = $headers['X-XC-SCHEMA-URI'];
//deserialize the data
$content = file_get_contents($schema_uri);
$schema = AvroSchema::parse($content);
$datum_reader = new AvroIODatumReader($schema);
$read_io = new AvroStringIO($post_data);
$decoder = new AvroIOBinaryDecoder($read_io);
$message = $datum_reader->read($decoder);