-
Notifications
You must be signed in to change notification settings - Fork 45
feat(letters): adds support for letters endpoint #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import lob | ||
lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. | ||
|
||
# Creating an Address Object | ||
|
||
example_address = lob.Address.create( | ||
name = 'Julia Sanchez', | ||
address_line1 = '104 Printing Boulevard', | ||
address_city = 'Boston', | ||
address_state = 'MA', | ||
address_country = 'US', | ||
address_zip = '12345' | ||
) | ||
print "\n" | ||
print "Address Response" | ||
print "\n" | ||
print "=======================================================" | ||
print "\n" | ||
print example_address | ||
print "\n" | ||
print "=======================================================" | ||
print "\n" | ||
|
||
# Creating a Letter | ||
|
||
example_letter = lob.Letter.create( | ||
name = 'Test Letter', | ||
to_address = { | ||
'name': 'Antoinette Reynolds', | ||
'address_line1': '1859 Kinney St', | ||
'address_city': 'Agawam', | ||
'address_zip': '01001', | ||
'address_state': 'MA' | ||
}, | ||
from_address = example_address, | ||
file = '<html><p>Hello Julia</p></html>' | ||
) | ||
|
||
print "Letter Response" | ||
print "\n" | ||
print "=======================================================" | ||
print "\n" | ||
print example_letter | ||
print "\n" | ||
print "=======================================================" | ||
print "\n" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ def lob_format(resp): | |
'check': Check, | ||
'country': Country, | ||
'job': Job, | ||
'letter' : Letter, | ||
'object': Object, | ||
'postcard': Postcard, | ||
'state': State | ||
|
@@ -170,6 +171,19 @@ def create(cls, **params): | |
params.pop('objects', None) | ||
return super(Job, cls).create(**params) | ||
|
||
class Letter(ListableAPIResource, CreateableAPIResource): | ||
endpoint = '/letters' | ||
@classmethod | ||
def create(cls, **params): | ||
if isinstance(params, dict): | ||
if 'from_address' in params: | ||
params['from'] = params['from_address'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason we call the vars "to_address" and "from_address" and not "to" and "from" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from is a reserved python keyword so it complains if you try to use it as a param name in the create() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. booo reserved words. |
||
params.pop('from_address') | ||
if 'to_address' in params: | ||
params['to'] = params['to_address'] | ||
params.pop('to_address') | ||
return super(Letter, cls).create(**params) | ||
|
||
class Object(ListableAPIResource, DeleteableAPIResource, CreateableAPIResource): | ||
endpoint = '/objects' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import unittest | ||
import lob | ||
# Setting the API key | ||
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc' | ||
|
||
class LetterFunctions(unittest.TestCase): | ||
def setUp(self): | ||
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc' | ||
self.addr = lob.Address.list(count=1).data[0] | ||
|
||
def test_list_letters(self): | ||
letters = lob.Letter.list() | ||
self.assertTrue(isinstance(letters.data[0], lob.Letter)) | ||
self.assertEqual(letters.object, 'list') | ||
|
||
def test_retrieve_letter(self): | ||
letter = lob.Letter.retrieve(id=lob.Letter.list().data[0].id) | ||
self.assertTrue(isinstance(letter, lob.Letter)) | ||
|
||
def test_create_letter(self): | ||
letter = lob.Letter.create( | ||
from_address = { | ||
'name': 'Antoinette Reynolds', | ||
'address_line1': '1859 Kinney St', | ||
'address_city': 'Agawam', | ||
'address_zip': '01001', | ||
'address_state': 'MA' | ||
}, | ||
to_address = self.addr.id, | ||
file = 'https://lob.com/goblue.pdf' | ||
) | ||
self.assertEqual(letter.to_address.id, self.addr.id) | ||
self.assertTrue(isinstance(letter, lob.Letter)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍