signature:
def _validate ( self , value ) :
    """Validates a value as a proper Flow object .
 Args :
 value : A value to be set on the property .
 Raises :
 TypeError if the value is not an instance of Flow ."""

implementation:
_LOGGER . info ( 'validate: Got type %s' , type ( value ) )
if value is not None and not isinstance ( value , client . Flow ) :
    raise TypeError ( 'Property {0} must be convertible to a flow ' 'instance; received: {1}.' . format ( self . _name , value ) )


signature:
def _from_base_type ( self , value ) :
    """Converts our stored JSON string back to the desired type .
 Args :
 value : A value from the datastore to be converted to the
 desired type .
 Returns :
 A deserialized Credentials ( or subclass ) object , else None if
 the value can ' t be parsed ."""

implementation:
if not value :
    return None
try : # Uses the from _ json method of the implied class of value
    credentials = client . Credentials . new_from_json ( value )
except ValueError :
    credentials = None
return credentials


signature:
def _make_flow ( request , scopes , return_url = None ) :
    """Creates a Web Server Flow
 Args :
 request : A Django request object .
 scopes : the request oauth2 scopes .
 return _ url : The URL to return to after the flow is complete . Defaults
 to the path of the current request .
 Returns :
 An OAuth2 flow object that has been stored in the session ."""

implementation:
# Generate a CSRF token to prevent malicious requests .
csrf_token = hashlib . sha256 ( os . urandom ( 1024 ) ) . hexdigest ( )
request . session [ _CSRF_KEY ] = csrf_token
state = json . dumps ( { 'csrf_token' : csrf_token , 'return_url' : return_url , } )
flow = client . OAuth2WebServerFlow ( client_id = django_util . oauth2_settings . client_id , client_secret = django_util . oauth2_settings . client_secret , scope = scopes , state = state , redirect_uri = request . build_absolute_uri ( urlresolvers . reverse ( "google_oauth:callback" ) ) )
flow_key = _FLOW_KEY . format ( csrf_token )
request . session [ flow_key ] = jsonpickle . encode ( flow )
return flow


signature:
def _get_flow_for_token ( csrf_token , request ) :
    """Looks up the flow in session to recover information about requested
 scopes .
 Args :
 csrf _ token : The token passed in the callback request that should
 match the one previously generated and stored in the request on the
 initial authorization view .
 Returns :
 The OAuth2 Flow object associated with this flow based on the
 CSRF token ."""

implementation:
flow_pickle = request . session . get ( _FLOW_KEY . format ( csrf_token ) , None )
return None if flow_pickle is None else jsonpickle . decode ( flow_pickle )


signature:
def oauth2_callback ( request ) :
    """View that handles the user ' s return from OAuth2 provider .
 This view verifies the CSRF state and OAuth authorization code , and on
 success stores the credentials obtained in the storage provider ,
 and redirects to the return _ url specified in the authorize view and
 stored in the session .
 Args :
 request : Django request .
 Returns :
 A redirect response back to the return _ url ."""

implementation:
if 'error' in request . GET :
    reason = request . GET . get ( 'error_description' , request . GET . get ( 'error' , '' ) )
    reason = html . escape ( reason )
    return http . HttpResponseBadRequest ( 'Authorization failed {0}' . format ( reason ) )
try :
    encoded_state = request . GET [ 'state' ]
    code = request . GET [ 'code' ]
except KeyError :
    return http . HttpResponseBadRequest ( 'Request missing state or authorization code' )
try :
    server_csrf = request . session [ _CSRF_KEY ]
except KeyError :
    return http . HttpResponseBadRequest ( 'No existing session for this flow.' )
try :
    state = json . loads ( encoded_state )
    client_csrf = state [ 'csrf_token' ]
    return_url = state [ 'return_url' ]
except ( ValueError , KeyError ) :
    return http . HttpResponseBadRequest ( 'Invalid state parameter.' )
if client_csrf != server_csrf :
    return http . HttpResponseBadRequest ( 'Invalid CSRF token.' )
flow = _get_flow_for_token ( client_csrf , request )
if not flow :
    return http . HttpResponseBadRequest ( 'Missing Oauth2 flow.' )
try :
    credentials = flow . step2_exchange ( code )
except client . FlowExchangeError as exchange_error :
    return http . HttpResponseBadRequest ( 'An error has occurred: {0}' . format ( exchange_error ) )
get_storage ( request ) . put ( credentials )
signals . oauth2_authorized . send ( sender = signals . oauth2_authorized , request = request , credentials = credentials )
return shortcuts . redirect ( return_url )


signature:
def oauth2_authorize ( request ) :
    """View to start the OAuth2 Authorization flow .
 This view starts the OAuth2 authorization flow . If scopes is passed in
 as a GET URL parameter , it will authorize those scopes , otherwise the
 default scopes specified in settings . The return _ url can also be
 specified as a GET parameter , otherwise the referer header will be
 checked , and if that isn ' t found it will return to the root path .
 Args :
 request : The Django request object .
 Returns :
 A redirect to Google OAuth2 Authorization ."""

implementation:
return_url = request . GET . get ( 'return_url' , None )
if not return_url :
    return_url = request . META . get ( 'HTTP_REFERER' , '/' )
scopes = request . GET . getlist ( 'scopes' , django_util . oauth2_settings . scopes )
# Model storage ( but not session storage ) requires a logged in user
if django_util . oauth2_settings . storage_model :
    if not request . user . is_authenticated ( ) :
        return redirect ( '{0}?next={1}' . format ( settings . LOGIN_URL , parse . quote ( request . get_full_path ( ) ) ) )
    # This checks for the case where we ended up here because of a logged
    # out user but we had credentials for it in the first place
    else :
        user_oauth = django_util . UserOAuth2 ( request , scopes , return_url )
        if user_oauth . has_credentials ( ) :
            return redirect ( return_url )
flow = _make_flow ( request = request , scopes = scopes , return_url = return_url )
auth_url = flow . step1_get_authorize_url ( )
return shortcuts . redirect ( auth_url )


signature:
def locked_get ( self ) :
    """Retrieve Credential from file .
 Returns :
 oauth2client . client . Credentials
 Raises :
 IOError if the file is a symbolic link ."""

implementation:
credentials = None
_helpers . validate_file ( self . _filename )
try :
    f = open ( self . _filename , 'rb' )
    content = f . read ( )
    f . close ( )
except IOError :
    return credentials
try :
    credentials = client . Credentials . new_from_json ( content )
    credentials . set_store ( self )
except ValueError :
    pass
return credentials


signature:
def _create_file_if_needed ( self ) :
    """Create an empty file if necessary .
 This method will not initialize the file . Instead it implements a
 simple version of " touch " to ensure the file has been created ."""

implementation:
if not os . path . exists ( self . _filename ) :
    old_umask = os . umask ( 0o177 )
    try :
        open ( self . _filename , 'a+b' ) . close ( )
    finally :
        os . umask ( old_umask )


signature:
def locked_put ( self , credentials ) :
    """Write Credentials to file .
 Args :
 credentials : Credentials , the credentials to store .
 Raises :
 IOError if the file is a symbolic link ."""

implementation:
self . _create_file_if_needed ( )
_helpers . validate_file ( self . _filename )
f = open ( self . _filename , 'w' )
f . write ( credentials . to_json ( ) )
f . close ( )


signature:
def to_python ( self , value ) :
    """Overrides ` ` models . Field ` ` method . This is used to convert
 bytes ( from serialization etc ) to an instance of this class"""

implementation:
if value is None :
    return None
elif isinstance ( value , oauth2client . client . Credentials ) :
    return value
else :
    try :
        return jsonpickle . decode ( base64 . b64decode ( encoding . smart_bytes ( value ) ) . decode ( ) )
    except ValueError :
        return pickle . loads ( base64 . b64decode ( encoding . smart_bytes ( value ) ) )


signature:
def get_prep_value ( self , value ) :
    """Overrides ` ` models . Field ` ` method . This is used to convert
 the value from an instances of this class to bytes that can be
 inserted into the database ."""

implementation:
if value is None :
    return None
else :
    return encoding . smart_text ( base64 . b64encode ( jsonpickle . encode ( value ) . encode ( ) ) )


signature:
def value_to_string ( self , obj ) :
    """Convert the field value from the provided model to a string .
 Used during model serialization .
 Args :
 obj : db . Model , model object
 Returns :
 string , the serialized field value"""

implementation:
value = self . _get_val_from_obj ( obj )
return self . get_prep_value ( value )


signature:
def make_signed_jwt ( signer , payload , key_id = None ) :
    """Make a signed JWT .
 See http : / / self - issued . info / docs / draft - jones - json - web - token . html .
 Args :
 signer : crypt . Signer , Cryptographic signer .
 payload : dict , Dictionary of data to convert to JSON and then sign .
 key _ id : string , ( Optional ) Key ID header .
 Returns :
 string , The JWT for the payload ."""

implementation:
header = { 'typ' : 'JWT' , 'alg' : 'RS256' }
if key_id is not None :
    header [ 'kid' ] = key_id
segments = [ _helpers . _urlsafe_b64encode ( _helpers . _json_encode ( header ) ) , _helpers . _urlsafe_b64encode ( _helpers . _json_encode ( payload ) ) , ]
signing_input = b'.' . join ( segments )
signature = signer . sign ( signing_input )
segments . append ( _helpers . _urlsafe_b64encode ( signature ) )
logger . debug ( str ( segments ) )
return b'.' . join ( segments )


signature:
def _verify_signature ( message , signature , certs ) :
    """Verifies signed content using a list of certificates .
 Args :
 message : string or bytes , The message to verify .
 signature : string or bytes , The signature on the message .
 certs : iterable , certificates in PEM format .
 Raises :
 AppIdentityError : If none of the certificates can verify the message
 against the signature ."""

implementation:
for pem in certs :
    verifier = Verifier . from_string ( pem , is_x509_cert = True )
    if verifier . verify ( message , signature ) :
        return
# If we have not returned , no certificate confirms the signature .
raise AppIdentityError ( 'Invalid token signature' )


signature:
def _check_audience ( payload_dict , audience ) :
    """Checks audience field from a JWT payload .
 Does nothing if the passed in ` ` audience ` ` is null .
 Args :
 payload _ dict : dict , A dictionary containing a JWT payload .
 audience : string or NoneType , an audience to check for in
 the JWT payload .
 Raises :
 AppIdentityError : If there is no ` ` ' aud ' ` ` field in the payload
 dictionary but there is an ` ` audience ` ` to check .
 AppIdentityError : If the ` ` ' aud ' ` ` field in the payload dictionary
 does not match the ` ` audience ` ` ."""

implementation:
if audience is None :
    return
audience_in_payload = payload_dict . get ( 'aud' )
if audience_in_payload is None :
    raise AppIdentityError ( 'No aud field in token: {0}' . format ( payload_dict ) )
if audience_in_payload != audience :
    raise AppIdentityError ( 'Wrong recipient, {0} != {1}: {2}' . format ( audience_in_payload , audience , payload_dict ) )


signature:
def _verify_time_range ( payload_dict ) :
    """Verifies the issued at and expiration from a JWT payload .
 Makes sure the current time ( in UTC ) falls between the issued at and
 expiration for the JWT ( with some skew allowed for via
 ` ` CLOCK _ SKEW _ SECS ` ` ) .
 Args :
 payload _ dict : dict , A dictionary containing a JWT payload .
 Raises :
 AppIdentityError : If there is no ` ` ' iat ' ` ` field in the payload
 dictionary .
 AppIdentityError : If there is no ` ` ' exp ' ` ` field in the payload
 dictionary .
 AppIdentityError : If the JWT expiration is too far in the future ( i . e .
 if the expiration would imply a token lifetime
 longer than what is allowed . )
 AppIdentityError : If the token appears to have been issued in the
 future ( up to clock skew ) .
 AppIdentityError : If the token appears to have expired in the past
 ( up to clock skew ) ."""

implementation:
# Get the current time to use throughout .
now = int ( time . time ( ) )
# Make sure issued at and expiration are in the payload .
issued_at = payload_dict . get ( 'iat' )
if issued_at is None :
    raise AppIdentityError ( 'No iat field in token: {0}' . format ( payload_dict ) )
expiration = payload_dict . get ( 'exp' )
if expiration is None :
    raise AppIdentityError ( 'No exp field in token: {0}' . format ( payload_dict ) )
# Make sure the expiration gives an acceptable token lifetime .
if expiration >= now + MAX_TOKEN_LIFETIME_SECS :
    raise AppIdentityError ( 'exp field too far in future: {0}' . format ( payload_dict ) )
# Make sure ( up to clock skew ) that the token wasn ' t issued in the future .
earliest = issued_at - CLOCK_SKEW_SECS
if now < earliest :
    raise AppIdentityError ( 'Token used too early, {0} < {1}: {2}' . format ( now , earliest , payload_dict ) )
# Make sure ( up to clock skew ) that the token isn ' t already expired .
latest = expiration + CLOCK_SKEW_SECS
if now > latest :
    raise AppIdentityError ( 'Token used too late, {0} > {1}: {2}' . format ( now , latest , payload_dict ) )


signature:
def verify_signed_jwt_with_certs ( jwt , certs , audience = None ) :
    """Verify a JWT against public certs .
 See http : / / self - issued . info / docs / draft - jones - json - web - token . html .
 Args :
 jwt : string , A JWT .
 certs : dict , Dictionary where values of public keys in PEM format .
 audience : string , The audience , ' aud ' , that this JWT should contain . If
 None then the JWT ' s ' aud ' parameter is not verified .
 Returns :
 dict , The deserialized JSON payload in the JWT .
 Raises :
 AppIdentityError : if any checks are failed ."""

implementation:
jwt = _helpers . _to_bytes ( jwt )
if jwt . count ( b'.' ) != 2 :
    raise AppIdentityError ( 'Wrong number of segments in token: {0}' . format ( jwt ) )
header , payload , signature = jwt . split ( b'.' )
message_to_sign = header + b'.' + payload
signature = _helpers . _urlsafe_b64decode ( signature )
# Parse token .
payload_bytes = _helpers . _urlsafe_b64decode ( payload )
try :
    payload_dict = json . loads ( _helpers . _from_bytes ( payload_bytes ) )
except :
    raise AppIdentityError ( 'Can\'t parse token: {0}' . format ( payload_bytes ) )
# Verify that the signature matches the message .
_verify_signature ( message_to_sign , signature , certs . values ( ) )
# Verify the issued at and created times in the payload .
_verify_time_range ( payload_dict )
# Check audience .
_check_audience ( payload_dict , audience )
return payload_dict


signature:
def get ( self , template_id , ** queryparams ) :
    """Get information about a specific template .
 : param template _ id : The unique id for the template .
 : type template _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . template_id = template_id
return self . _mc_client . _get ( url = self . _build_path ( template_id ) , ** queryparams )


signature:
def update ( self , template_id , data ) :
    """Update the name , HTML , or folder _ id of an existing template .
 : param template _ id : The unique id for the template .
 : type template _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " html " : string *"""

implementation:
if 'name' not in data :
    raise KeyError ( 'The template must have a name' )
if 'html' not in data :
    raise KeyError ( 'The template must have html' )
self . template_id = template_id
return self . _mc_client . _patch ( url = self . _build_path ( template_id ) , data = data )


signature:
def delete ( self , template_id ) :
    """Delete a specific template .
 : param template _ id : The unique id for the template .
 : type template _ id : : py : class : ` str `"""

implementation:
self . template_id = template_id
return self . _mc_client . _delete ( url = self . _build_path ( template_id ) )


signature:
def get_subscriber_hash ( member_email ) :
    """The MD5 hash of the lowercase version of the list member ' s email .
 Used as subscriber _ hash
 : param member _ email : The member ' s email address
 : type member _ email : : py : class : ` str `
 : returns : The MD5 hash in hex
 : rtype : : py : class : ` str `"""

implementation:
check_email ( member_email )
member_email = member_email . lower ( ) . encode ( )
m = hashlib . md5 ( member_email )
return m . hexdigest ( )


signature:
def check_url ( url ) :
    """Function that verifies that the string passed is a valid url .
 Original regex author Diego Perini ( http : / / www . iport . it )
 regex ported to Python by adamrofer ( https : / / github . com / adamrofer )
 Used under MIT license .
 : param url :
 : return : Nothing"""


signature:
def merge_results ( x , y ) :
    """Given two dicts , x and y , merge them into a new dict as a shallow copy .
 The result only differs from ` x . update ( y ) ` in the way that it handles list
 values when both x and y have list values for the same key . In which case
 the returned dictionary , z , has a value according to :
 z [ key ] = x [ key ] + z [ key ]
 : param x : The first dictionary
 : type x : : py : class : ` dict `
 : param y : The second dictionary
 : type y : : py : class : ` dict `
 : returns : The merged dictionary
 : rtype : : py : class : ` dict `"""

implementation:
z = x . copy ( )
for key , value in y . items ( ) :
    if isinstance ( value , list ) and isinstance ( z . get ( key ) , list ) :
        z [ key ] += value
    else :
        z [ key ] = value
return z


signature:
def create ( self , data ) :
    """Create a new list in your MailChimp account .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " contact " : object *
 " company " : string * ,
 " address1 " : string * ,
 " city " : string * ,
 " state " : string * ,
 " zip " : string * ,
 " country " : string *
 " permission _ reminder " : string * ,
 " campaign _ defaults " : object *
 " from _ name " : string * ,
 " from _ email " : string * ,
 " subject " : string * ,
 " language " : string *
 " email _ type _ option " : boolean"""

implementation:
if 'name' not in data :
    raise KeyError ( 'The list must have a name' )
if 'contact' not in data :
    raise KeyError ( 'The list must have a contact' )
if 'company' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a company' )
if 'address1' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a address1' )
if 'city' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a city' )
if 'state' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a state' )
if 'zip' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a zip' )
if 'country' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a country' )
if 'permission_reminder' not in data :
    raise KeyError ( 'The list must have a permission_reminder' )
if 'campaign_defaults' not in data :
    raise KeyError ( 'The list must have a campaign_defaults' )
if 'from_name' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a from_name' )
if 'from_email' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a from_email' )
check_email ( data [ 'campaign_defaults' ] [ 'from_email' ] )
if 'subject' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a subject' )
if 'language' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a language' )
if 'email_type_option' not in data :
    raise KeyError ( 'The list must have an email_type_option' )
if data [ 'email_type_option' ] not in [ True , False ] :
    raise TypeError ( 'The list email_type_option must be True or False' )
response = self . _mc_client . _post ( url = self . _build_path ( ) , data = data )
if response is not None :
    self . list_id = response [ 'id' ]
else :
    self . list_id = None
return response


signature:
def update_members ( self , list_id , data ) :
    """Batch subscribe or unsubscribe list members .
 Only the members array is required in the request body parameters .
 Within the members array , each member requires an email _ address
 and either a status or status _ if _ new . The update _ existing parameter
 will also be considered required to help prevent accidental updates
 to existing members and will default to false if not present .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " members " : array *
 " email _ address " : string * ,
 " status " : string * ( Must be one of ' subscribed ' , ' unsubscribed ' , ' cleaned ' , or ' pending ' ) ,
 " status _ if _ new " : string * ( Must be one of ' subscribed ' , ' unsubscribed ' , ' cleaned ' , or ' pending ' )
 " update _ existing " : boolean *"""

implementation:
self . list_id = list_id
if 'members' not in data :
    raise KeyError ( 'The update must have at least one member' )
else :
    if not len ( data [ 'members' ] ) <= 500 :
        raise ValueError ( 'You may only batch sub/unsub 500 members at a time' )
for member in data [ 'members' ] :
    if 'email_address' not in member :
        raise KeyError ( 'Each list member must have an email_address' )
    check_email ( member [ 'email_address' ] )
    if 'status' not in member and 'status_if_new' not in member :
        raise KeyError ( 'Each list member must have either a status or a status_if_new' )
    valid_statuses = [ 'subscribed' , 'unsubscribed' , 'cleaned' , 'pending' ]
    if 'status' in member and member [ 'status' ] not in valid_statuses :
        raise ValueError ( 'The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"' )
    if 'status_if_new' in member and member [ 'status_if_new' ] not in valid_statuses :
        raise ValueError ( 'The list member status_if_new must be one of "subscribed", "unsubscribed", ' '"cleaned", or "pending"' )
if 'update_existing' not in data :
    data [ 'update_existing' ] = False
return self . _mc_client . _post ( url = self . _build_path ( list_id ) , data = data )


signature:
def update ( self , list_id , data ) :
    """Update the settings for a specific list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " contact " : object *
 " company " : string * ,
 " address1 " : string * ,
 " city " : string * ,
 " state " : string * ,
 " zip " : string * ,
 " country " : string *
 " permission _ reminder " : string * ,
 " campaign _ defaults " : object *
 " from _ name " : string * ,
 " from _ email " : string * ,
 " subject " : string * ,
 " language " : string *
 " email _ type _ option " : boolean"""

implementation:
self . list_id = list_id
if 'name' not in data :
    raise KeyError ( 'The list must have a name' )
if 'contact' not in data :
    raise KeyError ( 'The list must have a contact' )
if 'company' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a company' )
if 'address1' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a address1' )
if 'city' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a city' )
if 'state' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a state' )
if 'zip' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a zip' )
if 'country' not in data [ 'contact' ] :
    raise KeyError ( 'The list contact must have a country' )
if 'permission_reminder' not in data :
    raise KeyError ( 'The list must have a permission_reminder' )
if 'campaign_defaults' not in data :
    raise KeyError ( 'The list must have a campaign_defaults' )
if 'from_name' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a from_name' )
if 'from_email' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a from_email' )
check_email ( data [ 'campaign_defaults' ] [ 'from_email' ] )
if 'subject' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a subject' )
if 'language' not in data [ 'campaign_defaults' ] :
    raise KeyError ( 'The list campaign_defaults must have a language' )
if 'email_type_option' not in data :
    raise KeyError ( 'The list must have an email_type_option' )
if data [ 'email_type_option' ] not in [ True , False ] :
    raise TypeError ( 'The list email_type_option must be True or False' )
return self . _mc_client . _patch ( url = self . _build_path ( list_id ) , data = data )


signature:
def create ( self , store_id , order_id , data ) :
    """Add a new line item to an existing order .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param order _ id : The id for the order in a store .
 : type order _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " product _ id " : string * ,
 " product _ variant _ id " : string * ,
 " quantity " : integer * ,
 " price " : number *"""

implementation:
self . store_id = store_id
self . order_id = order_id
if 'id' not in data :
    raise KeyError ( 'The order line must have an id' )
if 'product_id' not in data :
    raise KeyError ( 'The order line must have a product_id' )
if 'product_variant_id' not in data :
    raise KeyError ( 'The order line must have a product_variant_id' )
if 'quantity' not in data :
    raise KeyError ( 'The order line must have a quantity' )
if 'price' not in data :
    raise KeyError ( 'The order line must have a price' )
response = self . _mc_client . _post ( url = self . _build_path ( store_id , 'orders' , order_id , 'lines' ) )
if response is not None :
    self . line_id = response [ 'id' ]
else :
    self . line_id = None
return response


signature:
def get ( self , ** queryparams ) :
    """Get links to all other resources available in the API .
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation: return self . _mc_client . _get ( url = self . _build_path ( ) , ** queryparams )


signature:
def create ( self , data ) :
    """Retrieve OAuth2 - based credentials to associate API calls with your
 application .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " client _ id " : string * ,
 " client _ secret " : string *"""

implementation:
self . app_id = None
if 'client_id' not in data :
    raise KeyError ( 'The authorized app must have a client_id' )
if 'client_secret' not in data :
    raise KeyError ( 'The authorized app must have a client_secret' )
return self . _mc_client . _post ( url = self . _build_path ( ) , data = data )


signature:
def get ( self , app_id , ** queryparams ) :
    """Get information about a specific authorized application
 : param app _ id : The unique id for the connected authorized application
 : type app _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . app_id = app_id
return self . _mc_client . _get ( url = self . _build_path ( app_id ) , ** queryparams )


signature:
def create ( self , store_id , data ) :
    """Add new promo rule to a store
 : param store _ id : The store id
 : type store _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict '
 data = {
 " id " : string * ,
 " title " : string ,
 " description " : string * ,
 " starts _ at " : string ,
 " ends _ at " : string ,
 " amount " : number * ,
 " type " : string * ,
 " target " : string * ,
 " enabled " : boolean ,
 " created _ at _ foreign " : string ,
 " updated _ at _ foreign " : string ,"""

implementation:
self . store_id = store_id
if 'id' not in data :
    raise KeyError ( 'The promo rule must have an id' )
if 'description' not in data :
    raise KeyError ( 'This promo rule must have a description' )
if 'amount' not in data :
    raise KeyError ( 'This promo rule must have an amount' )
if 'target' not in data :
    raise KeyError ( 'This promo rule must apply to a target (example per_item, total, or shipping' )
response = self . _mc_client . _post ( url = self . _build_path ( store_id , 'promo-rules' ) , data = data )
if response is not None :
    return response


signature:
def get ( self , folder_id , ** queryparams ) :
    """Get information about a specific folder used to organize campaigns .
 : param folder _ id : The unique id for the campaign folder .
 : type folder _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . folder_id = folder_id
return self . _mc_client . _get ( url = self . _build_path ( folder_id ) , ** queryparams )


signature:
def delete ( self , folder_id ) :
    """Delete a specific campaign folder , and mark all the campaigns in the
 folder as ‘ unfiled ’ .
 : param folder _ id : The unique id for the campaign folder .
 : type folder _ id : : py : class : ` str `"""

implementation:
self . folder_id = folder_id
return self . _mc_client . _delete ( url = self . _build_path ( folder_id ) )


signature:
def get ( self , workflow_id , email_id ) :
    """Get information about an individual Automation workflow email .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
return self . _mc_client . _get ( url = self . _build_path ( workflow_id , 'emails' , email_id ) )


signature:
def create ( self , data ) :
    """Upload a new image or file to the File Manager .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " file _ data " : string *"""

implementation:
if 'name' not in data :
    raise KeyError ( 'The file must have a name' )
if 'file_data' not in data :
    raise KeyError ( 'The file must have file_data' )
response = self . _mc_client . _post ( url = self . _build_path ( ) , data = data )
if response is not None :
    self . file_id = response [ 'id' ]
else :
    self . file_id = None
return response


signature:
def get ( self , file_id , ** queryparams ) :
    """Get information about a specific file in the File Manager .
 : param file _ id : The unique id for the File Manager file .
 : type file _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . file_id = file_id
return self . _mc_client . _get ( url = self . _build_path ( file_id ) , ** queryparams )


signature:
def update ( self , file_id , data ) :
    """Update a file in the File Manager .
 : param file _ id : The unique id for the File Manager file .
 : type file _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " file _ data " : string *"""

implementation:
self . file_id = file_id
if 'name' not in data :
    raise KeyError ( 'The file must have a name' )
if 'file_data' not in data :
    raise KeyError ( 'The file must have file_data' )
return self . _mc_client . _patch ( url = self . _build_path ( file_id ) , data = data )


signature:
def delete ( self , file_id ) :
    """Remove a specific file from the File Manager .
 : param file _ id : The unique id for the File Manager file .
 : type file _ id : : py : class : ` str `"""

implementation:
self . file_id = file_id
return self . _mc_client . _delete ( url = self . _build_path ( file_id ) )


signature:
def _build_path ( self , * args ) :
    """Build path with endpoint and args
 : param args : Tokens in the endpoint URL
 : type args : : py : class : ` unicode `"""

implementation: return '/' . join ( chain ( ( self . endpoint , ) , map ( str , args ) ) )


signature:
def _iterate ( self , url , ** queryparams ) :
    """Iterate over all pages for the given url . Feed in the result of self . _ build _ path as the url .
 : param url : The url of the endpoint
 : type url : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]
 queryparams [ ' count ' ] = integer
 queryparams [ ' offset ' ] = integer"""

implementation:
# fields as a query string parameter should be a string with
# comma - separated substring values to pass along to
# self . _ mc _ client . _ get ( ) . It should also contain total _ items whenever
# the parameter is employed , which is forced here .
if 'fields' in queryparams :
    if 'total_items' not in queryparams [ 'fields' ] . split ( ',' ) :
        queryparams [ 'fields' ] += ',total_items'
# Remove offset and count if provided in queryparams
# to avoid ' multiple values for keyword argument ' TypeError
queryparams . pop ( "offset" , None )
queryparams . pop ( "count" , None )
# Fetch results from mailchimp , up to first 1000
result = self . _mc_client . _get ( url = url , offset = 0 , count = 1000 , ** queryparams )
total = result [ 'total_items' ]
# Fetch further results if necessary
if total > 1000 :
    for offset in range ( 1 , int ( total / 1000 ) + 1 ) :
        result = merge_results ( result , self . _mc_client . _get ( url = url , offset = int ( offset * 1000 ) , count = 1000 , ** queryparams ) )
    return result
else : # Further results not necessary
    return result


signature:
def create ( self , workflow_id , data ) :
    """Remove a subscriber from a specific Automation workflow . You can
 remove a subscriber at any point in an Automation workflow , regardless
 of how many emails they ’ ve been sent from that workflow . Once they ’ re
 removed , they can never be added back to the same workflow .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " email _ address " : string *"""

implementation:
self . workflow_id = workflow_id
if 'email_address' not in data :
    raise KeyError ( 'The automation removed subscriber must have an email_address' )
check_email ( data [ 'email_address' ] )
return self . _mc_client . _post ( url = self . _build_path ( workflow_id , 'removed-subscribers' ) , data = data )


signature:
def all ( self , workflow_id ) :
    """Get information about subscribers who were removed from an Automation
 workflow .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
return self . _mc_client . _get ( url = self . _build_path ( workflow_id , 'removed-subscribers' ) )


signature:
def create ( self , list_id , data ) :
    """Create a new webhook for a specific list .
 The documentation does not include any required request body
 parameters but the url parameter is being listed here as a required
 parameter in documentation and error - checking based on the description
 of the method
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " url " : string *"""

implementation:
self . list_id = list_id
if 'url' not in data :
    raise KeyError ( 'The list webhook must have a url' )
check_url ( data [ 'url' ] )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'webhooks' ) , data = data )
if response is not None :
    self . webhook_id = response [ 'id' ]
else :
    self . webhook_id = None
return response


signature:
def get ( self , list_id , webhook_id ) :
    """Get information about a specific webhook .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param webhook _ id : The unique id for the webhook .
 : type webhook _ id : : py : class : ` str `"""

implementation:
self . list_id = list_id
self . webhook_id = webhook_id
return self . _mc_client . _get ( url = self . _build_path ( list_id , 'webhooks' , webhook_id ) )


signature:
def update ( self , list_id , webhook_id , data ) :
    """Update the settings for an existing webhook .
 : param list _ id : The unique id for the list
 : type list _ id : : py : class : ` str `
 : param webhook _ id : The unique id for the webhook
 : type webhook _ id : : py : class : ` str `"""

implementation:
self . list_id = list_id
self . webhook_id = webhook_id
return self . _mc_client . _patch ( url = self . _build_path ( list_id , 'webhooks' , webhook_id ) , data = data )


signature:
def delete ( self , list_id , webhook_id ) :
    """Delete a specific webhook in a list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param webhook _ id : The unique id for the webhook .
 : type webhook _ id : : py : class : ` str `"""

implementation:
self . list_id = list_id
self . webhook_id = webhook_id
return self . _mc_client . _delete ( url = self . _build_path ( list_id , 'webhooks' , webhook_id ) )


signature:
def all ( self , list_id , ** queryparams ) :
    """returns the first 10 segments for a specific list ."""

implementation: return self . _mc_client . _get ( url = self . _build_path ( list_id , 'segments' ) , ** queryparams )


signature:
def get ( self , list_id , segment_id ) :
    """returns the specified list segment ."""

implementation: return self . _mc_client . _get ( url = self . _build_path ( list_id , 'segments' , segment_id ) )


signature:
def update ( self , list_id , segment_id , data ) :
    """updates an existing list segment ."""

implementation: return self . _mc_client . _patch ( url = self . _build_path ( list_id , 'segments' , segment_id ) , data = data )


signature:
def delete ( self , list_id , segment_id ) :
    """removes an existing list segment from the list . This cannot be undone ."""

implementation: return self . _mc_client . _delete ( url = self . _build_path ( list_id , 'segments' , segment_id ) )


signature:
def create ( self , list_id , data ) :
    """adds a new segment to the list ."""

implementation: return self . _mc_client . _post ( url = self . _build_path ( list_id , 'segments' ) , data = data )


signature:
def _post ( self , url , data = None ) :
    """Handle authenticated POST requests
 : param url : The url for the endpoint including path parameters
 : type url : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : data : ` none ` or : py : class : ` dict `
 : returns : The JSON output from the API or an error message"""

implementation:
url = urljoin ( self . base_url , url )
try :
    r = self . _make_request ( ** dict ( method = 'POST' , url = url , json = data , auth = self . auth , timeout = self . timeout , hooks = self . request_hooks , headers = self . request_headers ) )
except requests . exceptions . RequestException as e :
    raise e
else :
    if r . status_code >= 400 : # in case of a 500 error , the response might not be a JSON
        try :
            error_data = r . json ( )
        except ValueError :
            error_data = { "response" : r }
        raise MailChimpError ( error_data )
    if r . status_code == 204 :
        return None
    return r . json ( )


signature:
def get_metadata ( self ) :
    """Get the metadata returned after authentication"""

implementation:
try :
    r = requests . get ( 'https://login.mailchimp.com/oauth2/metadata' , auth = self )
except requests . exceptions . RequestException as e :
    raise e
else :
    r . raise_for_status ( )
    output = r . json ( )
    if 'error' in output :
        raise requests . exceptions . RequestException ( output [ 'error' ] )
    return output


signature:
def update ( self , campaign_id , data ) :
    """Set the content for a campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _put ( url = self . _build_path ( campaign_id , 'content' ) , data = data )


signature:
def get ( self , conversation_id , ** queryparams ) :
    """Get details about an individual conversation .
 : param conversation _ id : The unique id for the conversation .
 : type conversation _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . conversation_id = conversation_id
return self . _mc_client . _get ( url = self . _build_path ( conversation_id ) , ** queryparams )


signature:
def all ( self , campaign_id , get_all = False , ** queryparams ) :
    """Get information about members who have unsubscribed from a specific
 campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param get _ all : Should the query get all results
 : type get _ all : : py : class : ` bool `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]
 queryparams [ ' count ' ] = integer
 queryparams [ ' offset ' ] = integer"""

implementation:
self . campaign_id = campaign_id
self . subscriber_hash = None
if get_all :
    return self . _iterate ( url = self . _build_path ( campaign_id , 'unsubscribed' ) , ** queryparams )
else :
    return self . _mc_client . _get ( url = self . _build_path ( campaign_id , 'unsubscribed' ) , ** queryparams )


signature:
def all ( self , template_id , ** queryparams ) :
    """Get the sections that you can edit in a template , including each
 section ’ s default content .
 : param template _ id : The unique id for the template .
 : type template _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . template_id = template_id
return self . _mc_client . _get ( url = self . _build_path ( template_id , 'default-content' ) , ** queryparams )


signature:
def create ( self , workflow_id , email_id , data ) :
    """Manually add a subscriber to a workflow , bypassing the default trigger
 settings . You can also use this endpoint to trigger a series of
 automated emails in an API 3.0 workflow type or add subscribers to an
 automated email queue that uses the API request delay type .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " email _ address " : string *"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
if 'email_address' not in data :
    raise KeyError ( 'The automation email queue must have an email_address' )
check_email ( data [ 'email_address' ] )
response = self . _mc_client . _post ( url = self . _build_path ( workflow_id , 'emails' , email_id , 'queue' ) , data = data )
if response is not None :
    self . subscriber_hash = response [ 'id' ]
else :
    self . subscriber_hash = None
return response


signature:
def all ( self , workflow_id , email_id ) :
    """Get information about an Automation email queue .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
self . subscriber_hash = None
return self . _mc_client . _get ( url = self . _build_path ( workflow_id , 'emails' , email_id , 'queue' ) )


signature:
def get ( self , workflow_id , email_id , subscriber_hash ) :
    """Get information about a specific subscriber in an Automation email
 queue .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . workflow_id = workflow_id
self . email_id = email_id
self . subscriber_hash = subscriber_hash
return self . _mc_client . _get ( url = self . _build_path ( workflow_id , 'emails' , email_id , 'queue' , subscriber_hash ) )


signature:
def cancel ( self , campaign_id ) :
    """Cancel a Regular or Plain - Text Campaign after you send , before all of
 your recipients receive it . This feature is included with MailChimp
 Pro .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/cancel-send' ) )


signature:
def pause ( self , campaign_id ) :
    """Pause an RSS - Driven campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/pause' ) )


signature:
def replicate ( self , campaign_id ) :
    """Replicate a campaign in saved or send status .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/replicate' ) )


signature:
def resume ( self , campaign_id ) :
    """Resume an RSS - Driven campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/resume' ) )


signature:
def schedule ( self , campaign_id , data ) :
    """Schedule a campaign for delivery . If you ’ re using Multivariate
 Campaigns to test send times or sending RSS Campaigns , use the send
 action instead .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " schedule _ time " : datetime * ( A UTC timezone datetime that ends on the quarter hour [ : 00 , : 15 , : 30 , or : 45 ] )"""

implementation:
if not data [ 'schedule_time' ] :
    raise ValueError ( 'You must supply a schedule_time' )
else :
    if data [ 'schedule_time' ] . tzinfo is None :
        raise ValueError ( 'The schedule_time must be in UTC' )
    else :
        if data [ 'schedule_time' ] . tzinfo . utcoffset ( None ) != timedelta ( 0 ) :
            raise ValueError ( 'The schedule_time must be in UTC' )
if data [ 'schedule_time' ] . minute not in [ 0 , 15 , 30 , 45 ] :
    raise ValueError ( 'The schedule_time must end on the quarter hour (00, 15, 30, 45)' )
data [ 'schedule_time' ] = data [ 'schedule_time' ] . strftime ( '%Y-%m-%dT%H:%M:00+00:00' )
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/schedule' ) , data = data )


signature:
def send ( self , campaign_id ) :
    """Send a MailChimp campaign . For RSS Campaigns , the campaign will send
 according to its schedule . All other campaigns will send immediately .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/send' ) )


signature:
def unschedule ( self , campaign_id ) :
    """Unschedule a scheduled campaign that hasn ’ t started sending .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'actions/unschedule' ) )


signature:
def create ( self , store_id , data ) :
    """Add a new customer to a store .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " email _ address " : string * ,
 " opt _ in _ status " : boolean *"""

implementation:
self . store_id = store_id
if 'id' not in data :
    raise KeyError ( 'The store customer must have an id' )
if 'email_address' not in data :
    raise KeyError ( 'The store customer must have an email_address' )
check_email ( data [ 'email_address' ] )
if 'opt_in_status' not in data :
    raise KeyError ( 'The store customer must have an opt_in_status' )
if data [ 'opt_in_status' ] not in [ True , False ] :
    raise TypeError ( 'The opt_in_status must be True or False' )
response = self . _mc_client . _post ( url = self . _build_path ( store_id , 'customers' ) , data = data )
if response is not None :
    self . customer_id = response [ 'id' ]
else :
    self . customer_id = None
return response


signature:
def get ( self , store_id , customer_id , ** queryparams ) :
    """Get information about a specific customer .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param customer _ id : The id for the customer of a store .
 : type customer _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . store_id = store_id
self . customer_id = customer_id
return self . _mc_client . _get ( url = self . _build_path ( store_id , 'customers' , customer_id ) , ** queryparams )


signature:
def create_or_update ( self , store_id , customer_id , data ) :
    """Add or update a customer .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param customer _ id : The id for the customer of a store .
 : type customer _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " email _ address " : string * ,
 " opt _ in _ status " : boolean"""

implementation:
self . store_id = store_id
self . customer_id = customer_id
if 'id' not in data :
    raise KeyError ( 'The store customer must have an id' )
if 'email_address' not in data :
    raise KeyError ( 'Each store customer must have an email_address' )
check_email ( data [ 'email_address' ] )
if 'opt_in_status' not in data :
    raise KeyError ( 'The store customer must have an opt_in_status' )
if data [ 'opt_in_status' ] not in [ True , False ] :
    raise TypeError ( 'The opt_in_status must be True or False' )
return self . _mc_client . _put ( url = self . _build_path ( store_id , 'customers' , customer_id ) , data = data )


signature:
def create_or_update ( self , store_id , product_id , variant_id , data ) :
    """Add or update a product variant .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param product _ id : The id for the product of a store .
 : type product _ id : : py : class : ` str `
 : param variant _ id : The id for the product variant .
 : type variant _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " title " : string *"""

implementation:
self . store_id = store_id
self . product_id = product_id
self . variant_id = variant_id
if 'id' not in data :
    raise KeyError ( 'The product variant must have an id' )
if 'title' not in data :
    raise KeyError ( 'The product variant must have a title' )
return self . _mc_client . _put ( url = self . _build_path ( store_id , 'products' , product_id , 'variants' , variant_id ) , data = data )


signature:
def create ( self , campaign_id , data , ** queryparams ) :
    """Add feedback on a specific campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " message " : string *
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . campaign_id = campaign_id
if 'message' not in data :
    raise KeyError ( 'The campaign feedback must have a message' )
response = self . _mc_client . _post ( url = self . _build_path ( campaign_id , 'feedback' ) , data = data , ** queryparams )
if response is not None :
    self . feedback_id = response [ 'feedback_id' ]
else :
    self . feedback_id = None
return response


signature:
def update ( self , campaign_id , feedback_id , data ) :
    """Update a specific feedback message for a campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param feedback _ id : The unique id for the feedback message .
 : type feedback _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " message " : string *"""

implementation:
self . campaign_id = campaign_id
self . feedback_id = feedback_id
if 'message' not in data :
    raise KeyError ( 'The campaign feedback must have a message' )
return self . _mc_client . _patch ( url = self . _build_path ( campaign_id , 'feedback' , feedback_id ) , data = data )


signature:
def create ( self , list_id , data ) :
    """Add a new merge field for a specific list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string * ,
 " type " : string *"""

implementation:
self . list_id = list_id
if 'name' not in data :
    raise KeyError ( 'The list merge field must have a name' )
if 'type' not in data :
    raise KeyError ( 'The list merge field must have a type' )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'merge-fields' ) , data = data )
if response is not None :
    self . merge_id = response [ 'merge_id' ]
else :
    self . merge_id = None
return response


signature:
def get ( self , list_id , merge_id ) :
    """Get information about a specific merge field in a list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param merge _ id : The id for the merge field .
 : type merge _ id : : py : class : ` str `"""

implementation:
self . list_id = list_id
self . merge_id = merge_id
return self . _mc_client . _get ( url = self . _build_path ( list_id , 'merge-fields' , merge_id ) )


signature:
def get ( self , batch_webhook_id , ** queryparams ) :
    """Get information about a specific batch webhook .
 : param batch _ webhook _ id : The unique id for the batch webhook .
 : type batch _ webhook _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . batch_webhook_id = batch_webhook_id
return self . _mc_client . _get ( url = self . _build_path ( batch_webhook_id ) , ** queryparams )


signature:
def update ( self , batch_webhook_id , data ) :
    """Update a webhook that will fire whenever any batch request completes
 processing .
 : param batch _ webhook _ id : The unique id for the batch webhook .
 : type batch _ webhook _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " url " : string *"""

implementation:
self . batch_webhook_id = batch_webhook_id
if 'url' not in data :
    raise KeyError ( 'The batch webhook must have a valid url' )
return self . _mc_client . _patch ( url = self . _build_path ( batch_webhook_id ) , data = data )


signature:
def delete ( self , batch_webhook_id ) :
    """Remove a batch webhook . Webhooks will no longer be sent to the given
 URL .
 : param batch _ webhook _ id : The unique id for the batch webhook .
 : type batch _ webhook _ id : : py : class : ` str `"""

implementation:
self . batch_webhook_id = batch_webhook_id
return self . _mc_client . _delete ( url = self . _build_path ( batch_webhook_id ) )


signature:
def all ( self , list_id , subscriber_hash , ** queryparams ) :
    """Get the last 50 events of a member ’ s activity on a specific list ,
 including opens , clicks , and unsubscribes .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
return self . _mc_client . _get ( url = self . _build_path ( list_id , 'members' , subscriber_hash , 'activity' ) , ** queryparams )


signature:
def create ( self , data ) :
    """Add a new store to your MailChimp account .
 Error checking on the currency code verifies that it is in the correct
 three - letter , all - caps format as specified by ISO 4217 but does not
 check that it is a valid code as the list of valid codes changes over
 time .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " list _ id " : string * ,
 " name " : string * ,
 " currency _ code " : string *"""

implementation:
if 'id' not in data :
    raise KeyError ( 'The store must have an id' )
if 'list_id' not in data :
    raise KeyError ( 'The store must have a list_id' )
if 'name' not in data :
    raise KeyError ( 'The store must have a name' )
if 'currency_code' not in data :
    raise KeyError ( 'The store must have a currency_code' )
if not re . match ( r"^[A-Z]{3}$" , data [ 'currency_code' ] ) :
    raise ValueError ( 'The currency_code must be a valid 3-letter ISO 4217 currency code' )
response = self . _mc_client . _post ( url = self . _build_path ( ) , data = data )
if response is not None :
    self . store_id = response [ 'id' ]
else :
    self . store_id = None
return response


signature:
def update ( self , store_id , data ) :
    """Update a store .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `"""

implementation:
self . store_id = store_id
return self . _mc_client . _patch ( url = self . _build_path ( store_id ) , data = data )


signature:
def create ( self , store_id , product_id , data ) :
    """Add a new image to the product .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param product _ id : The id for the product of a store .
 : type product _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " url " : string *"""

implementation:
self . store_id = store_id
self . product_id = product_id
if 'id' not in data :
    raise KeyError ( 'The product image must have an id' )
if 'title' not in data :
    raise KeyError ( 'The product image must have a url' )
response = self . _mc_client . _post ( url = self . _build_path ( store_id , 'products' , product_id , 'images' ) , data = data )
if response is not None :
    self . image_id = response [ 'id' ]
else :
    self . image_id = None
return response


signature:
def all ( self , store_id , product_id , get_all = False , ** queryparams ) :
    """Get information about a product ’ s images .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param product _ id : The id for the product of a store .
 : type product _ id : : py : class : ` str `
 : param get _ all : Should the query get all results
 : type get _ all : : py : class : ` bool `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]
 queryparams [ ' count ' ] = integer
 queryparams [ ' offset ' ] = integer"""

implementation:
self . store_id = store_id
self . product_id = product_id
self . image_id = None
if get_all :
    return self . _iterate ( url = self . _build_path ( store_id , 'products' , product_id , 'images' ) , ** queryparams )
else :
    return self . _mc_client . _post ( url = self . _build_path ( store_id , 'products' , product_id , 'images' ) , ** queryparams )


signature:
def get ( self , store_id , product_id , image_id , ** queryparams ) :
    """Get information about a specific product image .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param product _ id : The id for the product of a store .
 : type product _ id : : py : class : ` str `
 : param image _ id : The id for the product image .
 : type image _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . store_id = store_id
self . product_id = product_id
self . image_id = image_id
return self . _mc_client . _post ( url = self . _build_path ( store_id , 'products' , product_id , 'images' , image_id ) , ** queryparams )


signature:
def create ( self , conversation_id , data ) :
    """Post a new message to a conversation .
 : param conversation _ id : The unique id for the conversation .
 : type conversation _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " from _ email " : string * ,
 " read " : boolean *"""

implementation:
self . conversation_id = conversation_id
if 'from_email' not in data :
    raise KeyError ( 'The conversation message must have a from_email' )
check_email ( data [ 'from_email' ] )
if 'read' not in data :
    raise KeyError ( 'The conversation message must have a read' )
if data [ 'read' ] not in [ True , False ] :
    raise TypeError ( 'The conversation message read must be True or False' )
response = self . _mc_client . _post ( url = self . _build_path ( conversation_id , 'messages' ) , data = data )
if response is not None :
    self . message_id = response [ 'id' ]
else :
    self . message_id = None
return response


signature:
def create ( self , store_id , data ) :
    """Add a new order to a store .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " id " : string * ,
 " customer " : object *
 " ' id " : string *
 " curency _ code " : string * ,
 " order _ total " : number * ,
 " lines " : array *
 " id " : string * ,
 " product _ id " : string * ,
 " product _ variant _ id " : string * ,
 " quantity " : integer * ,
 " price " : number *"""

implementation:
self . store_id = store_id
if 'id' not in data :
    raise KeyError ( 'The order must have an id' )
if 'customer' not in data :
    raise KeyError ( 'The order must have a customer' )
if 'id' not in data [ 'customer' ] :
    raise KeyError ( 'The order customer must have an id' )
if 'currency_code' not in data :
    raise KeyError ( 'The order must have a currency_code' )
if not re . match ( r"^[A-Z]{3}$" , data [ 'currency_code' ] ) :
    raise ValueError ( 'The currency_code must be a valid 3-letter ISO 4217 currency code' )
if 'order_total' not in data :
    raise KeyError ( 'The order must have an order_total' )
if 'lines' not in data :
    raise KeyError ( 'The order must have at least one order line' )
for line in data [ 'lines' ] :
    if 'id' not in line :
        raise KeyError ( 'Each order line must have an id' )
    if 'product_id' not in line :
        raise KeyError ( 'Each order line must have a product_id' )
    if 'product_variant_id' not in line :
        raise KeyError ( 'Each order line must have a product_variant_id' )
    if 'quantity' not in line :
        raise KeyError ( 'Each order line must have a quantity' )
    if 'price' not in line :
        raise KeyError ( 'Each order line must have a price' )
response = self . _mc_client . _post ( url = self . _build_path ( store_id , 'orders' ) , data = data )
if response is not None :
    self . order_id = response [ 'id' ]
else :
    self . order_id = None
return response


signature:
def create ( self , list_id , subscriber_hash , data ) :
    """Add a new note for a specific subscriber .
 The documentation lists only the note request body parameter so it is
 being documented and error - checked as if it were required based on the
 description of the method .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " note " : string *"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
if 'note' not in data :
    raise KeyError ( 'The list member note must have a note' )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'members' , subscriber_hash , 'notes' ) , data = data )
if response is not None :
    self . note_id = response [ 'id' ]
else :
    self . note_id = None
return response


signature:
def update ( self , list_id , subscriber_hash , data ) :
    """Update tags for a specific subscriber .
 The documentation lists only the tags request body parameter so it is
 being documented and error - checked as if it were required based on the
 description of the method .
 The data list needs to include a " status " key . This determines if the
 tag should be added or removed from the user :
 data = {
 ' tags ' : [
 { ' name ' : ' foo ' , ' status ' : ' active ' } ,
 { ' name ' : ' bar ' , ' status ' : ' inactive ' }
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " tags " : list *"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
if 'tags' not in data :
    raise KeyError ( 'The list member tags must have a tag' )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'members' , subscriber_hash , 'tags' ) , data = data )
return response


signature:
def update ( self , list_id , segment_id , data ) :
    """Update a specific segment in a list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param segment _ id : The unique id for the segment .
 : type segment _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string *"""

implementation:
self . list_id = list_id
self . segment_id = segment_id
if 'name' not in data :
    raise KeyError ( 'The list segment must have a name' )
return self . _mc_client . _patch ( url = self . _build_path ( list_id , 'segments' , segment_id ) , data = data )


signature:
def update_members ( self , list_id , segment_id , data ) :
    """Batch add / remove list members to static segment .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param segment _ id : The unique id for the segment .
 : type segment _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " members _ to _ add " : array ,
 " members _ to _ remove " : array"""

implementation:
self . list_id = list_id
self . segment_id = segment_id
return self . _mc_client . _post ( url = self . _build_path ( list_id , 'segments' , segment_id ) , data = data )


signature:
def create ( self , list_id , category_id , data ) :
    """Create a new interest or ‘ group name ’ for a specific category .
 The documentation lists only the name request body parameter so it is
 being documented and error - checked as if it were required based on the
 description of the method .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param category _ id : The unique id for the interest category .
 : type category _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string *"""

implementation:
self . list_id = list_id
self . category_id = category_id
if 'name' not in data :
    raise KeyError ( 'The list interest category interest must have a name' )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'interest-categories' , category_id , 'interests' ) , data = data )
if response is not None :
    self . interest_id = response [ 'id' ]
else :
    self . interest_id = None
return response


signature:
def update ( self , list_id , category_id , interest_id , data ) :
    """Update interests or ‘ group names ’ for a specific category .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param category _ id : The unique id for the interest category .
 : type category _ id : : py : class : ` str `
 : param interest _ id : The specific interest or ‘ group name ’ .
 : type interest _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string *"""

implementation:
self . list_id = list_id
self . category_id = category_id
self . interest_id = interest_id
if 'name' not in data :
    raise KeyError ( 'The list interest category interest must have a name' )
return self . _mc_client . _patch ( url = self . _build_path ( list_id , 'interest-categories' , category_id , 'interests' , interest_id ) , data = data )


signature:
def get ( self , list_id , month , ** queryparams ) :
    """Get a summary of a specific list ’ s growth activity for a specific month and year .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param month : A specific month of list growth history .
 : type month : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . list_id = list_id
self . month = month
return self . _mc_client . _get ( url = self . _build_path ( list_id , 'growth-history' , month ) , ** queryparams )


signature:
def update ( self , folder_id , data ) :
    """Update a specific folder used to organize templates .
 : param folder _ id : The unique id for the File Manager folder .
 : type folder _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " name " : string *"""

implementation:
if 'name' not in data :
    raise KeyError ( 'The template folder must have a name' )
self . folder_id = folder_id
return self . _mc_client . _patch ( url = self . _build_path ( folder_id ) , data = data )


signature:
def create ( self , list_id , data ) :
    """Add a new member to the list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " status " : string * , ( Must be one of ' subscribed ' , ' unsubscribed ' , ' cleaned ' ,
 ' pending ' , or ' transactional ' )
 " email _ address " : string *"""

implementation:
self . list_id = list_id
if 'status' not in data :
    raise KeyError ( 'The list member must have a status' )
if data [ 'status' ] not in [ 'subscribed' , 'unsubscribed' , 'cleaned' , 'pending' , 'transactional' ] :
    raise ValueError ( 'The list member status must be one of "subscribed", "unsubscribed", "cleaned", ' '"pending", or "transactional"' )
if 'email_address' not in data :
    raise KeyError ( 'The list member must have an email_address' )
check_email ( data [ 'email_address' ] )
response = self . _mc_client . _post ( url = self . _build_path ( list_id , 'members' ) , data = data )
if response is not None :
    self . subscriber_hash = response [ 'id' ]
else :
    self . subscriber_hash = None
return response


signature:
def update ( self , list_id , subscriber_hash , data ) :
    """Update information for a specific list member .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
return self . _mc_client . _patch ( url = self . _build_path ( list_id , 'members' , subscriber_hash ) , data = data )


signature:
def create_or_update ( self , list_id , subscriber_hash , data ) :
    """Add or update a list member .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " email _ address " : string * ,
 " status _ if _ new " : string * ( Must be one of ' subscribed ' ,
 ' unsubscribed ' , ' cleaned ' , ' pending ' , or ' transactional ' )"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
if 'email_address' not in data :
    raise KeyError ( 'The list member must have an email_address' )
check_email ( data [ 'email_address' ] )
if 'status_if_new' not in data :
    raise KeyError ( 'The list member must have a status_if_new' )
if data [ 'status_if_new' ] not in [ 'subscribed' , 'unsubscribed' , 'cleaned' , 'pending' , 'transactional' ] :
    raise ValueError ( 'The list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", ' '"pending", or "transactional"' )
return self . _mc_client . _put ( url = self . _build_path ( list_id , 'members' , subscriber_hash ) , data = data )


signature:
def delete ( self , list_id , subscriber_hash ) :
    """Delete a member from a list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
return self . _mc_client . _delete ( url = self . _build_path ( list_id , 'members' , subscriber_hash ) )


signature:
def delete_permanent ( self , list_id , subscriber_hash ) :
    """Delete permanently a member from a list .
 : param list _ id : The unique id for the list .
 : type list _ id : : py : class : ` str `
 : param subscriber _ hash : The MD5 hash of the lowercase version of the
 list member ’ s email address .
 : type subscriber _ hash : : py : class : ` str `"""

implementation:
subscriber_hash = check_subscriber_hash ( subscriber_hash )
self . list_id = list_id
self . subscriber_hash = subscriber_hash
return self . _mc_client . _post ( url = self . _build_path ( list_id , 'members' , subscriber_hash , 'actions' , 'delete-permanent' ) )


signature:
def get ( self , workflow_id , ** queryparams ) :
    """Get a summary of an individual Automation workflow ’ s settings and
 content . The trigger _ settings object returns information for the first
 email in the workflow .
 : param workflow _ id : The unique id for the Automation workflow
 : type workflow _ id : : py : class : ` str `
 : param queryparams : the query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . workflow_id = workflow_id
return self . _mc_client . _get ( url = self . _build_path ( workflow_id ) , ** queryparams )


signature:
def pause ( self , workflow_id , email_id ) :
    """Pause an automated email .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
return self . _mc_client . _post ( url = self . _build_path ( workflow_id , 'emails' , email_id , 'actions/pause' ) )


signature:
def start ( self , workflow_id , email_id ) :
    """Start an automated email .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
return self . _mc_client . _post ( url = self . _build_path ( workflow_id , 'emails' , email_id , 'actions/start' ) )


signature:
def delete ( self , workflow_id , email_id ) :
    """Removes an individual Automation workflow email .
 : param workflow _ id : The unique id for the Automation workflow .
 : type workflow _ id : : py : class : ` str `
 : param email _ id : The unique id for the Automation workflow email .
 : type email _ id : : py : class : ` str `"""

implementation:
self . workflow_id = workflow_id
self . email_id = email_id
return self . _mc_client . _delete ( url = self . _build_path ( workflow_id , 'emails' , email_id ) )


signature:
def create ( self , data ) :
    """Create a new MailChimp campaign .
 The ValueError raised by an invalid type in data does not mention
 ' absplit ' as a potential value because the documentation indicates
 that the absplit type has been deprecated .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " recipients " : object *
 " list _ id " : string *
 " settings " : object *
 " subject _ line " : string * ,
 " from _ name " : string * ,
 " reply _ to " : string *
 " variate _ settings " : object * ( Required if type is " variate " )
 " winner _ criteria " : string * ( Must be one of " opens " , " clicks " , " total _ revenue " , or " manual " )
 " rss _ opts " : object * ( Required if type is " rss " )
 " feed _ url " : string * ,
 " frequency " : string * ( Must be one of " daily " , " weekly " , or " monthly " )
 " type " : string * ( Must be one of " regular " , " plaintext " , " rss " , " variate " , or " absplit " )"""

implementation:
if 'recipients' not in data :
    raise KeyError ( 'The campaign must have recipients' )
if 'list_id' not in data [ 'recipients' ] :
    raise KeyError ( 'The campaign recipients must have a list_id' )
if 'settings' not in data :
    raise KeyError ( 'The campaign must have settings' )
if 'subject_line' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a subject_line' )
if 'from_name' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a from_name' )
if 'reply_to' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a reply_to' )
check_email ( data [ 'settings' ] [ 'reply_to' ] )
if 'type' not in data :
    raise KeyError ( 'The campaign must have a type' )
if not data [ 'type' ] in [ 'regular' , 'plaintext' , 'rss' , 'variate' , 'abspilt' ] :
    raise ValueError ( 'The campaign type must be one of "regular", "plaintext", "rss", or "variate"' )
if data [ 'type' ] == 'variate' :
    if 'variate_settings' not in data :
        raise KeyError ( 'The variate campaign must have variate_settings' )
    if 'winner_criteria' not in data [ 'variate_settings' ] :
        raise KeyError ( 'The campaign variate_settings must have a winner_criteria' )
    if data [ 'variate_settings' ] [ 'winner_criteria' ] not in [ 'opens' , 'clicks' , 'total_revenue' , 'manual' ] :
        raise ValueError ( 'The campaign variate_settings ' 'winner_criteria must be one of "opens", "clicks", "total_revenue", or "manual"' )
if data [ 'type' ] == 'rss' :
    if 'rss_opts' not in data :
        raise KeyError ( 'The rss campaign must have rss_opts' )
    if 'feed_url' not in data [ 'rss_opts' ] :
        raise KeyError ( 'The campaign rss_opts must have a feed_url' )
    if not data [ 'rss_opts' ] [ 'frequency' ] in [ 'daily' , 'weekly' , 'monthly' ] :
        raise ValueError ( 'The rss_opts frequency must be one of "daily", "weekly", or "monthly"' )
response = self . _mc_client . _post ( url = self . _build_path ( ) , data = data )
if response is not None :
    self . campaign_id = response [ 'id' ]
else :
    self . campaign_id = None
return response


signature:
def update ( self , campaign_id , data ) :
    """Update some or all of the settings for a specific campaign .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " settings " : object *
 " subject _ line " : string * ,
 " from _ name " : string * ,
 " reply _ to " : string *"""

implementation:
self . campaign_id = campaign_id
if 'settings' not in data :
    raise KeyError ( 'The campaign must have settings' )
if 'subject_line' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a subject_line' )
if 'from_name' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a from_name' )
if 'reply_to' not in data [ 'settings' ] :
    raise KeyError ( 'The campaign settings must have a reply_to' )
check_email ( data [ 'settings' ] [ 'reply_to' ] )
return self . _mc_client . _patch ( url = self . _build_path ( campaign_id ) , data = data )


signature:
def delete ( self , campaign_id ) :
    """Remove a campaign from your MailChimp account .
 : param campaign _ id : The unique id for the campaign .
 : type campaign _ id : : py : class : ` str `"""

implementation:
self . campaign_id = campaign_id
return self . _mc_client . _delete ( url = self . _build_path ( campaign_id ) )


signature:
def delete ( self , store_id , cart_id , line_id ) :
    """Delete a cart .
 : param store _ id : The store id .
 : type store _ id : : py : class : ` str `
 : param cart _ id : The id for the cart .
 : type cart _ id : : py : class : ` str `
 : param line _ id : The id for the line item of a cart .
 : type line _ id : : py : class : ` str `"""

implementation:
self . store_id = store_id
self . cart_id = cart_id
self . line_id = line_id
return self . _mc_client . _delete ( url = self . _build_path ( store_id , 'carts' , cart_id , 'lines' , line_id ) )


signature:
def create ( self , data ) :
    """Begin processing a batch operations request .
 : param data : The request body parameters
 : type data : : py : class : ` dict `
 data = {
 " operations " : array *
 " method " : string * ( Must be one of " GET " , " POST " , " PUT " , " PATCH " , or " DELETE " )
 " path " : string * ,"""

implementation:
if 'operations' not in data :
    raise KeyError ( 'The batch must have operations' )
for op in data [ 'operations' ] :
    if 'method' not in op :
        raise KeyError ( 'The batch operation must have a method' )
    if op [ 'method' ] not in [ 'GET' , 'POST' , 'PUT' , 'PATCH' , 'DELETE' ] :
        raise ValueError ( 'The batch operation method must be one of "GET", "POST", "PUT", "PATCH", ' 'or "DELETE", not {0}' . format ( op [ 'method' ] ) )
    if 'path' not in op :
        raise KeyError ( 'The batch operation must have a path' )
return self . _mc_client . _post ( url = self . _build_path ( ) , data = data )


signature:
def all ( self , get_all = False , ** queryparams ) :
    """Get a summary of batch requests that have been made .
 : param get _ all : Should the query get all results
 : type get _ all : : py : class : ` bool `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]
 queryparams [ ' count ' ] = integer
 queryparams [ ' offset ' ] = integer"""

implementation:
self . batch_id = None
self . operation_status = None
if get_all :
    return self . _iterate ( url = self . _build_path ( ) , ** queryparams )
else :
    return self . _mc_client . _get ( url = self . _build_path ( ) , ** queryparams )


signature:
def get ( self , batch_id , ** queryparams ) :
    """Get the status of a batch request .
 : param batch _ id : The unique id for the batch operation .
 : type batch _ id : : py : class : ` str `
 : param queryparams : The query string parameters
 queryparams [ ' fields ' ] = [ ]
 queryparams [ ' exclude _ fields ' ] = [ ]"""

implementation:
self . batch_id = batch_id
self . operation_status = None
return self . _mc_client . _get ( url = self . _build_path ( batch_id ) , ** queryparams )


signature:
def delete ( self , batch_id ) :
    """Stops a batch request from running . Since only one batch request is
 run at a time , this can be used to cancel a long running request . The
 results of any completed operations will not be available after this
 call .
 : param batch _ id : The unique id for the batch operation .
 : type batch _ id : : py : class : ` str `"""

implementation:
self . batch_id = batch_id
self . operation_status = None
return self . _mc_client . _delete ( url = self . _build_path ( batch_id ) )


signature:
def _reformat_policy ( policy ) :
    """Policies returned from boto3 are massive , ugly , and difficult to read .
 This method flattens and reformats the policy .
 : param policy : Result from invoking describe _ load _ balancer _ policies ( . . . )
 : return : Returns a tuple containing policy _ name and the reformatted policy dict ."""

implementation:
policy_name = policy [ 'PolicyName' ]
ret = { }
ret [ 'type' ] = policy [ 'PolicyTypeName' ]
attrs = policy [ 'PolicyAttributeDescriptions' ]
if ret [ 'type' ] != 'SSLNegotiationPolicyType' :
    return policy_name , ret
attributes = dict ( )
for attr in attrs :
    attributes [ attr [ 'AttributeName' ] ] = attr [ 'AttributeValue' ]
ret [ 'protocols' ] = dict ( )
ret [ 'protocols' ] [ 'sslv2' ] = bool ( attributes . get ( 'Protocol-SSLv2' ) )
ret [ 'protocols' ] [ 'sslv3' ] = bool ( attributes . get ( 'Protocol-SSLv3' ) )
ret [ 'protocols' ] [ 'tlsv1' ] = bool ( attributes . get ( 'Protocol-TLSv1' ) )
ret [ 'protocols' ] [ 'tlsv1_1' ] = bool ( attributes . get ( 'Protocol-TLSv1.1' ) )
ret [ 'protocols' ] [ 'tlsv1_2' ] = bool ( attributes . get ( 'Protocol-TLSv1.2' ) )
ret [ 'server_defined_cipher_order' ] = bool ( attributes . get ( 'Server-Defined-Cipher-Order' ) )
ret [ 'reference_security_policy' ] = attributes . get ( 'Reference-Security-Policy' , None )
non_ciphers = [ 'Server-Defined-Cipher-Order' , 'Protocol-SSLv2' , 'Protocol-SSLv3' , 'Protocol-TLSv1' , 'Protocol-TLSv1.1' , 'Protocol-TLSv1.2' , 'Reference-Security-Policy' ]
ciphers = [ ]
for cipher in attributes :
    if attributes [ cipher ] == 'true' and cipher not in non_ciphers :
        ciphers . append ( cipher )
ciphers . sort ( )
ret [ 'supported_ciphers' ] = ciphers
return policy_name , ret


signature:
def _flatten_listener ( listener ) :
    """from
 " Listener " : {
 " InstancePort " : 80,
 " LoadBalancerPort " : 80,
 " Protocol " : " HTTP " ,
 " InstanceProtocol " : " HTTP "
 " PolicyNames " : [ ]
 to
 " InstancePort " : 80,
 " LoadBalancerPort " : 80,
 " Protocol " : " HTTP " ,
 " InstanceProtocol " : " HTTP " ,
 " PolicyNames " : [ ]"""

implementation:
result = dict ( )
if set ( listener . keys ( ) ) == set ( [ 'Listener' , 'PolicyNames' ] ) :
    result . update ( listener [ 'Listener' ] )
    result [ 'PolicyNames' ] = listener [ 'PolicyNames' ]
else :
    result = dict ( listener )
return result


signature:
def get_load_balancer ( load_balancer , flags = FLAGS . ALL ^ FLAGS . POLICY_TYPES , ** conn ) :
    """Fully describes an ELB .
 : param loadbalancer : Could be an ELB Name or a dictionary . Likely the return value from a previous call to describe _ load _ balancers . At a minimum , must contain a key titled ' LoadBalancerName ' .
 : param flags : Flags describing which sections should be included in the return value . Default is FLAGS . ALL minus FLAGS . POLICY _ TYPES .
 : return : Returns a dictionary describing the ELB with the fields described in the flags parameter ."""

implementation:
# Python 2 and 3 support :
try :
    basestring
except NameError as _ :
    basestring = str
if isinstance ( load_balancer , basestring ) :
    load_balancer = dict ( LoadBalancerName = load_balancer )
return registry . build_out ( flags , start_with = load_balancer , pass_datastructure = True , ** conn )


signature:
def get ( self , key , delete_if_expired = True ) :
    """Retrieve key from Cache .
 : param key : key to look up in cache .
 : type key : ` ` object ` `
 : param delete _ if _ expired : remove value from cache if it is expired .
 Default is True .
 : type delete _ if _ expired : ` ` bool ` `
 : returns : value from cache or None
 : rtype : varies or None"""

implementation:
self . _update_cache_stats ( key , None )
if key in self . _CACHE :
    ( expiration , obj ) = self . _CACHE [ key ]
    if expiration > self . _now ( ) :
        self . _update_cache_stats ( key , 'hit' )
        return obj
    else :
        if delete_if_expired :
            self . delete ( key )
            self . _update_cache_stats ( key , 'expired' )
            return None
self . _update_cache_stats ( key , 'miss' )
return None


signature:
def insert ( self , key , obj , future_expiration_minutes = 15 ) :
    """Insert item into cache .
 : param key : key to look up in cache .
 : type key : ` ` object ` `
 : param obj : item to store in cache .
 : type obj : varies
 : param future _ expiration _ minutes : number of minutes item is valid
 : type param : ` ` int ` `
 : returns : True
 : rtype : ` ` bool ` `"""

implementation:
expiration_time = self . _calculate_expiration ( future_expiration_minutes )
self . _CACHE [ key ] = ( expiration_time , obj )
return True


signature:
def _update_cache_stats ( self , key , result ) :
    """Update the cache stats .
 If no cache - result is specified , we iniitialize the key .
 Otherwise , we increment the correct cache - result .
 Note the behavior for expired . A client can be expired and the key
 still exists ."""

implementation:
if result is None :
    self . _CACHE_STATS [ 'access_stats' ] . setdefault ( key , { 'hit' : 0 , 'miss' : 0 , 'expired' : 0 } )
else :
    self . _CACHE_STATS [ 'access_stats' ] [ key ] [ result ] += 1


signature:
def get_access_details ( self , key = None ) :
    """Get access details in cache ."""

implementation:
if key in self . _CACHE_STATS :
    return self . _CACHE_STATS [ 'access_stats' ] [ key ]
else :
    return self . _CACHE_STATS [ 'access_stats' ]


signature:
def get_stats ( self ) :
    """Get general stats for the cache ."""

implementation:
expired = sum ( [ x [ 'expired' ] for _ , x in self . _CACHE_STATS [ 'access_stats' ] . items ( ) ] )
miss = sum ( [ x [ 'miss' ] for _ , x in self . _CACHE_STATS [ 'access_stats' ] . items ( ) ] )
hit = sum ( [ x [ 'hit' ] for _ , x in self . _CACHE_STATS [ 'access_stats' ] . items ( ) ] )
return { 'totals' : { 'keys' : len ( self . _CACHE_STATS [ 'access_stats' ] ) , 'expired' : expired , 'miss' : miss , 'hit' : hit , } }


signature:
def get_security_group ( sg_obj , flags = FLAGS . ALL , ** conn ) :
    """Orchestrates calls to build a Security Group in the following format :
 " Description " : . . . ,
 " GroupName " : . . . ,
 " IpPermissions " . . . ,
 " OwnerId " . . . ,
 " GroupId " . . . ,
 " IpPermissionsEgress " . . . ,
 " VpcId " . . .
 Args :
 sg _ obj : name , ARN , or dict of Security Group
 flags : Flags describing which sections should be included in the return value . Default ALL
 Returns :
 dictionary describing the requested Security Group"""

implementation:
if isinstance ( sg_obj , string_types ) :
    group_arn = ARN ( sg_obj )
    if group_arn . error :
        sg_obj = { 'GroupId' : sg_obj }
    else :
        sg_obj = { 'GroupId' : group_arn . parsed_name }
return registry . build_out ( flags , sg_obj , ** conn )


signature:
def get_user ( user , flags = FLAGS . ALL , ** conn ) :
    """Orchestrates all the calls required to fully build out an IAM User in the following format :
 " Arn " : . . . ,
 " AccessKeys " : . . . ,
 " CreateDate " : . . . , # str
 " InlinePolicies " : . . . ,
 " ManagedPolicies " : . . . ,
 " MFADevices " : . . . ,
 " Path " : . . . ,
 " UserId " : . . . ,
 " UserName " : . . . ,
 " SigningCerts " : . . .
 : param user : dict MUST contain the UserName and also a combination of either the ARN or the account _ number
 : param output : Determines whether keys should be returned camelized or underscored .
 : param conn : dict containing enough information to make a connection to the desired account .
 Must at least have ' assume _ role ' key .
 : return : dict containing fully built out user ."""

implementation:
user = modify ( user , output = 'camelized' )
_conn_from_args ( user , conn )
return registry . build_out ( flags , start_with = user , pass_datastructure = True , ** conn )


signature:
def get_all_users ( flags = FLAGS . ACCESS_KEYS | FLAGS . MFA_DEVICES | FLAGS . LOGIN_PROFILE | FLAGS . SIGNING_CERTIFICATES , ** conn ) :
    """Returns a list of Users represented as dictionary below :
 " Arn " : . . . ,
 " AccessKeys " : . . . ,
 " CreateDate " : . . . , # str
 " InlinePolicies " : . . . ,
 " ManagedPolicies " : . . . ,
 " MFADevices " : . . . ,
 " Path " : . . . ,
 " UserId " : . . . ,
 " UserName " : . . . ,
 " SigningCerts " : . . .
 : param flags :
 : param conn : dict containing enough information to make a connection to the desired account .
 : return : list of dicts containing fully built out user ."""

implementation:
users = [ ]
account_users = get_account_authorization_details ( 'User' , ** conn )
for user in account_users :
    temp_user = { 'Arn' : user [ 'Arn' ] , 'CreateDate' : get_iso_string ( user [ 'CreateDate' ] ) , 'GroupList' : user [ 'GroupList' ] , 'InlinePolicies' : user [ 'UserPolicyList' ] , 'ManagedPolicies' : [ { "name" : x [ 'PolicyName' ] , "arn" : x [ 'PolicyArn' ] } for x in user [ 'AttachedManagedPolicies' ] ] , 'Path' : user [ 'Path' ] , 'UserId' : user [ 'UserId' ] , 'UserName' : user [ 'UserName' ] }
    user = modify ( temp_user , output = 'camelized' )
    _conn_from_args ( user , conn )
    users . append ( registry . build_out ( flags , start_with = user , pass_datastructure = True , ** conn ) )
return users


signature:
def get_vpc_flow_logs ( vpc , ** conn ) :
    """Gets the VPC Flow Logs for a VPC"""

implementation:
fl_result = describe_flow_logs ( Filters = [ { "Name" : "resource-id" , "Values" : [ vpc [ "id" ] ] } ] , ** conn )
fl_ids = [ ]
for fl in fl_result :
    fl_ids . append ( fl [ "FlowLogId" ] )
return fl_ids


signature:
def get_classic_link ( vpc , ** conn ) :
    """Gets the Classic Link details about a VPC"""

implementation:
result = { }
try :
    cl_result = describe_vpc_classic_link ( VpcIds = [ vpc [ "id" ] ] , ** conn ) [ 0 ]
    result [ "Enabled" ] = cl_result [ "ClassicLinkEnabled" ]
    # Check for DNS as well :
    dns_result = describe_vpc_classic_link_dns_support ( VpcIds = [ vpc [ "id" ] ] , ** conn ) [ 0 ]
    result [ "DnsEnabled" ] = dns_result [ "ClassicLinkDnsSupported" ]
except ClientError as e : # This is not supported for all regions .
    if 'UnsupportedOperation' not in str ( e ) :
        raise e
return result


signature:
def get_internet_gateway ( vpc , ** conn ) :
    """Gets the Internet Gateway details about a VPC"""

implementation:
result = { }
ig_result = describe_internet_gateways ( Filters = [ { "Name" : "attachment.vpc-id" , "Values" : [ vpc [ "id" ] ] } ] , ** conn )
if ig_result : # Only 1 IG can be attached to a VPC :
    result . update ( { "State" : ig_result [ 0 ] [ "Attachments" ] [ 0 ] [ "State" ] , "Id" : ig_result [ 0 ] [ "InternetGatewayId" ] , "Tags" : ig_result [ 0 ] . get ( "Tags" , [ ] ) } )
return result


signature:
def get_vpc_peering_connections ( vpc , ** conn ) :
    """Gets the Internet Gateway details about a VPC"""

implementation:
accepter_result = describe_vpc_peering_connections ( Filters = [ { "Name" : "accepter-vpc-info.vpc-id" , "Values" : [ vpc [ "id" ] ] } ] , ** conn )
requester_result = describe_vpc_peering_connections ( Filters = [ { "Name" : "requester-vpc-info.vpc-id" , "Values" : [ vpc [ "id" ] ] } ] , ** conn )
# Assuming that there will be no duplicates :
peer_ids = [ ]
for peering in accepter_result + requester_result :
    peer_ids . append ( peering [ "VpcPeeringConnectionId" ] )
return peer_ids


signature:
def get_subnets ( vpc , ** conn ) :
    """Gets the VPC Subnets"""

implementation:
subnets = describe_subnets ( Filters = [ { "Name" : "vpc-id" , "Values" : [ vpc [ "id" ] ] } ] , ** conn )
s_ids = [ ]
for s in subnets :
    s_ids . append ( s [ "SubnetId" ] )
return s_ids