5 """This class represents a conversation.
8 Remember that you need to have access to the conversation.
10 def __init__(self
, conv_id
, connection
):
12 :param conv_id: id of the post and not the guid!
14 :param connection: connection object used to authenticate
15 :type connection: connection.Connection
18 The login function of the connection should be called,
19 before calling any of the post functions.
22 self
._connection
= connection
23 self
.conv_id
= conv_id
26 """ returns the plain json data representing conversation.
28 r
= self
._connection
.get('conversations/{1}.json'.format(self
.conv_id
))
29 if r
.status_code
== 200:
30 return r
.json()['conversation']
32 raise Exception('wrong status code: {0}'.format(r
.status_code
))
34 def answer(self
, text
):
35 """ answer that conversation
37 :param text: text to answer.
42 data
= {'message[text]': text
,
44 'authenticity_token': self
._connection
.get_token()}
46 r
= self
._connection
.post('conversations/{}/messages'.format(self
.conv_id
),
48 headers
={'accept': 'application/json'})
49 if r
.status_code
!= 200:
50 raise Exception('{0}: Answer could not be posted.'
51 .format(r
.status_code
))
55 """ delete this conversation
58 data
= {'authenticity_token': self
._connection
.get_token()}
60 r
= self
._connection
.delete('conversations/{0}/visibility/'
61 .format(self
.conv_id
),
63 headers
={'accept': 'application/json'})
65 if r
.status_code
!= 404:
66 raise Exception('{0}: Conversation could not be deleted.'
67 .format(r
.status_code
))
69 def get_subject(self
):
70 """ return the subject of this conversation
72 return self
.get_data()['subject']