0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ニフティクラウド mobile backendとやりとりするChoregrapheのboxを作成する

Last updated at Posted at 2016-11-06

準備するもの

いくつかライブラリをChoregrapheプロジェクトのlibフォルダ(なかったら作成)にコピーする必要があります

setup.ymlの用意

APIキーをメモしたsetup.ymlを、プロジェクト直下(manifest.xmlと同じところ)に配置

APPLICATION_KEY: YOUR_APP_KEY
CLIENT_KEY: YOUR_CLIENT_KEY

プロジェクトのファイル構成は以下のようになります
pj_structure.png

pythonのboxを作成

以下のサンプルコードでは、postメソッドを利用してデータをmobile backendに送信しています。
実行したあとにmobile backendのダッシュボードを開いて、データが保存されているか確認してください。

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        self.framemanager = ALProxy("ALFrameManager")
        self.folderName = None

    def onUnload(self):
        import sys
        if self.folderName and self.folderName in sys.path:
            sys.path.remove(self.folderName)
        self.folderName = None

    def onInput_onStart(self):
        import sys, os
        self.folderName = os.path.join(self.framemanager.getBehaviorPath(self.behaviorId), "../lib")
        if self.folderName not in sys.path:
            sys.path.append(self.folderName)
        #import
        from py_nifty_cloud.nifty_cloud_request import NiftyCloudRequest
        
        # instanciate with yaml file contains APPLICATION KEY and CLIENT KEY
        ncr = NiftyCloudRequest(os.path.join(self.framemanager.getBehaviorPath(self.behaviorId), "../setup.yml"))
        path = '/classes/TestClass'
        method = 'POST'
        
        # post a new recode
        values = {'key': 'test'}
        response = ncr.post(path=path, query=values)
        print(response.status_code)


    def onInput_onStop(self):
        self.onUnload()
        self.onStopped()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?