YahooFinanceAPI is an open source php library for interacting with the Yahoo Finance Stock API. For those of you unfamiliar with Yahoo’s Stock API please review my previous post Yahoo Finance Stock API. This library contains an easy interface for obtaining information on one or more stocks. For a quick demo of the library feel free to go to http://mdbitz.com/testing/PHPYahooFinance/finance.php?symbol=DELL which will return JSON coded response of some of the basic information that can be obtained via the library. Also feel free to swap out the symbol in the url with any of your choice, if it is an invalid symbol you will simply not get any information.

Updates in Release 1.0

  • isSuccess method added to YahooFinance_Result object to check if request was successful.
  • Bug fixes for typo errors in YahooFinance_Options
  • toXML method added to YahooFinance_Result and YahooFinance_Quote
  • STRICT and LOOSE mode added to YahooFinanceAPI to throw or supress exceptions

Online Documentation

The YahooFinanceAPI PHP Library is fully documented using phpDocumentor. The online documentation contains a full code example as well as class and method descriiptions and parameters.

How do I use the YahooFinanceAPI library?

The YahooFinanceAPI was constructed so that users need to simply follow a basic 6 set process to get any stock information they are looking for.

Step 1: Obtain the main YahooFinanceAPI class

require_once(dirname(__FILE__) . '/YahooFinanceAPI.php');

Step 2: Register the autoloader

spl_autoload_register(array('YahooFinanceAPI', 'autoload'));

Step 3: Identify the information to be returned

Now that the library is properly configured in your script lets define the information that is to be returned for each of the symbols or stocks being looked up. This is done by using the addOption function of the YahooFinanceAPI instance. For a complete list of options please view the YahooFinance_Options class.

$api = new YahooFinanceAPI();
 
// set options
$api->addOption("symbol");
$api->addOption("previousClose");
$api->addOption("open");
$api->addOption("lastTrade");
$api->addOption("lastTradeTime");
$api->addOption("change" );
$api->addOption("daysLow" );
$api->addOption("daysHigh" );
$api->addOption("volume" );

Step 4: Identity the symbols (stocks) to obtain the information for

After defining the information to be returned we define they symbols (stocks) to be returned. This is done by the addSymbol function. To find symbols you can search Yahoo Finance for the company you are interested in.

$api->addSymbol("DELL" );

Step 5: Query for the Information

$result = $api->getQuotes();

Step 6: Use the Stock Information

if( $result->isSuccess() ) {
    $quotes = $result->data;
    foreach( $quotes as $quote ) {
        $symbol = $quote->symbol;
        $lastTrade = $quote->lastTrade;
    }
}

Download the YahooFinanceAPI Library

The YahooFinanceAPI is copyright MDBitz – Matthew John Denton under the GNU Public License. The current release is available for download at http://mdbitz.com/downloads/YahooFinanceAPI-1.0.zip. The archive contains the php classes as well as a test.php file that demonstrates how to use the library.

Feedback Appreciated

Please leave your comments, suggestions, and/or questions below. And if you need any additional support please feel free to send me an email at info@mdbitz.com.

, , , , ,

New Version Released!! Get it here.

Version 0.3 is available. I’ve been making enhancements since the initial release of the PHP Wrapper Library for the Harvest API. This 0.3 version of the wrapper library contains full implementation of the Extended REST API minus the receipt images. In addition there are 2 new utility classes that contain constants for the currency and timezone values that Harvest Supports. I have also updated the files to be phpDocumentor compliant with inline example code usage available at http://mdbitz.com/docs/harvest/.  For those that want a quick introduction to the library please visit the 0.2 release post that shows some usage examples.

Contact

This version remains largely untested as I currently make use of only the Projects, Clients, Contacts, and Expenses portion of the API. If you encounter any bugs, or issues with the library please contact me with the details. I hope that you will find this library useful and if you do feel free to leave a comment.

Download

Resources

, ,

New Version released ! Get it Here.

I’ve been making enhancements since the initial release of the PHP Wrapper Library for the Harvest API, that I first released a week ago in my entry PHP Wrapper Library for the Harvest API. This 0.2 version of the wrapper library contains bug fixes for some issues that Jesse Mortenson of Supermega Design found, as well as implementation of the full API for Projects, Clients, and Client Contacts. Create and Delete functionality has been included for all other Harvest Objects but is currently untested.

Example Setup

  1. Require the HarvestAPI main class
    require_once( dirname(__FILE__) . '/HarvestAPI.php' );
  2. Register the Auto Loader
    spl_autoload_register(array('HarvestAPI', 'autoload') );
  3. Set Account & User information
    $api = new HarvestAPI();
    $api->setUser( "user@email.com" );
    $api->setPassword( "password" );
    $api->setAccount( "account" );

Example: Create a new Client

  1. Initialize and populate your Client Object
    $client = new Harvest_Client();
    $client->set( "name", "New Client" );
    $client->set( "details", "Our new Client" );
  2. Call create method
    $result = $api->createClient( $client );
  3. Check if request was successfull
    if( $result->isSuccess() ) {
      ...
    }
  4. If successful you will be returned the new Client’s Harvest ID
    $client_id = $result->data;

Example: Toggle a Projects active state

  1. Call toggle method with the Project’s Harvest ID
    $result = $api->toggleProject( $project_id );
  2. Check if request was successfull
    if( $result->isSuccess() ) {
      ...
    }

Contact

If you encounter bugs, or issues with the library please contact me with the details. I hope that you will find this useful and if you do feel free to leave a comment.

Download

Resources

, , ,

UPDATE: Current Release details and download available here

Harvest Users may or may not be familiar with the Harvest API that can be used to access and manipulate timesheets, clients, projects, tasks, and more. Since Harvests creation they have been integrating with other 3rd party applications and to communicate information across channels they created the Harvest API.

Harvest users can use this same API to utilize information in their Harvest account in their own applications.  Currently their is an open-sourced Harvest Ruby wrapper that can be from github. But as I prefer to utilize PHP I have created a PHP Wrapper Library for the Harvest API.  Currently the API requires cURL support and can be utilized to obtain information from your harvest account but not modification of data. Over the next few months I will be expanding this to include the rest of the functionality of the API.

Example Usage

  1. Require the HarvestAPI main class
    require_once( dirname(__FILE__) . '/HarvestAPI.php' );
  2. Register the Auto Loader
    spl_autoload_register(array('HarvestAPI', 'autoload') );
  3. Set Account & User information
    $api = new HarvestAPI();
    $api->setUser( "user@email.com" );
    $api->setPassword( "password" );
    $api->setAccount( "account" );
  4. Query the API for desired information
    $result = $api->getClient( 1-----  );
    $result = $api->getProjects();
  5. Check if request was successfull
    if( $result->isSuccess() ) {
      ...
    }
  6. If successful use the information
    $project = $result->data;
    echo "Name: " . $project->name;
    echo "Id: " . $project->id;
    echo "Active: " . $project->active;

Contact

Currently the library is in its first phase so you may encounter some bugs, or issues If you do so please contact me with the details. Also if you find that you need a particular feature of the Harvest API that is currently not supported please also let me know so I can know where to focus my development efforts. I hope that you will find this useful and if you do feel free to leave a comment.

Download

Resources

, , ,

YahooFinanceAPI is an open source php library for interacting with the Yahoo Finance Stock API. For those of you unfamiliar with Yahoo’s Stock API please review my previous post Yahoo Finance Stock API. This library contains an easy interface for obtaining information on one or more stocks. For a quick demo of the library feel free to go to http://mdbitz.com/testing/PHPYahooFinance/finance.php?symbol=DELL which will return JSON coded response of some of the basic information that can be obtained via the library. Also feel free to swap out the symbol in the url with any of your choice, if it is an invalid symbol you will simply not get any information.

How do I use the YahooFinanceAPI library?

The YahooFinanceAPI was constructed so that users need to simply follow a basic 6 set process to get any stock information they are looking for.

Step 1: Obtain the main YahooFinanceAPI class

Before you are able to utilize the YahooFinanceApi library you will need to require or include it into your php script.

require_once(dirname(__FILE__) . '/YahooFinanceAPI.php');

Step 2: Register the autoloader

To mitigate changes in potential future versions this library utilizes an autoloader to load its classes when and if needed. To properly function you will need to register its autoloader by the following command.

spl_autoload_register(array('YahooFinanceAPI', 'autoload'));<pre></p>
<p style="padding-left: 30px;"><strong>Step 3</strong>: Identify the information to be returned</p>
<p style="padding-left: 60px;">Now that the library is properly configured in your script lets define the information that is to be returned for each of the symbols or stocks being looked up. This is done by using the <em>addOption</em> function of the YahooFinanceAPI instance. For a complete list of options please view the YahooFinance_Options class.
<pre lang="php" escaped="true">$api = new YahooFinanceAPI();
// set options
$api-&gt;addOption("symbol");
$api-&gt;addOption("previousClose");
$api-&gt;addOption("open");
$api-&gt;addOption("lastTrade");
$api-&gt;addOption("lastTradeTime");
$api-&gt;addOption("change" );
$api-&gt;addOption("daysLow" );
$api-&gt;addOption("daysHigh" );
$api-&gt;addOption("volume" );

Step 4: Identity the symbols (stocks) to obtain the information for

After defining the information to be returned we define they symbols (stocks) to be returned. This is done by the addSymbol function. To find symbols you can search Yahoo Finance for the company you are interested in.

$api->addSymbol("DELL" );

Step 5: Query for the Information

At this point we have configured the library and defined the stocks and information that we are looking for and are ready to perform our query of the Yahoo Finance Stock API.

$result = $api->getQuotes();

Step 6: Use the Stock Information

The result object returned contains a code property to tell you if the query was successfull 2XX or failed 4XX. In addition the data property contains an array of the requested information for each of the symbols.

$results->code //-- returns the http response code
$results->data //-- array of Quote Objects
$results->data[0] ->symbol //-- returns the symbol name of the first Quote Object

Download the YahooFinanceAPI Library

The YahooFinanceAPI is copyright MDBitz – Matthew John Denton under the GNU Public License. The current release is available for download at http://mdbitz.com/downloads/YahooFinanceAPI.zip. The archive contains the php classes as well as a test.php file that demonstrates how to use the library.

Feedback Appreciated

Please leave your comments, suggestions, and/or questions below. And if you need any additional support please feel free to send me an email at info@mdbitz.com.

, , , , ,