5 """This class represents a conversation.
8 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
._sessionget
('conversations/{1}.json'.format(self
.conv_id
))
30 if r
.status_code
== 200:
31 return r
.json()['conversation']
33 raise Exception('wrong status code: {0}'.format(r
.status_code
))
35 def answer(self
, text
):
36 """ answer that conversation
38 :param text: text to answer.
43 data
= {'message[text]': text
,
45 'authenticity_token': self
._client
.get_token()}
47 r
= self
._client
._sessionpost
('conversations/{}/messages'.format(self
.conv_id
),
49 headers
={'accept': 'application/json'})
50 if r
.status_code
!= 200:
51 raise Exception('{0}: Answer could not be posted.'
52 .format(r
.status_code
))
56 """ delete this conversation
59 data
= {'authenticity_token': self
._client
.get_token()}
61 r
= self
._client
._sessiondelete
('conversations/{0}/visibility/'
62 .format(self
.conv_id
),
64 headers
={'accept': 'application/json'})
66 if r
.status_code
!= 404:
67 raise Exception('{0}: Conversation could not be deleted.'
68 .format(r
.status_code
))
70 def get_subject(self
):
71 """ return the subject of this conversation
73 return self
.get_data()['subject']