from __future__ import print_function

from listobj import List, UnknownList

InternalServerError = {
        'statusCode': 500,
        'message': 'Internal Server Error',
        }

def NotFound(obj):
        return {
                'statusCode': 404,
                'message': '{} not found.'.format(obj),
                }

def handle_api(event):
    method = event.get('method')
    if not method:
        return InternalServerError

    list_address = event.get('list')
    member_address = event.get('member')

    try:
        l = List(list_address)
    except (UnknownList, TypeError, ValueError):
        if method == 'POST' and not member_address:
            # Create a list.
            return create_list(list_address)
        return NotFound('List {}'.format(list_address))

    if member_address:
        # List Member API Call
        m = l.member_with_address(member_address)
        if method == 'POST':
            if m:
                return  # TODO: conflict error?
            return create_member(l, member_address)
        if method == 'PUT':
            return update_member(l, m)
        if method == 'GET':
            return get_member(l, m)
        # Unknown method.
        return InternalServerError

    # List API Call
    if method == 'POST':
        return  # TODO: conflict error?
    if method == 'PUT':
        return update_list(l)
    if method == 'GET':
        return get_list(l)
    # Unknown method.
    return InternalServerError
    
def create_list(list_address):
    pass

def update_list(l):
    pass

def get_list(l):
    pass

def create_member(l, member_address):
    pass

def update_member(l, m):
    pass

def get_member(l, m):
    pass


@@ -96,33 +96,33 @@
 or = %7B%0A        '
-s
+S
 tatusCode': 500,
@@ -123,33 +123,33 @@
 : 500,%0A        '
-m
+M
 essage': 'Intern
@@ -230,17 +230,17 @@
        '
-s
+S
 tatusCod
@@ -265,17 +265,17 @@
        '
-m
+M
 essage':
@@ -354,17 +354,29 @@
     
-method = 
+action = actions.get(
 even
@@ -386,16 +386,17 @@
 et('
-method
+Action
 ')
+)
 %0A   
@@ -403,22 +403,22 @@
  if not 
-method
+action
 :%0A      
@@ -481,57 +481,22 @@
 et('
-list')%0A    member_address = event.get('member
+ListAddress
 ')%0A
-%0A
     
@@ -508,17 +508,29 @@
         
-l
+event%5B'List'%5D
  = List(
@@ -604,481 +604,333 @@
     
-if method == 'POST' and not 
+event%5B'List'%5D = None%0A%0A    event%5B'Member'%5D = l.
 member_
+with_
 address
-:%0A            # Create a list.%0A            return create_list(list_a
+(event.get('MemberA
 ddress
+')
 )%0A
-   
     
- 
 return 
-NotFound('List %7B%7D'.format(list_address))%0A%0A    if member_address:%0A        # List Member API Call%0A        m = l.member_with_address(member_address)%0A        if method == 'POST':%0A            if m:%0A                return  # TODO: conflict error?%0A            return create_member(l, member_address)%0A        if method == 'PUT':%0A            return 
+action(**event)%0A    %0Aactions = dict(%0A        CreateList=create_list,%0A        UpdateList=update_list,%0A        GetList=get_list,%0A        CreateMember=create_member,%0A        InviteMember=invite_member,%0A        UpdateMember=
 upda
@@ -934,30 +934,25 @@
 pdate_member
-(l, m)
+,
 %0A        if 
@@ -952,47 +952,18 @@
     
-if method == 'GET':%0A            return 
+GetMember=
 get_
@@ -968,22 +968,17 @@
 t_member
-(l, m)
+,
 %0A       
@@ -982,239 +982,189 @@
     
-# Unknown method.%0A        return InternalServerError%0A%0A    # List API Call%0A    if method == 'POST':%0A        return  # TODO: conflict error?%0A    if method == 'PUT':%0A        return update_list(l)%0A    if method == 'GET'
+UnsubscribeMember=unsubscribe_member,%0A        DeleteMember=delete_member,%0A        )%0A%0Adef create_list(ListAddress, **kwargs):%0A    pass%0A%0Adef update_list(List, **kwargs)
 :%0A    
-    return
+pass%0A%0Adef
  get
@@ -1173,154 +1173,195 @@
 ist(
-l)%0A    # Unknown method.%0A    return InternalServerError%0A    %0Adef create_list(list_address):%0A    pass%0A%0Adef update_list(l):%0A    pass%0A%0Adef get_list(l
+List, **kwargs):%0A    pass%0A%0Adef create_member(List, MemberAddress, **kwargs):%0A    pass%0A%0Adef invite_member(List, MemberAddress, **kwargs):%0A    pass%0A%0Adef update_member(List, Member, **kwargs
 ):%0A 
@@ -1373,30 +1373,27 @@
 ss%0A%0Adef 
-create
+get
 _member(
 l, membe
@@ -1388,24 +1388,29 @@
 ber(
-l, m
+List, M
 ember
-_addres
+, **kwarg
 s):%0A
@@ -1428,25 +1428,48 @@
 ef u
-pdate_member(l, m
+nsubscribe_member(List, Member, **kwargs
 ):%0A 
@@ -1481,27 +1481,30 @@
 ss%0A%0Adef 
-g
+del
 et
+e
 _member(
 l, m):%0A 
@@ -1499,12 +1499,30 @@
 ber(
-l, m
+List, Member, **kwargs
 ):%0A 

Restructure API around manually invoking the lambda.