I have done quite a bit of work on this Library and will be writing up a blog post on how to use it for people who are not fluent in PHP.
It's come a long way even from yesterday. I started out by using XPath to fetch most of the data but am now in the process of migrating it to use DOMDocument rather than XPath for most of the cases.
The new library will now return an instance of Fuelly_Response which is a container to hold your user object and vehicle object. The vehicle object holds all of the Fuelup objects ready for manipulation.
I have added some features to this that I personally wanted such as totalMilesToday
You can simply grab the vehicle object and write something as simple as:
echo "I have rode my motorcycle ".$vehicle->getTotalMilesToday()." today." and that will either print 0 or however many miles your fuelups for that day accumulate to.
I understand it's not going to be exact because I might start the day with a quarter tank and drive around for 20 miles before fueling up.
I plan to keep this accurate by topping off my tank every morning on my way to work. This will then be able to calculate properly.
You can now also fetch details only for a specific vehicle by passing the vehicle name to the run method. For instance $scraper->run('2WT'); will return only the fuelups and details for the vehicle labeled 2WT.
Here is some sample output from the library
object(Fuelly_Response)#3 (1) {
["_properties"
rotected]=>
array(6) {
["searchByVehicleName"]=>
bool(false)
["searchVehicleFound"]=>
bool(false)
["searchVehicleString"]=>
string(0) ""
["totalVehiclesFound"]=>
int(1)
["user"]=>
object(Fuelly_User)#1 (1) {
["_properties"
rotected]=>
array(4) {
["email"]=>
string(19) "test@mailinator.com"
["password"]=>
string(4) "test"
["displayName"]=>
string(6) "test27"
["isLoggedIn"]=>
bool(true)
}
}
["vehicles"]=>
array(1) {
["2WT"]=>
object(Fuelly_Vehicle)#11 (1) {
["_properties"
rotected]=>
array(15) {
["id"]=>
string(5) "93749"
["name"]=>
string(3) "2WT"
["displayName"]=>
string(3) "2WT"
["avgMilesPerGallon"]=>
string(4) "47.5"
["lastMilesPerGallon"]=>
string(4) "64.5"
["bestMilesPerGallon"]=>
string(4) "64.5"
["avgPricePerGallon"]=>
string(5) "$3.92"
["avgPricePerFuelUp"]=>
string(6) "$12.14"
["avgPricePerMile"]=>
string(6) "$0.082"
["totalFuelups"]=>
int(5)
["totalSpent"]=>
string(6) "$60.71"
["totalMilesTracked"]=>
string(3) "589"
["totalMilesToday"]=>
int(0)
["hasFirstFuelupOfTheDayBeenCompleted"]=>
bool(false)
["fuelups"]=>
array(5) {
[0]=>
object(Fuelly_Fuelup)#19 (1) {
["_properties"
rotected]=>
array(9) {
["timestamp"]=>
int(1318365120)
["odometer"]=>
string(3) "590"
["miles"]=>
int(200)
["gallons"]=>
string(3) "3.1"
["milesPerGallon"]=>
float(64.5)
["pricePerGallon"]=>
string(6) "$3.899"
["note"]=>
string(16) "Cumberland Farms"
["addedBy"]=>
string(6) "test27"
["total"]=>
string(6) "$12.09"
}
}
[1]=>
object(Fuelly_Fuelup)#18 (1) {
["_properties"
rotected]=>
array(9) {
["timestamp"]=>
int(1317663120)
["odometer"]=>
string(3) "390"
["miles"]=>
int(109)
["gallons"]=>
string(3) "3.1"
["milesPerGallon"]=>
float(35.2)
["pricePerGallon"]=>
string(6) "$3.999"
["note"]=>
string(5) "Mobil"
["addedBy"]=>
string(6) "test27"
["total"]=>
string(6) "$12.40"
}
}
[2]=>
object(Fuelly_Fuelup)#22 (1) {
["_properties"
rotected]=>
array(9) {
["timestamp"]=>
int(1317576660)
["odometer"]=>
string(3) "281"
["miles"]=>
int(140)
["gallons"]=>
string(3) "3.1"
["milesPerGallon"]=>
float(45.2)
["pricePerGallon"]=>
string(6) "$3.799"
["note"]=>
string(0) ""
["addedBy"]=>
string(6) "test27"
["total"]=>
string(6) "$11.78"
}
}
[3]=>
object(Fuelly_Fuelup)#23 (1) {
["_properties"
rotected]=>
array(9) {
["timestamp"]=>
int(1317490200)
["odometer"]=>
string(3) "141"
["miles"]=>
int(140)
["gallons"]=>
string(3) "3.1"
["milesPerGallon"]=>
float(45.2)
["pricePerGallon"]=>
string(6) "$3.899"
["note"]=>
string(0) ""
["addedBy"]=>
string(6) "test27"
["total"]=>
string(6) "$12.09"
}
}
[4]=>
object(Fuelly_Fuelup)#24 (1) {
["_properties"
rotected]=>
array(9) {
["timestamp"]=>
int(1317490140)
["odometer"]=>
string(1) "1"
["miles"]=>
int(0)
["gallons"]=>
string(3) "3.1"
["milesPerGallon"]=>
float(0)
["pricePerGallon"]=>
string(6) "$3.989"
["note"]=>
string(0) ""
["addedBy"]=>
string(6) "test27"
["total"]=>
string(6) "$12.37"
}
}
}
}
}
}
}
}
You can download the new one at
http://www.josephcrawford.com/wp-con...-0.2-alpha.zip
Please let me know your thoughts and what features you think you might want to see in this codebase.
I plan to write up a tutorial about this library to give users an insight into how to use it. and will post here when that's done.
__________________