def update(self, data, as_json=False, **identifier): """Update single subscriber. https://developers.mailerlite.com/v2/reference#update-subscriber Parameters ---------- data : dict subscriber object. only the email is required. you can use the following example: data = {'name' : 'John', 'fields' : {'company': 'MailerLite'} } as_json : bool return result as json format identifier : str should be subscriber id or email. e.g: id=1343965485 or email='*****@*****.**' Returns ------- response : int response value content : dict The JSON output from the API Notes ----- The email of a subscriber can not be updated """ path = get_id_or_email_identifier(**identifier) if path is None: raise IOError('An identifier must be define') if 'email' in data.keys(): raise ValueError("Subscriber email can not be updated. Please, " "remove this field or create a new Subscriber. " "For more informations, look at " "http://help.mailerlite.com/article/show" "/29233-how-to-edit-a-subscribers-data") optional_keys = ['name', 'type', 'fields', 'resend_autoresponders'] unknown_keys = [ d for d in data.keys() if d not in optional_keys if d not in ['groups', 'segments'] ] if unknown_keys: raise ValueError( "The following keys are unknown: {}".format(unknown_keys)) url = client.build_url('subscribers', path) res_code, res_json = client.put(url, body=data, headers=self.headers) if not res_json: return False res_json['fields'] = [Field(**res) for res in res_json['fields']] return Subscriber(**res_json)
def update(self, field_id, title, as_json=False): """Update custom field in account. https://developers.mailerlite.com/v2/reference#update-field Parameters ---------- field_id : int field id title : str Title of field Returns ------- field : :class:Field field object updated """ url = client.build_url('fields', field_id) body = {"title": title} res_code, res_json = client.put(url, body=body, headers=self.headers) if as_json or not res_json: return res_json return Field(**res_json)
def update(self, group_id, name, as_json=False): """Update existing group. https://developers.mailerlite.com/v2/reference#rename-group Parameters ---------- group_id : int group that you want to rename name : str group name as_json : bool return result as json format Returns ------- group: :class:Group group object """ url = client.build_url('groups', group_id) body = { "name": name, } _, res_json = client.put(url, body=body, headers=self.headers) if as_json or not res_json: return as_json return Group(**res_json)
def update(self, campaign_id, html, plain, auto_inline=True): r"""Upload your HTML template to created campaign. https://developers.mailerlite.com/v2/reference#put-custom-content-to-campaign Parameters ---------- campaign_id : int the campaign id that you want to update html : str HTML template source plain : str Plain text of email auto_inline : bool, optional Defines if it is needed to convert available CSS to inline CSS (excluding media queries) Returns ------- success : bool Examples -------- >>> from mailerlite import MailerLiteApi >>> api = MailerLiteApi('my_keys') >>> html = '<head></head><body><h1>Title</h1><p>Content</p><p><small>' >>> html += '<a href=\"{$unsubscribe}\">Unsubscribe</a></small></p>' >>> html += '</body>' >>> plain = "Your email client does not support HTML emails. " >>> plain += "Open newsletter here: {$url}. If you do not want" >>> plain += " to receive emails from us, click here: {$unsubscribe}" >>> api.campaigns.update(campaign_id, html=html, plain=plain) True Notes ----- * HTML template must contain body and head tag. * HTML template must contain a link for unsubscribe. It may look like this: <a href="{$unsubscribe}">Unsubscribe</a> * Some email clients do not support HTML emails so you need to set plain text email and it must contain these variables: * {$unsubscribe} - unsubscribe link * {$url} - URL to your HTML newsletter """ url = client.build_url('campaigns', campaign_id, 'content') # Todo, Check html syntax body = {"html": html, "plain": plain} _, res_json = client.put(url, body=body, headers=self.headers) if not res_json: return False return res_json['success']
def update(self, webhook_id, url, event): """Update webhook. https://developers.mailerlite.com/v2/reference#update-a-webhook Parameters ---------- webhook_id : int ID of a webhook url : str Your URL where callbacks are sent event : str Subscribed event Returns ------- field : :class:Field field object updated """ url = client.build_url('webhooks', webhook_id) body = {"url": url, 'event': event} _, res_json = client.put(url, body=body, headers=self.headers) return res_json