def search(self, filter_id=None, show_all=None): """ Apply filters and search for loans matching the specifications """ url = DNS + ENDPOINTS['loans'].format(version=API_VERSION) criteria = list() if filter_id is not None: criteria.append('filterId={}'.format(filter_id)) if show_all is not None: if show_all: criteria.append('showAll=true') else: criteria.append('showAll=false') if criteria: url += '?' + '&'.join(criteria) headers = {'X-LC-LISTING-VERSION': LISTING_VERSION} response = Response(request.get(url, headers=headers)) if not response.successful: fstr = "cannot search for any loans" raise LCError(fstr, details=json.dumps(response.json, indent=2)) # Reset the stored loans whenever we search again as long as the # latest request was successful self.loans = list() for loan_json in response.json['loans']: loan = Loan(loan_json) self.loans.append(loan)
def pending(investor_id): """ Retrieve the pending transfers :param investor_id: int - the investor account id :returns: iterable of instance of lendingclub2.response.transfer.Transaction """ url = DNS + ENDPOINTS['pending_transfer'].format(version=API_VERSION, investor_id=investor_id) response = Response(request.get(url)) if not response.successful: fstr = "cannot find list of pending transactions" raise LCError(fstr, details=json.dumps(response.json, indent=2)) transactions = list() total_transactions = 0 try: total_transactions = response.json['transfers'] except KeyError: pass for key in range(total_transactions): transactions.append(Transaction(response.json[key])) return transactions
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response)
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response) # Formulate the list of portfolios self._list = list() for portfolio_json in self.json['myPortfolios']: self._list.append( Portfolio(self._investor_id, response=portfolio_json))
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response) self._notes = list() try: self._notes = [ Note(note_json) for note_json in self.json['myNotes'] ] except KeyError: pass
def update(self): """ Update the summary """ self._response = request.get(self.url)