コード例 #1
0
ファイル: client.py プロジェクト: MacHu-GWU/pyknackhq-project
    def crud_basic_test():
        client =  KnackhqClient(
            auth=KnackhqAuth.from_json(AUTH_JSON_PATH),
            application=Application.from_json(SCHEMA_JSON_PATH),
        )
        short_text_object = client.get_collection("short_text_object")
        
        # delete all, initialize database
        short_text_object.delete_all()
         
        # insert one record
        record = {"short text field": "word1"}
        res = short_text_object.insert_one(record)
         
        # insert two records
        records = [{"short text field": "word2"}, {"short text field": "word3"}]
        short_text_object.insert(records)
        
        # find all
        res = short_text_object.find()
        
        # update
        new_record = {"short text field": "Hello World"}
        res = short_text_object.update_one(res[0]["id"], new_record)
        
        # find one
        res = short_text_object.find_one(res["id"])
        
#     crud_basic_test()
コード例 #2
0
    def crud_basic_test():
        client = KnackhqClient(
            auth=KnackhqAuth.from_json(AUTH_JSON_PATH),
            application=Application.from_json(SCHEMA_JSON_PATH),
        )
        short_text_object = client.get_collection("short_text_object")

        # delete all, initialize database
        short_text_object.delete_all()

        # insert one record
        record = {"short text field": "word1"}
        res = short_text_object.insert_one(record)

        # insert two records
        records = [{
            "short text field": "word2"
        }, {
            "short text field": "word3"
        }]
        short_text_object.insert(records)

        # find all
        res = short_text_object.find()

        # update
        new_record = {"short text field": "Hello World"}
        res = short_text_object.update_one(res[0]["id"], new_record)

        # find one
        res = short_text_object.find_one(res["id"])


#     crud_basic_test()
コード例 #3
0
 def __init__(self, auth, application=None):
     self.auth = auth
     if isinstance(application, Application):
         self.application = application
     else:  # get the schema json, construct Application instance
         res = requests.get("https://api.knackhq.com/v1/applications/%s" %
                            self.auth.application_id)
         self.application = Application.from_dict(json.loads(res.text))
コード例 #4
0
ファイル: client.py プロジェクト: MacHu-GWU/pyknackhq-project
 def __init__(self, auth, application=None):
     self.auth = auth
     if isinstance(application, Application):
         self.application = application
     else: # get the schema json, construct Application instance
         res = requests.get(
             "https://api.knackhq.com/v1/applications/%s" % 
             self.auth.application_id)
         self.application = Application.from_dict(json.loads(res.text))
コード例 #5
0
    RatingType = RatingType
    
dtype = DataType()

if __name__ == "__main__":
    from pyknackhq.tests import AUTH_JSON_PATH, SCHEMA_JSON_PATH
    from pyknackhq.client import KnackhqAuth, KnackhqClient
    from pyknackhq.schema import Application
    from pyknackhq.js import prt_js
    from pprint import pprint as ppt
    import unittest
    
    # connect client    
    client =  KnackhqClient(
        auth=KnackhqAuth.from_json(AUTH_JSON_PATH),
        application=Application.from_json(SCHEMA_JSON_PATH),
    )
    # get collection
    test_obj = client.get_collection("test_object")
    
    # basic type
    short_text_obj = client.get_collection("short_text_object")
    paragraph_text_obj = client.get_collection("paragraph_text_object")
    yes_no_obj = client.get_collection("yes_no_object")
    multi_choice_obj = client.get_collection("multiple_choice_object")
    date_time_obj = client.get_collection("date_time_object")
    from_to_obj = client.get_collection("date_time_from_to_object")
    number_obj = client.get_collection("number_object")
    image_obj = client.get_collection("image_object")
    file_obj = client.get_collection("file_object")