Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,59 @@ This will output:
"message": "Default address: The address you entered was found but more information is needed (such as an apartment, suite, or box number) to match to a specific address."
}
```

## Routes

```python
#Retrieve routes for given zip codes
lob.Route.list(zip_codes=[94158,60031])
```

## Areas

```python
#List areas
lob.Area.list()

#List Areas with Count and Offset
lob.Area.list(count=5, offset=2)

# You can query an area with its `ID`
lob.Area.retrieve(id=<id>)

#or another way
lob.Area.retrieve(<id>)

#Basic Area Create with Zip Codes
lob.Area.create(
name='Lob',
front = 'https://www.lob.com/areafront.pdf',
back = 'https://www.lob.com/areaback.pdf',
routes = ['94158','60031'],
target_type = 'all',
full_bleed = '1'
)

#Basic Area Create with Routes Object
var routes = lob.Route.list(zip_codes=[94158,60031])
lob.Area.create(
name='Lob',
front = 'https://www.lob.com/areafront.pdf',
back = 'https://www.lob.com/areaback.pdf',
routes = routes,
target_type = 'all',
full_bleed = '1'
)


#Create Area with Optional Parameters
lob.Area.create(
front = 'https://www.lob.com/areafront.pdf',
back = 'https://www.lob.com/areaback.pdf',
routes = '94158',
)
```

## Settings

```python
Expand Down Expand Up @@ -372,10 +425,10 @@ lob.Postcard.create(
lob.BankAccount.list()

# Can specify count and offset as well
lob.BankAccount.list(count=5, offset=1)
lob.BankAccount.list(count=5, offset=1)

#Retrieve a specific BankAccount by id
lob.BankAccount.retrieve(<id>)
lob.BankAccount.retrieve(<id>)

#Create Bank Account Using Address Ids
lob.BankAccount.create(
Expand Down Expand Up @@ -409,7 +462,7 @@ lob.BankAccount.create(
)

#Delete a specific BankAccount by id
lob.BankAccount.delete(<id>)
lob.BankAccount.delete(<id>)
```

## Checks
Expand All @@ -419,12 +472,12 @@ lob.BankAccount.delete(<id>)
lob.Check.list()

# Can specify count and offset as well
lob.Check.list(count=5, offset=1)
lob.Check.list(count=5, offset=1)

#Retrieve a specific Check by id
lob.Check.retrieve(<id>)

#Create Check with Address Id
#Create Check with Address Id
lob.Check.create(
name = 'Check Test',
to_address = <address_id>,
Expand Down
4 changes: 2 additions & 2 deletions lob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
api_base = 'https://api.lob.com/v1'

#Resources
from lob.resource import (Address, BankAccount, Check, Country, Job,
Object, Packaging, Postcard, Service, Setting, State, Verification)
from lob.resource import (Address, Area, BankAccount, Check, Country, Job,
Object, Packaging, Postcard, Route, Service, Setting, State, Verification)

from lob.version import VERSION
17 changes: 17 additions & 0 deletions lob/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def lob_format(resp):
types = {
'address': Address,
'area': Area,
'bank_account': BankAccount,
'check': Check,
'job': Job,
Expand Down Expand Up @@ -111,6 +112,19 @@ def create(cls, **params):
class Address(ListableAPIResource, DeleteableAPIResource, CreateableAPIResource):
url = '/addresses'

class Area(ListableAPIResource, CreateableAPIResource):
url = '/areas'
@classmethod
def create(cls, **params):
if isinstance(params, dict):
if 'routes' in params:
if isinstance(params['routes'], LobObject):
routes = []
for r in params['routes'].data[0]['routes']:
routes.append(params['routes'].data[0]['zip_code'] + '-' + r["route"])
params['routes'] = routes
return super(Area, cls).create(**params)

class BankAccount(ListableAPIResource, DeleteableAPIResource, CreateableAPIResource):
url = '/bank_accounts'

Expand Down Expand Up @@ -167,6 +181,9 @@ def create(cls, **params):
class Packaging(ListableAPIResource):
url='/packagings'

class Route(ListableAPIResource):
url='/routes'

class Service(ListableAPIResource):
url = '/services'

Expand Down
Binary file added tests/areaback.pdf
Binary file not shown.
Binary file added tests/areafront.pdf
Binary file not shown.
67 changes: 67 additions & 0 deletions tests/test_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import unittest
import lob
# Setting the API key
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc'

class AreaFunctions(unittest.TestCase):
def setUp(self):
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc'
self.route = lob.Route.list(zip_codes=94158)

def test_create_area_with_zip(self):
area = lob.Area.create(
name = 'area_test_zip',
front = 'https://www.lob.com/areafront.pdf',
back = 'https://www.lob.com/areaback.pdf',
routes = ['94158','60031'],
target_type = 'all',
full_bleed = '1'
)
self.assertTrue(isinstance(area, lob.Area))


def test_create_area_with_route(self):
area = lob.Area.create(
name = 'area_test_route',
front = 'https://www.lob.com/areafront.pdf',
back = 'https://www.lob.com/areaback.pdf',
routes = self.route,
target_type = 'all',
full_bleed = '1'
)
self.assertTrue(isinstance(area, lob.Area))


def test_create_area_local_file(self):
area = lob.Area.create(
name = 'area_local_file',
front = open('tests/areafront.pdf', 'rb'),
back = open('tests/areaback.pdf', 'rb'),
routes = self.route,
target_type = 'all',
full_bleed = '1'
)
self.assertTrue(isinstance(area, lob.Area))

def test_create_area_fail(self):
self.assertRaises(lob.error.InvalidRequestError, lob.Area.create)

def test_list_areas(self):
areas = lob.Area.list()
self.assertTrue(isinstance(areas.data[0], lob.Area))
self.assertEqual(areas.object, 'list')

def test_list_areas_limit(self):
areas = lob.Area.list(count=2)
self.assertTrue(isinstance(areas.data[0], lob.Area))
self.assertEqual(len(areas.data), 2)

def test_list_area_fail(self):
self.assertRaises(lob.error.InvalidRequestError, lob.Area.list, count=1000)

def test_retrieve_area(self):
area = lob.Area.retrieve(id=lob.Area.list().data[0].id)
self.assertTrue(isinstance(area, lob.Area))

def test_retrieve_area_fail(self):
self.assertRaises(lob.error.InvalidRequestError, lob.Area.retrieve, id='test')
16 changes: 11 additions & 5 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,27 @@ def test_create_job_inline(self):
'setting_id': '201'
}
)
self.assertEqual(job.to_address.name, 'LOB1')
self.assertEqual(job.from_address.name, 'LOB2')
self.assertEqual(job.to_address.name, 'Lob1')
self.assertEqual(job.from_address.name, 'Lob2')
self.assertEqual(job.objects[0].name, 'Object1')
self.assertTrue(isinstance(job, lob.Job))

def test_create_job_multi_object(self):
job = lob.Job.create(
to_address = self.addr.id,
from_address = self.addr.id,
objects = [self.obj.id, self.obj.id]
objects = [
{
'name': 'Test Job',
'file': open('tests/pc.pdf', 'rb'),
'setting_id': 201,
'quantity': 2
}
]
)
self.assertEqual(job.to_address.id, self.addr.id)
self.assertEqual(job.from_address.id, self.addr.id)
self.assertEqual(job.objects[0].id, self.obj.id)
self.assertEqual(job.objects[1].id, self.obj.id)
self.assertEqual(job.objects[0].quantity, 2)
self.assertTrue(isinstance(job, lob.Job))

def test_create_job_local_file(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unittest
import lob
# Setting the API key
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc'

class RouteTest(unittest.TestCase):
def setUp(self):
lob.api_key = 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc'

def test_route_find(self):
print lob.Route.list(zip_codes=[94158,60031])