Skip to content

Commit

Permalink
Fix formatting and method calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexortizrosado committed Jun 10, 2015
1 parent ce19024 commit 6763b8d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
60 changes: 29 additions & 31 deletions breeze/breeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
breeze_api = breeze.BreezeApi(
breeze_url='https://demo.breezechms.com',
api_key='5c2d2cbacg3...')
people = breeze_api.get_people();
people = breeze_api.GetPeople();
for person in people:
print '%s %s' % (person['first_name'], person['last_name'])
Expand All @@ -21,7 +21,8 @@

from utils import make_enum

ENDPOINTS = make_enum('BreezeApiURL',
ENDPOINTS = make_enum(
'BreezeApiURL',
PEOPLE = '/api/people',
EVENTS = '/api/events',
PROFILE_FIELDS = '/api/profile',
Expand All @@ -36,17 +37,18 @@ class BreezeApi(object):

def __init__(self, breeze_url, api_key, debug=False, dry_run=False,
connection=requests.Session()):
"""Instantiates the BreezeApi with your Breeze account information.
Args:
breeze_url: Fully qualified domain for your organizations Breeze service.
api_key: Unique Breeze API key. For instructions on finding your
organizations API key, see:
http://breezechms.com/docs#extensions_api
debug: Enable debug output.
dry_run: Enable no-op mode, which disables requests from being made. When
combined with debug, this allows debugging requests without
affecting data in your Breeze account."""
"""Instantiates the BreezeApi with your Breeze account information.
Args:
breeze_url: Fully qualified domain for your organizations Breeze service.
api_key: Unique Breeze API key. For instructions on finding your
organizations API key, see:
http://breezechms.com/docs#extensions_api
debug: Enable debug output.
dry_run: Enable no-op mode, which disables requests from being made. When
combined with debug, this allows debugging requests without
affecting data in your Breeze account."""

self.breeze_url = breeze_url
self.api_key = api_key
self.debug = debug
Expand All @@ -59,7 +61,7 @@ def __init__(self, breeze_url, api_key, debug=False, dry_run=False,
self.breeze_url.endswith('.breezechms.com')):
raise BreezeError('You must provide your breeze_url as ',
'subdomain.breezechms.com')

if not self.api_key:
raise BreezeError('You must provide an API key.')

Expand All @@ -80,7 +82,7 @@ def _Request(self, endpoint, params=None, headers=None, timeout=60):
"""
headers = {'Content-Type': 'application/json',
'Api-Key': self.api_key}

if params is None:
params = {}
kw = dict(params=params, headers=headers, timeout=timeout)
Expand All @@ -100,12 +102,12 @@ def _Request(self, endpoint, params=None, headers=None, timeout=60):
if not self._RequestSucceeded(response):
raise BreezeError(response)
return response

def _RequestSucceeded(self, response):
"""Predicate to ensure that the HTTP request succeeded."""
return not (('error' in response) or ('errorCode' in response))


def GetPeople(self, limit=None, offset=None, details=False):
"""List people from your database.
Expand Down Expand Up @@ -137,21 +139,21 @@ def GetPeople(self, limit=None, offset=None, details=False):
params = []
if limit:
params.append('limit=%s' % limit)
if start:
if offset:
params.append('offset=%s' % start)
if details:
params.append('details=1')
return self._Request('%s/?%s' % (ENDPOINTS.PEOPLE, '&'.join(params)))


def GetProfileFields(self):
"""List profile fields from your database.
Returns:
JSON response.
"""
return self._Request(ENDPOINTS.PROFILE_FIELDS)

def GetPersonDetails(self, person_id):
"""Retrieve the details for a specific person by their ID.
Expand All @@ -162,7 +164,7 @@ def GetPersonDetails(self, person_id):
JSON response.
"""
return self._Request('%s/%s' % (ENDPOINTS.PEOPLE, str(person_id)))

def GetEvents(self, start_date=None, end_date=None):
"""Retrieve all events for a given date range.
Args:
Expand All @@ -178,7 +180,7 @@ def GetEvents(self, start_date=None, end_date=None):
if end_date:
params.append('end=%s' % end_date)
return self._Request('%s/?%s' % (ENDPOINTS.EVENTS, '&'.join(params)))

def EventCheckIn(self, person_id, event_instance_id):
"""Checks in a person into an event.
Expand All @@ -191,8 +193,8 @@ def EventCheckIn(self, person_id, event_instance_id):
"""
return self._Request('%s/attendance/add?person_id=%s&instance_id=%s' % (
ENDPOINTS.EVENTS, str(person_id), str(event_instance_id)))


def EventCheckOut(self, person_id, event_instance_id):
"""Remove the attendance for a person checked into an event.
Expand Down Expand Up @@ -232,8 +234,8 @@ def AddContribution(self, date=None, name=None, person_id=None, uid=None,
processor: The name of the processor used to send the payment. Used in
conjunction with uid. Not needed if using Breeze ID.
(ie. SimpleGive, BluePay, Stripe)
method: The payment method. (ie. Check, Cash, Credit/Debit Online,
Credit/Debit Offline, Donated Goods (FMV), Stocks (FMV),
method: The payment method. (ie. Check, Cash, Credit/Debit Online,
Credit/Debit Offline, Donated Goods (FMV), Stocks (FMV),
Direct Deposit)
funds_json: JSON string containing fund names and amounts. This allows
splitting fund giving. The ID is optional. If present, it must
Expand All @@ -258,7 +260,7 @@ def AddContribution(self, date=None, name=None, person_id=None, uid=None,
batch_name: The name of the batch. Can be used with batch number or group.
Returns:
"""
params = []
if date:
Expand Down Expand Up @@ -287,7 +289,3 @@ def AddContribution(self, date=None, name=None, person_id=None, uid=None,
'&'.join(params)))
if not response['success']:
raise BreezeError('Failed to add contribution: ', response['errors'])




38 changes: 21 additions & 17 deletions easytithe_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def fund(self, fund_name):
@property
def amount(self):
return self._contribution['Amount'].lstrip('$').replace(',', '')

@property
def card_type(self):
return self._contribution['Type']

@property
def email_address(self):
return self._contribution['Email']
Expand Down Expand Up @@ -100,44 +100,47 @@ def PareArgs():
return args

def main():
# 6b1c3babdf4eeccad9c7f41a5edcccbf
args = PareArgs()
start_date = args.start_date[0]
end_date = args.end_date[0]

# EasyTithe
# Log into EasyTithe and get all contributions for date range.
username = args.username[0]
password = args.password[0]
print 'Username: %s\nPassword: %s' % (username, password)
print 'Connecting to EasyTithe [%s:%s]' % (username, password)
et = easytithe.EasyTithe(username, password)
contributions = [Contribution(contribution) for contribution in et.GetContributions(start_date, end_date)]

# Breeze
contributions = [
Contribution(contribution) for contribution in et.GetContributions(
start_date, end_date)]

print 'Found %s contributions between %s and %s' % (len(contributions),
start_date,
end_date)

# Log into Breeze using API.
breeze_api_key = args.breeze_api_key[0]
breeze_url = args.breeze_url[0]
breeze_api = breeze.BreezeApi(breeze_url, breeze_api_key, debug=True, dry_run=args.dry_run)
people = breeze_api.get_people();
breeze_api = breeze.BreezeApi(breeze_url, breeze_api_key, debug=True,
dry_run=args.dry_run)
people = breeze_api.GetPeople();
print 'Date range: %s - %s' % (start_date, end_date)
print 'Found %d people in database.' % len(people)

for person in people:
person['full_name'] = '%s %s' % (person['force_first_name'].strip(),
person['last_name'].strip())

for contribution in contributions:
person_match = filter(
lambda person: re.search(person['full_name'],
contribution.full_name,
re.IGNORECASE), people)
if person_match:
# The 2014 Womens Retreat fund contains a non-ascii character.
if 'Retreat' in contribution.fund:
contribution.fund('2014 Womens Retreat')
print 'Adding contribution for [%s] for fund [%s].' % (
print 'Adding contribution for [%s] to fund [%s].' % (
contribution.full_name, contribution.fund)

# Add the contribution on the matching person's Breeze profile.
breeze_api.add_contribution(
breeze_api.AddContribution(
date=contribution.date,
name=contribution.full_name,
person_id=person_match[0]['id'],
Expand All @@ -148,7 +151,8 @@ def main():
group=contribution.date)

if not person_match:
print 'WARNING: Unable to find match for [%s].' % full_name
print 'WARNING: Unable to find a matching person in Breeze for [%s].' % (
full_name)

if __name__ == '__main__':
main()
Empty file added third_party/__init__.py
Empty file.

0 comments on commit 6763b8d

Please sign in to comment.