2 """This class represents a conversation.
5 Remember that you need to have access to the conversation.
8 def __init__(self
, conv_id
, client
):
10 :param conv_id: id of the post and not the guid!
12 :param client: client object used to authenticate
13 :type client: client.Client
16 The login function of the client should be called,
17 before calling any of the post functions.
21 self
.conv_id
= conv_id
24 """ returns the plain json data representing conversation.
26 r
= self
._client
.session
.get('{0}/conversations/{1}.json'
27 .format(self
._client
.pod
, self
.conv_id
))
28 if r
.status_code
== 200:
29 return r
.json()['conversation']
31 raise Exception('wrong status code: {0}'.format(r
.status_code
))
33 def answer(self
, text
):
34 """ answer that conversation
36 :param text: text to answer.
41 data
= {'message[text]': text
,
43 'authenticity_token': self
._client
.get_token()}
45 r
= self
._client
.session
.post('{0}/conversations/{1}/messages'
46 .format(self
._client
.pod
, 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
))
56 """ delete this conversation
59 data
= {'authenticity_token': self
._client
.get_token()}
61 r
= self
._client
.session
.delete('{0}/conversations/{1}/visibility/'
62 .format(self
._client
.pod
,
65 headers
={'accept': 'application/json'})
67 if r
.status_code
!= 404:
68 raise Exception('{0}: Conversation could not be deleted.'
69 .format(r
.status_code
))
71 def get_subject(self
):
72 """ return the subject of this conversation
74 return self
.get_data()['subject']