4 """This class represents a conversation.
7 Remember that you need to have access to the conversation.
11 def __init__(self
, conv_id
, client
):
13 :param conv_id: id of the post and not the guid!
15 :param client: client object used to authenticate
16 :type client: client.Client
19 The login function of the client should be called,
20 before calling any of the post functions.
24 self
.conv_id
= conv_id
27 """ returns the plain json data representing conversation.
29 r
= self
._client
.session
.get(self
._client
.pod
+
33 if r
.status_code
== 200:
34 return r
.json()['conversation']
36 raise Exception('wrong status code: ' + str(r
.status_code
))
38 def answer(self
, text
):
39 """ answer that conversation
41 :param text: text to answer.
46 data
= {'message[text]': text
,
48 'authenticity_token': self
._client
.get_token()}
50 r
= self
._client
.session
.post(self
._client
.pod
+
55 headers
={'accept': 'application/json'})
56 if r
.status_code
!= 200:
57 raise Exception(str(r
.status_code
) +
58 ': Answer could not be posted.')
63 """ delete this conversation
66 data
= {'authenticity_token': self
._client
.get_token()}
68 r
= self
._client
.session
.delete(self
._client
.pod
+ '/conversations/' +
72 headers
={'accept': 'application/json'})
74 if r
.status_code
!= 404:
75 raise Exception(str(r
.status_code
) +
76 ': Conversation could not be deleted.')
78 def get_subject(self
):
79 """ return the subject of this conversation
81 return self
.get_data()['subject']