RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
Payload.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 # Copyright 2016 RAPP
5 
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 
18 # Authors: Konstantinos Panayiotou
19 # contact: klpanagi@gmail.com
20 
21 
22 ## @file Objects/Payload.py
23 #
24 # @copyright Rapp Projecty EU 2016
25 # @author Konstantinos Panayiotou, [klpanagi@gmail.com]
26 #
27 
28 import json
29 
30 class Payload(object):
31  """ Payload object class """
32  def __init__(self, **kwargs):
33  for key, value in kwargs.iteritems():
34  setattr(self, key, value)
35 
36 
37  def __eq__(self, other):
38  """! Equality method """
39  return self.serialize() == other.serialize()
40 
41 
42  def append(self, **kwargs):
43  """! Append key-value pairs to the request payload.
44 
45  @param **kwargs - Keyword arguments. Key-Value pairs to append to the
46  payload.
47  """
48  for key, value in kwargs.iteritems():
49  setattr(self, key, value)
50 
51 
52  def remove(self, toDelAttr):
53  """! Remove payload properties
54 
55  @param toDelAttr (Array) - Array of Strings for properties to remove from
56  the payload.
57  """
58  for key in kwargs.iteritems():
59  delattr(self, key)
60 
61 
62  def serialize(self):
63  """! Serialize to Dictionary
64 
65  @return dictionary - Request Payload dictionary.
66  """
67  return { k:v for k,v in vars(self).items() if not k.startswith('_') or callable(v) }
68 
69 
70  def make_json(self):
71  """! Serialize to Dictionary and create a json string
72 
73  @return json - Request Payload json string.
74  """
75  return json.dumps(self.serialize())
76 
def make_json
Serialize to Dictionary and create a json string.
Definition: Payload.py:70
def append
Append key-value pairs to the request payload.
Definition: Payload.py:42
def serialize
Serialize to Dictionary.
Definition: Payload.py:62
def __eq__
Equality method.
Definition: Payload.py:37
def remove
Remove payload properties.
Definition: Payload.py:52