Guest User

zoho python sdk persistance problem

a guest
Mar 29th, 2022
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.27 KB | None | 0 0
  1. from zcrmsdk.src.com.zoho.crm.api.user_signature import UserSignature
  2. from zcrmsdk.src.com.zoho.crm.api.dc import EUDataCenter
  3. from zcrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken
  4. from zcrmsdk.src.com.zoho.api.logger import Logger
  5. from zcrmsdk.src.com.zoho.api.authenticator.store import FileStore
  6. from zcrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig
  7. from zcrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy
  8. from zcrmsdk.src.com.zoho.crm.api.initializer import Initializer
  9. import os
  10. from zcrmsdk.src.com.zoho.crm.api.currencies import *
  11. from zcrmsdk.src.com.zoho.crm.api.currencies import Currency as ZCRMCurrency
  12. from zcrmsdk.src.com.zoho.crm.api.util import Choice
  13.  
  14. folder = os.path.dirname(__file__)
  15.  
  16. print("pyZohoDownloader is starting...")
  17. print("Initializing...")
  18. class SDKInitializer(object):
  19.  
  20.     @staticmethod
  21.     def initialize():
  22.  
  23.         # Create an UserSignature instance that takes user Email as parameter
  24.         user = UserSignature(email='[email protected]')
  25.  
  26.         """
  27.        Configure the environment
  28.        which is of the pattern Domain.Environment
  29.        Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
  30.        Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
  31.        """
  32.         environment = EUDataCenter.PRODUCTION()
  33.  
  34.         """
  35.        Create a Token instance that takes the following parameters
  36.        1 -> OAuth client id.
  37.        2 -> OAuth client secret.
  38.        3 -> Grant token.
  39.        4 -> Refresh token.
  40.        5 -> OAuth redirect URL. Default value is None
  41.        6 -> id
  42.        7 -> Access token
  43.        """
  44.         token = OAuthToken(client_id='1000.XXXXXXXXXXXXXXXXXXXX', client_secret='f0ab92XXXXXXXXXXXXXX', grant_token='1000.b19d2e526XXXXXXXX.XXXXXXXX', refresh_token='1000.d7d85ce7d1221aXXXXXXXXXXXXX.cf97c6ae90XXXXXXXXXXXXXXXX', redirect_url='http://holmer-maschinenbau.com', id='1', access_token='1000.5400326XXXXXXXXX.eafXXXXXXX')
  45.        
  46.         """
  47.        Create an instance of Logger Class that takes two parameters
  48.        1 -> Level of the log messages to be logged. Can be configured by typing Logger.Levels "." and choose any level from the list displayed.
  49.        2 -> Absolute file path, where messages need to be logged.
  50.        """
  51.         logger = Logger.get_instance(level=Logger.Levels.INFO, file_path=os.path.join(folder,'logs', "python_sdk_log.log"))
  52.  
  53.         """
  54.        DBStore takes the following parameters
  55.        1 -> DataBase host name. Default value "localhost"
  56.        2 -> DataBase name. Default value "zohooauth"
  57.        3 -> DataBase user name. Default value "root"
  58.        4 -> DataBase password. Default value ""
  59.        5 -> DataBase port number. Default value "3306"
  60.        6 -> DataBase table name. Default value "oauthtoken"
  61.        """
  62.         #store = DBStore()
  63.  
  64.         #store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name = "table_name")
  65.  
  66.         """
  67.        FileStore takes the following parameter
  68.        1 -> Absolute file path of the file to persist tokens
  69.        """
  70.         store = FileStore(file_path=os.path.join(folder,'python_sdk_tokens.txt'))
  71.        
  72.  
  73.         """
  74.        By default, the SDK creates the SDKConfig instance
  75.        auto_refresh_fields (Default value is False)
  76.        if True - all the modules' fields will be auto-refreshed in the background, every hour.
  77.        if False - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(zcrmsdk/src/com/zoho/crm/api/util/module_fields_handler.py)
  78.  
  79.        pick_list_validation (Default value is True)
  80.        A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
  81.        if True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
  82.        if False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
  83.  
  84.        connect_timeout (Default value is None)
  85.        A  Float field to set connect timeout
  86.  
  87.        read_timeout (Default value is None)
  88.        A  Float field to set read timeout
  89.        """
  90.         config = SDKConfig(auto_refresh_fields=False, pick_list_validation=False, connect_timeout=None, read_timeout=None)
  91.  
  92.  
  93.         resource_path = folder
  94.  
  95.         """
  96.        RequestProxy takes the following parameters
  97.        1 -> Host
  98.        2 -> Port Number
  99.        3 -> User Name. Default value is None
  100.        4 -> Password. Default value is an empty string
  101.  
  102.        , proxy=request_proxy (last argument for initializer)
  103.        """
  104.         #request_proxy = RequestProxy(host='http://hoegweb01.holmer.net', port=3128)
  105.         #request_proxy = RequestProxy(host='http://hoegweb01.holmer.net', port=3128, user='username', password='password')
  106.  
  107.         """
  108.        Call the static initialize method of Initializer class that takes the following arguments
  109.        1 -> UserSignature instance
  110.        2 -> Environment instance
  111.        3 -> Token instance
  112.        4 -> TokenStore instance
  113.        5 -> SDKConfig instance
  114.        6 -> resource_path
  115.        7 -> Logger instance. Default value is None
  116.        8 -> RequestProxy instance. Default value is None
  117.        """
  118.         Initializer.initialize(user=user, environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger)
  119.  
  120. class Currency(object):
  121.     @staticmethod
  122.     def get_currency(currency_id):
  123.  
  124.         """
  125.        This method is used to get the details of a specific currency.
  126.        :param currency_id: Specify the unique ID of the currency.
  127.        """
  128.  
  129.         """
  130.        example
  131.        currency_id = 3409643000002293037
  132.        currency_id = 236065000005271513
  133.        javascript:loadCurrencyDiv('/crm/org20068335649/CurrencyAction.do?action=edit&currencyId=236065000005271513%27);
  134.        """
  135.  
  136.         # Get instance of CurrenciesOperations Class
  137.         currencies_operations = CurrenciesOperations()
  138.  
  139.         # Call get_currency method that takes currency_id as parameter
  140.         response = currencies_operations.get_currency(currency_id)
  141.  
  142.         if response is not None:
  143.  
  144.             # Get the status code from response
  145.             print('Status Code: ' + str(response.get_status_code()))
  146.  
  147.             if response.get_status_code() in [204, 304]:
  148.                 print('No Content' if response.get_status_code() == 204 else 'Not Modified')
  149.                 return
  150.  
  151.             # Get object from response
  152.             response_object = response.get_object()
  153.  
  154.             if response_object is not None:
  155.  
  156.                 # Check if expected ResponseWrapper instance is received
  157.                 if isinstance(response_object, ResponseWrapper):
  158.  
  159.                     # Get the list of Currency instances
  160.                     currencies_list = response_object.get_currencies()
  161.  
  162.                     for currency in currencies_list:
  163.  
  164.                         # Get the Id of each currency
  165.                         print("Currency Id: " + str(currency.get_id()))
  166.  
  167.                         # Get the IsoCode of each currency
  168.                         print("Currency IsoCode: " + str(currency.get_iso_code()))
  169.  
  170.                         # Get the Symbol of each currency
  171.                         print("Currency Symbol: " + str(currency.get_symbol()))
  172.  
  173.                         # Get the CreatedTime of each currency
  174.                         print("Currency CreatedTime: " + str(currency.get_created_time()))
  175.  
  176.                         # Get if the currency is active
  177.                         print("Currency IsActive: " + str(currency.get_is_active()))
  178.  
  179.                         # Get the ExchangeRate of each currency
  180.                         print("Currency ExchangeRate: " + str(currency.get_exchange_rate()))
  181.  
  182.                         # Get the format instance of each currency
  183.                         format = currency.get_format()
  184.  
  185.                         if format is not None:
  186.                             # Get the DecimalSeparator of the Format
  187.                             print("Currency Format DecimalSeparator: " + format.get_decimal_separator().get_value())
  188.  
  189.                             # Get the ThousandSeparator of the Format
  190.                             print("Currency Format ThousandSeparator: " + format.get_thousand_separator().get_value())
  191.  
  192.                             # Get the DecimalPlaces of the Format
  193.                             print("Currency Format DecimalPlaces: " + format.get_decimal_places().get_value())
  194.  
  195.                         # Get the createdBy User instance of each currency
  196.                         created_by = currency.get_created_by()
  197.  
  198.                         # Check if created_by is not None
  199.                         if created_by is not None:
  200.                             # Get the Name of the created_by User
  201.                             print("Currency Created By - Name: " + created_by.get_name())
  202.  
  203.                             # Get the ID of the created_by User
  204.                             print("Currency Created By - ID: " + str(created_by.get_id()))
  205.  
  206.                         # Get the createdBy User instance of each currency
  207.                         modified_by = currency.get_modified_by()
  208.  
  209.                         # Check if modified_by is not None
  210.                         if modified_by is not None:
  211.                             # Get the Name of the modifiedBy User
  212.                             print("Currency Modified By - Name: " + modified_by.get_name())
  213.  
  214.                             # Get the ID of the modifiedBy User
  215.                             print("Currency Modified By - ID: " + str(modified_by.get_id()))
  216.  
  217.                         # Get the PrefixSymbol of each currency
  218.                         print("Currency PrefixSymbol: " + str(currency.get_prefix_symbol()))
  219.  
  220.                         # Get the IsBase of each currency
  221.                         print("Currency IsBase: " + str(currency.get_is_base()))
  222.  
  223.                         # Get the ModifiedTime of each currency
  224.                         print("Currency ModifiedTime: " + str(currency.get_modified_time()))
  225.  
  226.                         # Get the Name of each currency
  227.                         print("Currency Name: " + currency.get_name())
  228.  
  229.                 # Check if the request returned an exception
  230.                 elif isinstance(response_object, APIException):
  231.  
  232.                     # Get the Status
  233.                     print("Status: " + response_object.get_status().get_value())
  234.  
  235.                     # Get the Code
  236.                     print("Code: " + response_object.get_code().get_value())
  237.  
  238.                     print("Details")
  239.  
  240.                     # Get the details dict
  241.                     details = response_object.get_details()
  242.  
  243.                     for key, value in details.items():
  244.                         print(key + ' : ' + str(value))
  245.  
  246.                     # Get the Message
  247.                     print("Message: " + response_object.get_message().get_value())
  248.  
  249. SDKInitializer.initialize()
  250.  
  251. print("Initialized successfully...")
  252.  
  253. currency_id = 236065000005271513
  254.  
  255. Currency.get_currency(currency_id)
Advertisement
Add Comment
Please, Sign In to add comment