a05620a2057e3545e6c55739346c137e1a118629
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
.session
.post('{0}/conversations/{1}/messages'
48 .format(self
._client
.pod
, self
.conv_id
),
50 headers
={'accept': 'application/json'})
51 if r
.status_code
!= 200:
52 raise Exception('{0}: Answer could not be posted.'
53 .format(r
.status_code
))
58 """ delete this conversation
61 data
= {'authenticity_token': self
._client
.get_token()}
63 r
= self
._client
.session
.delete('{0}/conversations/{1}/visibility/'
64 .format(self
._client
.pod
,
67 headers
={'accept': 'application/json'})
69 if r
.status_code
!= 404:
70 raise Exception('{0}: Conversation could not be deleted.'
71 .format(r
.status_code
))
73 def get_subject(self
):
74 """ return the subject of this conversation
76 return self
.get_data()['subject']