Skip to content

Commit

Permalink
Merge d069f27 into 8c66e8a
Browse files Browse the repository at this point in the history
  • Loading branch information
hamano committed Jan 9, 2016
2 parents 8c66e8a + d069f27 commit 02badb6
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
78 changes: 77 additions & 1 deletion src/pyejabberd/client.py
Expand Up @@ -196,6 +196,20 @@ def check_password_hash(self, user, host, password):
"""
return self._call_api(definitions.CheckPasswordHash, user=user, host=host, password=password)

def check_password(self, user, host, password):
"""
Check if a password is correct.
:param user: The username for the user we want to check the password for
:type user: str|unicode
:param host: The XMPP_DOMAIN
:type host: str|unicode
:param password: The password we want to check for the user
:type password: str|unicode
:rtype: bool
:return: A boolean indicating if the given password matches the user's password
"""
return self._call_api(definitions.CheckPassword, user=user, host=host, password=password)

def set_nickname(self, user, host, nickname):
"""
Set nickname in a user's vCard
Expand Down Expand Up @@ -395,6 +409,67 @@ def get_roster(self, user, host):
"""
return self._call_api(definitions.GetRoster, user=user, host=host)

def stats(self, name):
"""
Get statistical value
:param name: registeredusers onlineusers onlineusersnode uptimeseconds
:type name: str|unicode
:rtype: int
:return: statistical value
"""
return self._call_api(definitions.Stats, name=name)

def stats_host(self, name, host):
"""
Get statistical value for this host
:param name: registeredusers onlineusers onlineusersnode uptimeseconds
:type name: str|unicode
:param host: The XMPP_DOMAIN
:type host: str|unicode
:rtype: int
:return: statistical value
"""
return self._call_api(definitions.StatsHost, name=name, host=host)

def send_message(self, type, _from, to, subject, body):
"""
Send a message to a local or remote bare of full JID
:param type: chat | headline | normal
:type type: str|unicode
:param _from: from JID
:type _from: str|unicode
:param to: to JID
:type to: str|unicode
:param subject: message subject
:type subject: str|unicode
:param body: message body
:type body: str|unicode
:rtype: int
:return: result code
"""
return self._call_api(definitions.SendMessage,
type=type, _from=_from, to=to,
subject=subject, body=body)

def privacy_set(self, user, host, xmlquery):
"""
Send a IQ set privacy stanza for a local account
:param user: The Username
:type user: str|unicode
:param host: The XMPP_DOMAIN
:type host: str|unicode
:param xmlquery: xmlquery
:type xmlquery: str|unicode
:rtype: int
:return: responce code
"""
return self._call_api(definitions.PrivacySet,
user=user, host=host, xmlquery=xmlquery)

def _validate_and_serialize_arguments(self, api, arguments):
"""
Internal method to validate and serialize arguments
Expand All @@ -416,7 +491,8 @@ def _validate_and_serialize_arguments(self, api, arguments):
raise IllegalArgumentError('Missing required argument "%s"' % argument_name)

# Serializer argument value
serialized_arguments[argument_descriptor.name] = \
# we need lstrip underscore for special argument: _from
serialized_arguments[argument_descriptor.name.lstrip('_')] = \
argument_descriptor.serializer_class().to_api(arguments.get(argument_name))

return serialized_arguments
Expand Down
37 changes: 37 additions & 0 deletions src/pyejabberd/definitions.py
Expand Up @@ -74,6 +74,12 @@ def transform_arguments(self, **kwargs):
def transform_response(self, api, arguments, response):
return response.get('res') == 0

class CheckPassword(API):
method = 'check_password'
arguments = [StringArgument('user'), StringArgument('host'), StringArgument('password')]

def transform_response(self, api, arguments, response):
return response.get('res') == 0

class SetNickname(API):
method = 'set_nickname'
Expand Down Expand Up @@ -227,3 +233,34 @@ def transform_response(self, api, arguments, response):
contact_details[key] = value
roster.append(contact_details)
return roster

class Stats(API):
method = 'stats'
arguments = [StringArgument('name')]

def transform_response(self, api, arguments, response):
return response.get('stat')

class StatsHost(API):
method = 'stats_host'
arguments = [StringArgument('name'), StringArgument('host')]

def transform_response(self, api, arguments, response):
return response.get('stat')

class SendMessage(API):
method = 'send_message'
arguments = [StringArgument('type'),
StringArgument('_from'), StringArgument('to'),
StringArgument('subject'), StringArgument('body')]

def transform_response(self, api, arguments, response):
return response.get('res')

class PrivacySet(API):
method = 'privacy_set'
arguments = [StringArgument('user'), StringArgument('host'),
StringArgument('xmlquery')]

def transform_response(self, api, arguments, response):
return response.get('res')

0 comments on commit 02badb6

Please sign in to comment.