Source code for iro.offer.offer
# Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
#
# This file is part of Iro.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# #Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[docs]class Offer():
"""One Offer for sending.
This class is used to send a message via a provider.
"""
def __init__(self, name, provider, route, typ):
""" Constructor for Offer class.
:param string name: name is the name in database for the offer
:param `iro.offer.provider.Provider` provider: A valid provider object.
:param sting route: used to the the right send function via :meth:`iro.offer.provider.Provider.getSendFunc`.
:param sting typ: used to the the right send function via :meth:`iro.offer.provider.Provider.getSendFunc`.
.. automethod:: __call__
.. automethod:: __eq__
.. automethod:: __neq__
.. automethod:: __repr__
"""
self.name = name
self.route = route
self.provider = provider
self.typ = typ
self.sendfunc = provider.getSendFunc(typ, route)
[docs] def __call__(self, recipient, message):
"""send a message to a recipient. This method uses :meth:`iro.offer.provider.Provider.send`
:param recipient: one recipient
:param `iro.model.message.Message` message: message to send
"""
return self.sendfunc(recipient, message)
[docs] def __eq__(self,o):
"""return ``True``, if o is equal."""
return (self.name == o.name) and (self.route == o.route) and (self.provider == o.provider) and (self.typ == o.typ)
[docs] def __neq__(self,o):
"""return ``True``, if ``o`` is not equal (see :meth:`__eq__`)."""
return not self.__eq__(o)
[docs] def __repr__(self):
"""string representation of this class for debugging purpose.
:return: ``<Offer(name, provider, route, typ)>`` """
return "<Offer(%s, %s, %s, %s)>"%(self.name,self.provider,self.route,self.typ)