|
1 # Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net> |
|
2 # |
|
3 # This file is part of Iro. |
|
4 # |
|
5 # Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
6 # this software and associated documentation files (the "Software"), to deal in |
|
7 # the Software without restriction, including without limitation the rights to use, |
|
8 # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
|
9 # #Software, and to permit persons to whom the Software is furnished to do so, |
|
10 # subject to the following conditions: |
|
11 # |
|
12 # The above copyright notice and this permission notice shall be included in |
|
13 # all copies or substantial portions of the Software. |
|
14 # |
|
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
16 # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
|
17 # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
|
22 class Offer(): |
|
23 """One Offer for sending. |
|
24 This class is used to send a message via a provider. |
|
25 """ |
|
26 def __init__(self, name, provider, route, typ): |
|
27 """ Constructor for Offer class. |
|
28 |
|
29 :param string name: name is the name in database for the offer |
|
30 :param `iro.offer.provider.Provider` provider: A valid provider object. |
|
31 :param sting route: used to the the right send function via :meth:`iro.offer.provider.Provider.getSendFunc`. |
|
32 :param sting typ: used to the the right send function via :meth:`iro.offer.provider.Provider.getSendFunc`. |
|
33 |
|
34 |
|
35 .. automethod:: __call__ |
|
36 .. automethod:: __eq__ |
|
37 .. automethod:: __neq__ |
|
38 .. automethod:: __repr__ |
|
39 """ |
|
40 self.name = name |
|
41 self.route = route |
|
42 self.provider = provider |
|
43 self.typ = typ |
|
44 self.sendfunc = provider.getSendFunc(typ, route) |
|
45 |
|
46 def __call__(self, recipient, message): |
|
47 """send a message to a recipient. This method uses :meth:`iro.offer.provider.Provider.send` |
|
48 |
|
49 :param recipient: one recipient |
|
50 :param `iro.model.message.Message` message: message to send |
|
51 """ |
|
52 return self.sendfunc(recipient, message) |
|
53 |
|
54 def __eq__(self,o): |
|
55 """return ``True``, if o is equal.""" |
|
56 return (self.name == o.name) and (self.route == o.route) and (self.provider == o.provider) and (self.typ == o.typ) |
|
57 |
|
58 def __neq__(self,o): |
|
59 """return ``True``, if ``o`` is not equal (see :meth:`__eq__`).""" |
|
60 return not self.__eq__(o) |
|
61 |
|
62 def __repr__(self): |
|
63 """string representation of this class for debugging purpose. |
|
64 |
|
65 :return: ``<Offer(name, provider, route, typ)>`` """ |
|
66 return "<Offer(%s, %s, %s, %s)>"%(self.name,self.provider,self.route,self.typ) |
|
67 |