def setUp(self) -> None:
        self.cookie_value = "foobar"
        self.cookie_expire_time = "Tue, 26-May-2020 14:37:56 GMT"

        self.authenticator = CouchDbSessionAuthenticator("adm", "pass")
        self.client = CloudantV1(self.authenticator)
        self.prepare_for_url('http://cloudant.example')
    def setUp(self):
        if not configLoaded:
            self.skipTest("External configuration not available, skipping...")

        self.cloudant = CloudantV1.new_instance(service_name='SERVER')
        self.db_name = os.environ.get('DATABASE_NAME', 'stores')
        self.assertIsNotNone(self.cloudant)
        self.assertIsNotNone(self.db_name)
示例#3
0
import json
import logging

from ibm_cloud_sdk_core import ApiException
from ibmcloudant.cloudant_v1 import CloudantV1

# Set logging level to show only critical logs
logging.basicConfig(level=logging.CRITICAL)

# 1. Create a client with `CLOUDANT` default service name ============
client = CloudantV1.new_instance()

# 2. Update the document =============================================
example_db_name = "orders"
example_doc_id = "example"

# Try to get the document if it previously existed in the database
try:
    document = client.get_document(db=example_db_name,
                                   doc_id=example_doc_id).get_result()

    #  Add Bob Smith's address to the document
    document["address"] = "19 Front Street, Darlington, DL5 1TY"

    #  Remove the joined property from document object
    if "joined" in document:
        document.pop("joined")

    # Update the document in the database
    update_document_response = client.post_document(
        db=example_db_name, document=document).get_result()
示例#4
0
# Constants for IBM COS values
COS_ENDPOINT = "https://manohar.s3.jp-tok.cloud-object-storage.appdomain.cloud"  # Current list avaiable at https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints
COS_API_KEY_ID = "67MBwu0H49L21goGQBII-SufzagQ-j-Lc-1xIRZOyqat"  # eg "W00YixxxxxxxxxxMB-odB-2ySfTrFBIQQWanc--P3byk"
COS_INSTANCE_CRN = "crn:v1:bluemix:public:cloud-object-storage:global:a/94a9058de7634a75b86a721e2524a404:9eaeda1b-4ff4-4fa1-94a8-9917e79c2fc3::"

# Create resource
cos = ibm_boto3.resource("s3",
                         ibm_api_key_id=COS_API_KEY_ID,
                         ibm_service_instance_id=COS_INSTANCE_CRN,
                         config=Config(signature_version="oauth"),
                         endpoint_url=COS_ENDPOINT)

authenticator = BasicAuthenticator(
    'apikey-v2-2y8twpk3cni02ngsc297oqatoulogdt961768upuw79q',
    '43c3fef46c4ca6560b7359d05c4c3d57')
service = CloudantV1(authenticator=authenticator)
service.set_service_url(
    'https://*****:*****@7b88ba8a-383b-49c5-ba00-9a03115de98a-bluemix.cloudantnosqldb.appdomain.cloud'
)


def myCommandCallback(cmd):
    print("Command received: %s" % cmd.data)


myConfig = {
    "identity": {
        "orgId": "sn7dm1",
        "typeId": "ESP32",
        "deviceId": "1234599"
    },
示例#5
0
import json

from ibmcloudant.cloudant_v1 import CloudantV1

# 1. Create a Cloudant client with "EXAMPLES" service name ============
client = CloudantV1.new_instance(service_name="EXAMPLES")

# 2. Get server information ===========================================
server_information = client.get_server_information().get_result()

print(f'Server Version: {server_information["version"]}')

# 3. Get database information for "animaldb" ==========================
db_name = "animaldb"

db_information = client.get_database_information(db=db_name).get_result()

# 4. Show document count in database ==================================
document_count = db_information["doc_count"]

print(f'Document count in \"{db_information["db_name"]}\" '
      f'database is {document_count}.')

# 5. Get zebra document out of the database by document id ============
document_about_zebra = client.get_document(db=db_name,
                                           doc_id="zebra").get_result()

print(f'Document retrieved from database:\n'
      f'{json.dumps(document_about_zebra, indent=2)}')
 def __init__(self):
     self.airport_service = CloudantV1.new_instance(service_name="AIRPORTS")
     self.airport_service.set_service_url('https://mikerhodes.cloudant.com')
     self.db_name = "airportdb"
     self.user_input = self.collect_user_input()
     self.query_data = self.collect_query_data()
def get_client(service_name):
    return CloudantV1.new_instance(service_name=service_name)