webdev

How To Deal With High Gear Media API Using PHP And XPath

For the serious players in the automotive industry on the net there is a new way to improve their sites. We had this feed for a while, but now with the new improvements and after big players (e.g. yahoo autos) have been happy with it, we wanted to share it with others around the world.
For developers that are not used to work with XML, XPath and other goodies, here is a short sample of code that will show you how easy it is to fetch our full feed. Unlike the previous post about our regular RSS feed, I’ve used here some basic functionality that anyone that used php (5.2+) will have under their belt.

<?php
/**
* @author Ido Green
*
* @since 04/10/2010
*
* @abstract Simple example how to fetch High Gear Media Full API using xPath
*
* @see greenido.wordpress.com
*
* @copyright HighGearMedia INC. 2010
*
*/error_reporting(E_ALL); // Always good to have it in development mode
$feed = new DOMDocument();
$feed->load('http://www.thecarconnection.com/api?uid=YourApiUserKey&cat=bottom-line');
if (isset($feed->documentElement)) {
$xpath = new DOMXPath($feed);
// Lets register TheCarConnection namespace
$xpath->registerNamespace('tcc', 'http://www.thecarconnection.com/rss');
// Now we looping on all the items and for each one we are extracting some data
foreach ($xpath->evaluate('//item') as $entryNode) {
// Simple way to get the title,desc per item
echo "Title: " . $xpath->evaluate('string(title)', $entryNode), "\n";
echo "Description " . $xpath->evaluate('string(description)', $entryNode), "\n";
// and some more interesting capabilities of xPath - we fetching the spec that is under tcc namespace for car details
echo "Make: " . $xpath->evaluate('string(tcc:review[1]/tcc:cardetails[1]/tcc:make[1])', $entryNode), "\n";
echo "Model: " . $xpath->evaluate('string(tcc:review[1]/tcc:cardetails[1]/tcc:make[1])', $entryNode), "\n";
echo "Rating: " . $xpath->evaluate('string(tcc:review[1]/tcc:cardetails[1]/tcc:rating[1])', $entryNode), " Out of 10\n";
echo "============\n";
}
} else {
echo 'Error: Could not fetch the feed';
}

 

You can also clone this code from github using: git clone git://gist.github.com/865542.git gist-865542

So it’s easy, right? You can load these feed for each site from our network.
For example: http://www.motorauthority.com/api?uid=YourUserKey&cat=reviews
Will give you all the reviews from Motor Authority.
For more specific custom calls you may use these parameters:

  • uid – your user ID
  • cat – you can choose: reviews / bottom-line / tips / blogs
    If you wish to get just the summaries of the bottom-line use: bottomline-summary
  • media – Use 0 for strip html and media=1 to have our HTML format in the call.
  • from/to – Use unix time stamp (e.g. 1206514800 and yes… the ‘from’ need to be lower then the ‘to‘)
  • limit – Up to 100 items. The default is 10.
  • limited-links – When it’s equal 1 we will give you just 5 links per item.
  • version – You will only need it if you wish to get reviews for cars that are older then 2008. Then use: version=0
  • morelinks – Use 1 if you wish to get links from thecarconnection.com or 0 if you don’t want links.

(*) Note that the bold parameters are mandatory.

If you wish to have quality automotive content on your site please feel free to approach High Gear Media
(feedback at HighGearMedia.com) and get a user ID. With more then 1000 new items of content per month, there are something for every car lover girl.

Standard
webdev

How To Work With High Gear Media RSS Feed In (less then) 4 Minutes


For all the girls that asked me time after time ‘How/Who/When/Why?’ and for all the ones that want to have on their blog the best automotive content around the web… This short code example will harness you with a knowledge to fetch High Gear Media customizable feed and have it on your site. The first thing you need to do in order to save yourself some leg work is to install Zend Framework.

Why reinvent the wheel, right?

The good people that work with Zend build for us some nice components that save us lots of work. For example, to parse an Atom (or RSS) feed – you should use their class and in few lines of code, you can be productive and happy.

After the installation, you can copy & paste the code below and you good to go.

<?php
/**
* @author Ido Green
*
* @since 04/01/2010
*
* @abstract Simple example how to fetch High Gear Media API (XML feed).
* You should have Zend Framework (1.9.4 and above).
*
* @see greenido.wordpress.com
*
* @copyright HighGearMedia INC. 2010
*
*/
// Set error reporting to ALL - Always good when you developing new features
error_reporting(E_ALL);
// Lets make sure we can find Zend Framework lib. (You might want to change it base on your local
// environment.
set_include_path(get_include_path() . PATH_SEPARATOR . "../");
// get the feed library
require_once 'Zend/Feed.php';
try {
$rss = Zend_Feed::import('http://feeds.highgearmedia.com/?sites=thecarconnection,greencarreports,allaboutprius');
} catch (Exception $e) {
echo $e->getMessage(); // In case something didn't work - lets see it.
exit (-1);
}
$feedItems = array();
// Loop through the items in the feed
foreach ($rss as $item) {
$itemElements = array(
'title' => $item->title(),
'description' => $item-<description(),
'link' => $item->link(),
'pubDate' => $item->pubDate(),
'author' => $item->author()
);
array_push($feedItems, $itemElements);
}
echo "\nThe HGM feed we got:\n";
// dump all items
var_dump($feedItems);
// In case some other process want to check if we finished correctly.
exit(0);
?>

The feeds can be fully customize according to your interested topics. For example:

Please feel free to share you experience using the comments.

Standard
life, Sport

The Top 10 Air Time Around The World

Did I told you I love red-bull?

They are a great company that invest in crazy/cool people.

Standard
life

Long conversation with DHH

It’s (too) long conversation in ‘This week in Startup’ but you might want to browse it.
Lots of good stuff and it’s funny to see how David is refusing to the virtual offers Mr. C. is throwing in his direction.

Enjoy.

Standard
life

Marathon (short) Tutorial

Here is (yet another) lighting talk I gave at the Java Posse Roundup 2010

It’s a short presentation that give you the basic idea what is all about this trend of running 42.195 Km (or 26.2 miles if you want to count less).

Planning – there are lots of good resources out on the web. Here is one that I’ve used – It’s A Guru trainer site. You can pick the right plan base on your current shape. Another good online tool is this pace calculator. But like anything in life, it’s all about execution! You must follow the plan and do your best to stick with the runs.
The hard part and the most important part of any plan is the ‘long runs’. These runs build you body and make sure it will be able to do the distance and be active for 3 to 5 hours.

Be Strong and (try to) have fun.

Standard
Business, life, webdev

Java Posse Roundup 2010 – Suggested Books

books
With so many great recommendations…
I felt it was right to share it with the world. Here are some of the books that people in the Java Posse Roundup 2010 recommended you to read (quickly).

Agile Books

Testing Books

Complex Event Processing


Version Control

Scala

JavaScript

Career Books

Business

Software Projects and Their Teams, Groups, Processes and People

Release It! writing and maintaining software from an operations perspective

On Intelligence by Jeff Hawkins – How a new understanding of the brain will lead to the creation of truly intelligent machines

Standard
Business

The Web Is Shifting

Here is another lighting talk I’ve planed to this year Java Posse Roundup. Unfortunately, I didn’t have time to give it. So in order to share it with some girls that might find it interesting – Here you go:

The web is becoming more sociable than searchable, research firm Hitwise said that the two sites accounted for 14 per cent of all US internet visits last week. Facebook’s home page recorded 7.07 per cent of traffic and Google’s 7.03 per cent. You may  read more about the fact that Facebook got more unique users in the USA then Google all last week… so it’s clearly the direction that the web is moving. I only wonder, what are people doing all this time on Facebook.

Facebook is like a Starbucks (You know… friends don’t let they friend drink there) where everyone hangs out for hours but almost never buys anything. The revenue gap between sites like Facebook and Google should narrow over time.  Cost-per-click search ads are extremely good at harvesting intent, but bad at generating intent.

Standard
Business

Startup Best Practices

Here is the presentation I’ve used in my lighting talk at the Java Posse roundup 2010

There are just few ‘lessons’ here. IMHO, the important ones.
Over the past 15 years, I’ve been in start ups and swat teams in side big companies. There are lots of good things that I’ve learn, but also, lots of bold examples to how not to run things. In the end of the day, it’s all about peopleware and open commutation. But like any other aspect in life, lots of other methods you can use in order to be better and excel.

Disclaimer: In some of the slides I took some ideas from Rework book.

Standard
life, Sport

Why you should run on regular bases?

Here are few points that I’ve took from the article in the WSJ:

* People who exercise regularly heal from colds 20-30% faster.
* People who walked briskly for 45 minutes, 5 days a week for 12-15 weeks reduced their number of sick days by 25-50%.
* 36% of US adults didn’t engage in ANY leisure activities in 2008. Can this be true?
*  Exercise can lower the risk of stroke by 27%, diabetes by 50%, high-blood pressure by 40%, risk of recurring breast cancer by 50%, colon cancer by 60%, Alzheimer’s disease by 40%.
* Physical activity reduces erosion of telomeres, which essentially is an anti-aging effect at the cellular level.

So next time you thinking on doing some sport activity – follow Nike rule “Just do it!”.

Standard
Business, life

Good Books I’m reading now

It’s mainly a post to my presents (not that they are going to read it).
Hey, after all these years that you thought me the love of books. Here is a short list of what I’m reading when I don’t have time (usually around midnight). In this list I’ve included some recent books I’ve read:

  • What the Dog Saw: And Other Adventures. After Outliers, Blink and Tipping Point anything that Mr. Gladwell will write – I promise to read (as quickly as I can).
  • The Black Swan: The Impact of the Highly Improbable – it’s very good book on a simple topic. We know NOTHING on the stock market.
    “Assuming more order than exists in chaotic nature” – Our brains are wired for narrative, not statistical uncertainty. And so we tell ourselves simple stories to explain complex thing we don’t–and, most importantly, can’t–know. The truth is that we have no idea why stock markets go up or down on any given day, and whatever reason we give is sure to be grossly simplified, if not flat out wrong.
  • Predictably Irrational: The Hidden Forces That Shape Our Decisions
    In a similar way to the Black Swan – it contain lots of answers on how can we recover from an economic crisis.
  • The Intelligent Investor: It is the best book I’ve read about investing. The greatest investment advisor of the twentieth century, Benjamin Graham taught and inspired people worldwide. Graham’s philosophy of “value investing” — which shields investors from substantial error and teaches them to develop long-term strategies — has made The Intelligent Investor the stock market bible ever since its original publication in 1949.
Standard