Global Lender
A Pebble app for finding new and interesting loans on kiva.org
Data Structures | Typedefs | Functions
KivaModel.h File Reference
#include "libs/magpebapp.h"
Include dependency graph for KivaModel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LoanInfo
 
struct  KivaModel_PrefLoan_CIter
 
struct  KivaModel_Modified
 

Typedefs

typedef struct KivaModel KivaModel
 
typedef struct LoanInfo LoanInfo
 
typedef struct KivaModel_PrefLoan_CIter KivaModel_PrefLoan_CIter
 
typedef struct KivaModel_Modified KivaModel_Modified
 

Functions

KivaModelKivaModel_create (const char *)
 
MagPebApp_ErrCode KivaModel_destroy (KivaModel *this)
 
MagPebApp_ErrCode KivaModel_setLenderId (KivaModel *this, const char *)
 
MagPebApp_ErrCode KivaModel_setLenderName (KivaModel *const this, const char *)
 
MagPebApp_ErrCode KivaModel_setLenderLoc (KivaModel *this, const char *)
 
MagPebApp_ErrCode KivaModel_setLenderLoanQty (KivaModel *this, const int)
 
MagPebApp_ErrCode KivaModel_addLenderCountry (KivaModel *this, const char *, const char *)
 
MagPebApp_ErrCode KivaModel_addKivaCountry (KivaModel *this, const char *, const char *)
 
MagPebApp_ErrCode KivaModel_addPreferredLoan (KivaModel *this, const LoanInfo)
 
MagPebApp_ErrCode KivaModel_clearPreferredLoans (KivaModel *this)
 
MagPebApp_ErrCode KivaModel_getMods (const KivaModel *this, KivaModel_Modified *)
 
MagPebApp_ErrCode KivaModel_getLenderId (const KivaModel *this, char **)
 
MagPebApp_ErrCode KivaModel_getLenderName (const KivaModel *this, char **)
 
MagPebApp_ErrCode KivaModel_getLenderLoc (const KivaModel *this, char **)
 
MagPebApp_ErrCode KivaModel_getLenderLoanQty (const KivaModel *this, int *)
 
MagPebApp_ErrCode KivaModel_getLenderCountryQty (const KivaModel *this, int *)
 
MagPebApp_ErrCode KivaModel_getLenderCountryCodes (const KivaModel *this, const bool, char **)
 
MagPebApp_ErrCode KivaModel_getKivaCountryQty (const KivaModel *this, int *)
 
MagPebApp_ErrCode KivaModel_getKivaCountryName (const KivaModel *this, const char *, const char **)
 
MagPebApp_ErrCode KivaModel_getPreferredLoanQty (const KivaModel *this, uint16_t *)
 
KivaModel_PrefLoan_CIterKivaModel_firstPrefLoan (const KivaModel *this)
 
KivaModel_PrefLoan_CIterKivaModel_nextPrefLoan (const KivaModel *this, KivaModel_PrefLoan_CIter *)
 

Typedef Documentation

typedef struct KivaModel KivaModel
typedef struct LoanInfo LoanInfo

Function Documentation

MagPebApp_ErrCode KivaModel_addKivaCountry ( KivaModel this,
const char *  countryId,
const char *  countryName 
)

Adds a new country to the list of Kiva-recognized countries. The countryId and countryName parameters are copied; ownership of those parameters is not transferred by this function. The caller is still responsible for freeing that data.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]countryIdID of the country to add; a two-character ISO-3361 country code
[in]countryNameName of the country to add
MagPebApp_ErrCode KivaModel_addLenderCountry ( KivaModel this,
const char *  countryId,
const char *  countryName 
)

Adds a country ID to the list of countries supported by the lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]countryIdID of the country to add; a two-character ISO-3361 country code. Ownership is not transferred from the caller, so the caller should free this variable. If the countryId is not yet in the list of recognized Kiva countries, then it will be added to the hash.
[in]countryNameName of the country to add. If countryId is already a recognized Kiva country, then the countryName will be ignored. If the countryId is not yet in the list of countries that this KivaModel recognizes, then this will be the new country name for this ID. If NULL, then the countryId will be used as the name. Ownership is not transferred from the caller, so the caller should free this variable.
MagPebApp_ErrCode KivaModel_addPreferredLoan ( KivaModel this,
const LoanInfo  loanInfo 
)

Adds a new loan to the list of preferred loans. Preferred loans are a list of fundraising loans in which the lender has indicated an interest. The heap-allocated members of loanInfo are copied; ownership of those parameters is not transferred by this function. The caller is still responsible for freeing that data.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]loanInfoinformation about the preferred loan
MagPebApp_ErrCode KivaModel_clearPreferredLoans ( KivaModel this)

Clears the list of preferred loans, freeing all heap-allocated members of LoanInfo data. Preferred loans are a list of fundraising loans in which the lender has indicated an interest.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
KivaModel* KivaModel_create ( const char *  lenderId)

Constructor

Parameters
[in]lenderIdPointer to the lender ID C-string. Identifies the lender uniquely on kiva.org. Ownership is not transferred to this function, so the caller is still responsible for freeing this variable.
MagPebApp_ErrCode KivaModel_destroy ( KivaModel this)

Destroys KivaModel and frees allocated memory.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
KivaModel_PrefLoan_CIter* KivaModel_firstPrefLoan ( const KivaModel this)

Used to iterate through the list of preferred loans.

plIter != NULL; plIter = KivaModel_nextPrefLoan(kivaModel, plIter)) {
printf("Loan #%d Name: %s\n", plIter->idx, plIter->data->name);
}
Parameters
[in,out]thisPointer to KivaModel; must be already allocated
Returns
NULL if there are no preferred loans in this KivaModel a valid iterator for the first preferred loan in this KivaModel If a valid iterator, is returned, ownership of the iterator pointer's memory is transferred to the caller, and the caller is responsible for freeing it, in one of the following ways:
MagPebApp_ErrCode KivaModel_getKivaCountryName ( const KivaModel this,
const char *  countryId,
const char **  countryName 
)

Provides a pointer to the country name identified by the specified ID.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]countryIdID of the country to add; a two-character ISO-3361 country code. Ownership of this parameter is not transferred, so the caller is still responsible for freeing this variable.
[out]countryNameIf the country ID is recognized by this KivaModel, this parameter will be replaced with a pointer to the recognized country name. Must be NULL upon entry to this function. If the country ID is not recognized, then this parameter will remain NULL. Caller does not own (should not free) the memory associated with countryName.
Returns
MPA_SUCCESS on success MPA_INVALID_INPUT_ERR if countryName is not NULL on entry
MagPebApp_ErrCode KivaModel_getKivaCountryQty ( const KivaModel this,
int *  kivaCountryQty 
)

Gets the quantity of countries actively served by Kiva.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]kivaCountryQtyPointer to the Kiva country quantity int variable
MagPebApp_ErrCode KivaModel_getLenderCountryCodes ( const KivaModel this,
const bool  support,
char **  countryCodes 
)

Gets a list of country codes relative to the registered lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]supportIf true, returns a list of country codes that registered lender has supported with loans. If false, returns a list of country codes that the registered lender has NOT yet supported with loans.
[out]countryCodesIf countries exist that meet the support criteria relative to the lender in this KivaModel, then this parameter will be replaced with a pointer to a string of comma- separated country codes. Must be NULL upon entry to this function. If there are no countries that meet the criteria, then this parameter will remain NULL. Ownership of this string is transferred to the caller after this function call. Caller owns (and must free) the memory associated with countryCodes (if the string is not NULL).
Returns
MPA_SUCCESS on success MPA_INVALID_INPUT_ERR if countryCodes is not NULL on entry
MagPebApp_ErrCode KivaModel_getLenderCountryQty ( const KivaModel this,
int *  lenderCountryQty 
)

Gets the quantity of countries supported by the registered lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]lenderCountryQtyPointer to the lender country quantity int variable
MagPebApp_ErrCode KivaModel_getLenderId ( const KivaModel this,
char **  lenderId 
)

Gets the currently-stored lender ID.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]lenderIdPointer to the lender ID C-string; must be NULL on entry. Ownership is not transferred to the caller, so the caller should not free this variable.
MagPebApp_ErrCode KivaModel_getLenderLoanQty ( const KivaModel this,
int *  lenderLoanQty 
)

Gets the quantity of loans by the registered lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]lenderQtyPointer to the lender loan quantity int variable
MagPebApp_ErrCode KivaModel_getLenderLoc ( const KivaModel this,
char **  lenderLoc 
)

Gets the currently-stored lender location.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]lenderLocPointer to the lender location C-string; must be NULL on entry. Ownership is not transferred to the caller, so the caller should not free this variable.
MagPebApp_ErrCode KivaModel_getLenderName ( const KivaModel this,
char **  lenderName 
)

Gets the currently-stored lender name.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[out]lenderNamePointer to the lender name C-string; must be NULL on entry. Ownership is not transferred to the caller, so the caller should not free this variable.
MagPebApp_ErrCode KivaModel_getMods ( const KivaModel this,
KivaModel_Modified mods 
)

Indicates which parts of the data model were modified since the last time the data was retrieved from a "getter" member function.

MagPebApp_ErrCode KivaModel_getPreferredLoanQty ( const KivaModel this,
uint16_t *  prefLoanQty 
)

Returns the number of preferred loans stored in this model.

Preferred loans are a list of fundraising loans in which the lender has indicated an interest.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in,out]prefLoanQtyThe quantity of preferred loans stored
Returns
MPA_SUCCESS on success MPA_NULL_POINTER_ERR if this is NULL
KivaModel_PrefLoan_CIter* KivaModel_nextPrefLoan ( const KivaModel this,
KivaModel_PrefLoan_CIter plIter 
)

Used to iterate through the list of preferred loans.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
Returns
NULL if there are no more preferred loans in this KivaModel a valid LoanInfo* for the next preferred loan in this KivaModel
MagPebApp_ErrCode KivaModel_setLenderId ( KivaModel this,
const char *  lenderId 
)

Sets the Lender ID and resets any lender-specific data so that it will be NULL or empty until it is reloaded.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]lenderIdPointer to the lender ID C-string. Identifies the lender uniquely on kiva.org. Ownership is not transferred to this function, so the caller is still responsible for freeing this variable.
MagPebApp_ErrCode KivaModel_setLenderLoanQty ( KivaModel this,
const int   
)
MagPebApp_ErrCode KivaModel_setLenderLoc ( KivaModel this,
const char *  lenderLoc 
)

Sets the lender location for the registered lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]lenderNamePointer to the lender location C-string, as it appears on kiva.org. This is a free format text field. Ownership is not transferred to this function, so the caller is still responsible for freeing this variable.
MagPebApp_ErrCode KivaModel_setLenderName ( KivaModel this,
const char *  lenderName 
)

Sets the lender name for the registered lender.

Parameters
[in,out]thisPointer to KivaModel; must be already allocated
[in]lenderNamePointer to the lender name C-string, as it is written on kiva.org. This may be a first name and last name, but is not limited to that format. Ownership is not transferred to this function, so the caller is still responsible for freeing this variable.