add/remove contacts
This commit is contained in:
parent
878f095056
commit
2e0b1f1200
2 changed files with 27 additions and 2 deletions
|
@ -107,6 +107,12 @@ files = m.find('myfile.doc')
|
||||||
if files:
|
if files:
|
||||||
m.delete(files[0])
|
m.delete(files[0])
|
||||||
```
|
```
|
||||||
|
### Add/remove contacts
|
||||||
|
```python
|
||||||
|
m.add_contact('test@email.com')
|
||||||
|
m.remove_contact('test@email.com')
|
||||||
|
```
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
1. Python2.7+
|
1. Python2.7+
|
||||||
|
|
23
mega/mega.py
23
mega/mega.py
|
@ -642,12 +642,31 @@ class Mega(object):
|
||||||
"""
|
"""
|
||||||
Add another user to your mega contact list
|
Add another user to your mega contact list
|
||||||
"""
|
"""
|
||||||
|
return self._edit_contact(email, True)
|
||||||
|
|
||||||
|
def remove_contact(self, email):
|
||||||
|
"""
|
||||||
|
Remove a user to your mega contact list
|
||||||
|
"""
|
||||||
|
return self._edit_contact(email, False)
|
||||||
|
|
||||||
|
def _edit_contact(self, email, add):
|
||||||
|
"""
|
||||||
|
Editing contacts
|
||||||
|
"""
|
||||||
|
if add is True:
|
||||||
|
l = '1' # add command
|
||||||
|
elif add is False:
|
||||||
|
l = '0' # remove command
|
||||||
|
else:
|
||||||
|
raise ValidationError('add parameter must be of type bool')
|
||||||
|
|
||||||
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
|
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
|
||||||
ValidationError('add_contact requires a valid email address')
|
ValidationError('add_contact requires a valid email address')
|
||||||
else:
|
else:
|
||||||
return self.api_request({'a': 'ur',
|
return self.api_request({'a': 'ur',
|
||||||
'u': email,
|
'u': email,
|
||||||
'l': "1",
|
'l': l,
|
||||||
'i': self.request_id})
|
'i': self.request_id})
|
||||||
|
|
||||||
def get_contacts(self):
|
def get_contacts(self):
|
||||||
|
@ -660,7 +679,7 @@ class Mega(object):
|
||||||
|
|
||||||
#req = requests.post(
|
#req = requests.post(
|
||||||
#'{0}://g.api.{1}/sc'.format(self.schema, self.domain),
|
#'{0}://g.api.{1}/sc'.format(self.schema, self.domain),
|
||||||
# params={'sn': 'ilRTiY7r35I'},
|
# params={'sn': 'ZMxcQ_DmHnM', 'ssl': '1'},
|
||||||
# data=json.dumps(None),
|
# data=json.dumps(None),
|
||||||
# timeout=self.timeout)
|
# timeout=self.timeout)
|
||||||
#json_resp = json.loads(req.text)
|
#json_resp = json.loads(req.text)
|
||||||
|
|
Loading…
Reference in a new issue