def get(self):
        # クライアントIDを取得する
        clientId = self.request.get("clientId")
        helper = PictureHelper()
        helper.connect_picture(clientId)

        # トークンを生成する
        token = channel.create_channel(clientId)

        # JSONの形にして返す
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(token)
    def _get_picture(self, path):
        # /initstrokes/<id>の形式で入ってくる
        splitPath = path.split('/')

        helper = PictureHelper()
        if len(splitPath) < 3:
            # IDがない場合、指定された履歴の情報を取得する
            return helper.get_picture()

        else:
            # 指定された履歴の情報を取得する
            return helper.get_picture_by_id(splitPath[2])
    def post(self):
        # 新しい絵を作成する。前の絵がなければ、そのまま終わる
        helper = PictureHelper()
        picture = helper.create_new_picture()
        if picture == None:
            return

        # 前の絵を描いていたクライアントに、再読み込みの指示を送信する
        clientIds = picture.clientIds
        cmd = Command('newpicture', None)
        message = json.dumps(cmd, ensure_ascii=False, cls=ComplexEncoder)

        # 接続中のクライアントに、1つずつ送信する
        for targetId in clientIds:
            channel.send_message(targetId, message)
    def get(self):
        # 過去の絵の履歴を取得して、Historyクラスとして保存する
        histories = []

        helper = PictureHelper()
        pictures = helper.get_histories()
        for picture in pictures:
            id = picture.key().id()
            createDate = picture.createDate
            histories.append(History(id, createDate))


        # JSONで返す
        encoded = json.dumps(histories, ensure_ascii=False, cls=ComplexEncoder)
        self.response.headers['Content-Type'] = 'application/json;  charset=utf-8'
        self.response.out.write(encoded)
    def post(self):
        
        clientId = self.request.get('clientId')
        stroke = self.request.get('stroke')

        # 描画情報を登録する
        helper = PictureHelper()
        picture = helper.add_stroke(stroke)


        # 描画情報をチャネルサービスに送信する
        clientIds = picture.clientIds
        cmd = Command('addstroke', stroke)
        message = json.dumps(cmd, ensure_ascii=False, cls=ComplexEncoder)


        # 接続中のクライアントに、1つずつ送信する
        for targetId in clientIds:
            # 自分自身は除く
            if targetId == clientId:
                continue

            channel.send_message(targetId, message)