From a6804714394b913d5ff5e3347cf6502b39184583 Mon Sep 17 00:00:00 2001 From: Bo Laurent Date: Tue, 9 May 2017 16:44:10 -0700 Subject: [PATCH] packaged for pipit --- LICENSE.txt | 8 ++++ MANIFEST | 5 +++ README.md | 2 +- config.py | 12 ------ setup.cfg | 2 + setup.py | 15 +++++++ zoql.py | 50 ----------------------- zuora_restful_python/__init__.py | 0 zuora.py => zuora_restful_python/zuora.py | 24 ++++++----- 9 files changed, 44 insertions(+), 74 deletions(-) create mode 100644 LICENSE.txt create mode 100644 MANIFEST delete mode 100644 config.py create mode 100644 setup.cfg create mode 100644 setup.py delete mode 100644 zoql.py create mode 100644 zuora_restful_python/__init__.py rename zuora.py => zuora_restful_python/zuora.py (97%) diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b9475dd --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,8 @@ +Copyright 2017 Bo Laurent + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..885478e --- /dev/null +++ b/MANIFEST @@ -0,0 +1,5 @@ +# file GENERATED by distutils, do NOT edit +setup.cfg +setup.py +zuora_restful_python/__init__.py +zuora_restful_python/zuora.py diff --git a/README.md b/README.md index e45ee2a..1e183f7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# zuora-restful-python +# zuora_restful_python A python class for accessing the Zuora API via REST ## References diff --git a/config.py b/config.py deleted file mode 100644 index 40e1f99..0000000 --- a/config.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -import json - -# -# Zuora REST configuration -# - -ZUORA_CONFIGFILE = os.path.expanduser('~') + '/.zuora-sandbox-config.json' -ZUORA_REST_ENDPOINT = 'https://rest.apisandbox.zuora.com/v1' -with open(ZUORA_CONFIGFILE, 'r') as f: - zuoraConfig = json.load(f) -zuoraConfig['endpoint'] = ZUORA_REST_ENDPOINT diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b88034e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..bd535ae --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +from distutils.core import setup +setup( + name = 'zuora_restful_python', + packages = ['zuora_restful_python'], # this must be the same as the name above + version = '0.1', + description = 'zuora REST API wrapper', + author = 'Bo Laurent', + author_email = 'bo@bolaurent.com', + url = 'https://github.com/bolaurent/zuora_restful_python', # use the URL to the github repo + download_url = 'https://github.com/peterldowns/mypackage/archive/0.1.tar.gz', # I'll explain this in a second + keywords = ['zuora', 'rest', 'api'], + classifiers = [ + 'Programming Language :: Python :: 3' + ], +) diff --git a/zoql.py b/zoql.py deleted file mode 100644 index 067137a..0000000 --- a/zoql.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/local/bin/python3 - -import sys -import cmd -import csv - -import pdb - -import config -from zuora import Zuora - -zuora = Zuora(config.zuoraConfig) - - -def zuoraObjectKeys(zouraObject): - if zouraObject: - return zouraObject.keys() - -def dumpRecords(records): - if records: - firstRecord = records[0] - keys = [key for key in zuoraObjectKeys(firstRecord) if firstRecord[key]] - - print(','.join(keys)) - - for record in records: - print(','.join(str(record[key]) for key in keys)) - - print(len(records), 'records') - -class Interpeter(cmd.Cmd): - def do_select(self, line): - try: - if '.' in line: - csvData = zuora.queryExport('select ' + line).split('\n') - records = [record for record in csv.DictReader(csvData)] - else: - records = zuora.queryAll('select ' + line) - dumpRecords(records) - except Exception as e: - print('Error: q', repr(e)) - - def do_q(self, line): - return self.do_EOF(line) - - def do_EOF(self, line): - return True - -if __name__ == '__main__': - Interpeter().cmdloop() diff --git a/zuora_restful_python/__init__.py b/zuora_restful_python/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zuora.py b/zuora_restful_python/zuora.py similarity index 97% rename from zuora.py rename to zuora_restful_python/zuora.py index fd0ecb6..21c98e5 100644 --- a/zuora.py +++ b/zuora_restful_python/zuora.py @@ -2,12 +2,23 @@ import json import time import datetime -import pdb ZUORA_CHUNKSIZE = 50 + + + class Zuora(object): + """ + config should be a dict as follows: + { + "user": "username", + "password": "password", + "endpoint": "https://rest.apisandbox.zuora.com/v1", + } + """ + def __init__(self, config): self.config = config self.auth = (config['user'], config['password']) @@ -239,13 +250,6 @@ def updateAccountingPeriod(self, accountingPeriodId, payload): response = self._put('/accounting-periods/' + accountingPeriodId, payload) assert response['success'], response - # not tested - # def getCustomExchangeRates(self, currency, startDate, endDate): - # payload = {'startDate': startDate, 'endDate': endDate} - # response = self._get('/custom-exchange-rates/' + currency, payload=payload) - # pdb.set_trace() - # pass - def createInvoiceItemAdjustment(self, type, amount, sourceType, sourceId, adjustmentDate, invoiceNumber=None, invoiceId=None): payload = { 'Type': type, @@ -261,9 +265,7 @@ def createInvoiceItemAdjustment(self, type, amount, sourceType, sourceId, adjust payload['InvoiceNumber'] = invoiceNumber response = self._post('/object/invoice-item-adjustment/', payload) - if not response['Success']: - pdb.set_trace() - # assert response['Success'], response + assert response['Success'], response return response def updateInvoiceItemAdjustment(self, id, reasonCode=None, status=None, transferredToAccounting=None):