My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
Code license: MIT License
Content license: Creative Commons 3.0 BY
Labels: Kiva
Feeds:
People details
Project owners:
  lifeinafolder

PhpKiva is a simple PHP5 library for accessing data from Kiva API.It presents a simple object oriented interface to query the Kiva API to obtain results in the formats supported by Kiva-.json,.xml and .html

Requirements

Description

Kiva API has been built around 4 primary objects in the Kiva World.PhpKiva extends a Php class for all 4 objects, providing functionalities on all those 4 objects.Here is a list of Kiva Objects and their corresponding PhpKiva classes:

For the query string of all API calls, the phpKiva interface takes an equivalent array of (key,value) pair and constructs a query string from it so that the users of the phpKiva API can work with standard PHP arrays itself.

Loan

Kiva API Call phpKiva equivalent method Parameters
loans/newest getRecentLoans($params) $params(optional): Array of optional parameters : 'page' there is one parameter, a string having it also works
loans/(ids) getLoansInfo($ids) $ids(required) : array of ids((upto 10 supported by Kiva Api)) to fetch info for.
loans/(id)/lenders getLenders($id,$params)

$id(required) : id of the loan for which lender information is required.

$params(optional) : Array of optional parameters : 'page' there is one parameter, a string having it also works

loans/(id)/journal_entries getJournalEntries($id,$params) $id(required) : The identification number for a loan

$params(optional) : Array of optional parameters : 'page','include_bulk'

loans/search searchLoans($params) $params(optional) : Array of optional parameters : 'page','status','gender','sector','region','country_code','partner','q'

To provide a list of 'sector','region' construct an array within the main array at these keys
loans/(id)/updates getStatusUpdates($id) $id(required)

Lender

Kiva API Call phpKiva equivalent method Parameters
lenders/(lender_ids) getLendersInfo($ids) $ids(required) : array of ids((upto 10 supported by Kiva Api)) to fetch info for.
lenders/(lender_id)/loans getLenderLoans($id,$params) $id(required) : The lender ID of a kiva lender

$params(optional) : Array of optional parameters : 'sort_by','page'
lenders/newest getRecentLenders($params) $params(optional) : Array of optional parameters : 'page' there is one parameter, a string having it also works
lenders/search searchLenders($params) $params (optional): Array of optional parameters : 'page','sort_by','occupation','country_code','q'

Partner

Kiva API Call phpKiva equivalent method Parameters
partners getPartners($params) $params(optional) : Array of optional parameters : 'page' there is one parameter, a string having it also works

JournalEntry

Kiva API Call phpKiva equivalent method Parameters
journal_entries/(id)/comments getComments($id,$params)

$id (required): id of the journal entry

$params(optional) : Array of optional parameters : 'page' there is one parameter, a string having it also works

Installation

All the above classes sub-class from a base class implemented in ApiConnector.php. Hence, in order to use a particular php file, the ApiConnector.php would also be required.So here are the step-by-step directions for using the API:

  1. Download ApiConnector.php
  2. Download the corresponding php file for the Kiva object that you plan to use.For instance, if you are building an application dealing only with Lender information, then you only need the class KivaLender in Lender.php and hence, downloading just that file would suffice.However, if you plan to use more than one type of Kiva Object, then you require multiple classes and hence, the corresponding files.
  3. Simple include them in your code using for instance: require 'Loan.php'.
  4. Instantiate the object and set the return format (json,xml,html) in which you want the desired ouput.By defauly, phpKiva returns results from Kiva in XML format.However, that can easily be changed while instantiating the object or by using the setReturnType function

Examples

require 'lender.php';
$lenderObj = new KivaLender();
if($lenderObj->setReturnType("html")){
	$response = $lenderObj->getRecentLenders("page=2");
        echo $response;
}








Hosted by Google Code