On Tue, Nov 04, 2014 at 11:11:53AM -0800, Shahab Sharifzadeh wrote:
>    Thanks...
>    I want to create a ticket with attachment...(callervoice.gsm)
>    But according to my search in web I can not use from Rest because when I
>    create ticket, the attach file was not sent with them...


You need to first create the ticket by rest and retrieve the user Id, then add
a correspondance or comment by rest including your gsm file as attachments. See
sample python code used here attached to this email.



-- 
Easter-eggs                              Spécialiste GNU/Linux
44-46 rue de l'Ouest  -  75014 Paris  -  France -  Métro Gaité
Phone: +33 (0) 1 43 35 00 37    -   Fax: +33 (0) 1 43 35 00 76
mailto:elac...@easter-eggs.com  -   http://www.easter-eggs.com
# peephone
#
# (c) 2009 - Julien Danjou <jdan...@easter-eggs.com>
#

import urllib, urllib2
from poster.encode import multipart_encode
from peephoneconfig import PeephoneConfig

class PeephoneRt:
    def __init__(self):
        config = PeephoneConfig()
        authinfo = urllib2.HTTPBasicAuthHandler()
        authinfo.add_password(realm='Ee',
                              uri=config.get('rt', 'url'),
                              user=config.get('rt', 'login'),
                              passwd=config.get('rt', 'password'))
        opener = urllib2.build_opener(authinfo)
        urllib2.install_opener(opener)

    def ticket_create(self, content):
        values = { 'content' : content }
        data = urllib.urlencode(values)
        req = urllib2.Request("%s/REST/1.0/ticket/new" % PeephoneConfig().get('rt', 'url'), data)
        return urllib2.urlopen(req)

    def ticket_get(self, tnumber):
        config = PeephoneConfig()
        f = urllib2.urlopen('%s/REST/1.0/ticket/%s/show' % (config.get('rt', 'url'), tnumber))
        line = f.readline()
        contents = {}
        while line:
            line = line.strip()
            i = line.find(": ")
            if i > 0:
                contents[line[:i]] = line[i + 2:]
            line = f.readline()
        return contents

    def ticket_edit(self, tnumber, field, value):
        config = PeephoneConfig()
        return urllib2.urlopen('%s/REST/1.0/ticket/%s/edit?content=%s:+%s' \
                                % (config.get('rt', 'url'), tnumber, field, value))

    def ticket_steal(self, tnumber):
        config = PeephoneConfig()
        values = { 'content' : "Action: Steal\nTicket: %s" % tnumber }
        data = urllib.urlencode(values)
        req = urllib2.Request("%s/REST/1.0/ticket/%s/take"
                              % (PeephoneConfig().get('rt', 'url'), tnumber),
                              data)
        return urllib2.urlopen(req)

    def ticket_comment(self, tnumber, comment="", attachment=None):
        config = PeephoneConfig()
        if attachment:
            values = { 'content': "Action: comment\nText: %s\nAttachment: %s" \
                           % (comment , attachment),
                       'attachment_1': file(attachment, "rb") }
        else:
            values = { 'content': "Action: comment\nText: %s" % comment }
        datagen, headers = multipart_encode(values)
        data = "".join(datagen)
        req = urllib2.Request("%s/REST/1.0/ticket/%d/comment" % \
                                  (PeephoneConfig().get('rt', 'url'), int(tnumber)),
                              data, headers)
        return urllib2.urlopen(req)

Reply via email to