Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from zcrmsdk.src.com.zoho.crm.api.user_signature import UserSignature
- from zcrmsdk.src.com.zoho.crm.api.dc import EUDataCenter
- from zcrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken
- from zcrmsdk.src.com.zoho.api.logger import Logger
- from zcrmsdk.src.com.zoho.api.authenticator.store import FileStore
- from zcrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig
- from zcrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy
- from zcrmsdk.src.com.zoho.crm.api.initializer import Initializer
- import os
- from zcrmsdk.src.com.zoho.crm.api.currencies import *
- from zcrmsdk.src.com.zoho.crm.api.currencies import Currency as ZCRMCurrency
- from zcrmsdk.src.com.zoho.crm.api.util import Choice
- folder = os.path.dirname(__file__)
- print("pyZohoDownloader is starting...")
- print("Initializing...")
- class SDKInitializer(object):
- @staticmethod
- def initialize():
- # Create an UserSignature instance that takes user Email as parameter
- """
- Configure the environment
- which is of the pattern Domain.Environment
- Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
- Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
- """
- environment = EUDataCenter.PRODUCTION()
- """
- Create a Token instance that takes the following parameters
- 1 -> OAuth client id.
- 2 -> OAuth client secret.
- 3 -> Grant token.
- 4 -> Refresh token.
- 5 -> OAuth redirect URL. Default value is None
- 6 -> id
- 7 -> Access token
- """
- 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')
- """
- Create an instance of Logger Class that takes two parameters
- 1 -> Level of the log messages to be logged. Can be configured by typing Logger.Levels "." and choose any level from the list displayed.
- 2 -> Absolute file path, where messages need to be logged.
- """
- logger = Logger.get_instance(level=Logger.Levels.INFO, file_path=os.path.join(folder,'logs', "python_sdk_log.log"))
- """
- DBStore takes the following parameters
- 1 -> DataBase host name. Default value "localhost"
- 2 -> DataBase name. Default value "zohooauth"
- 3 -> DataBase user name. Default value "root"
- 4 -> DataBase password. Default value ""
- 5 -> DataBase port number. Default value "3306"
- 6 -> DataBase table name. Default value "oauthtoken"
- """
- #store = DBStore()
- #store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name = "table_name")
- """
- FileStore takes the following parameter
- 1 -> Absolute file path of the file to persist tokens
- """
- store = FileStore(file_path=os.path.join(folder,'python_sdk_tokens.txt'))
- """
- By default, the SDK creates the SDKConfig instance
- auto_refresh_fields (Default value is False)
- if True - all the modules' fields will be auto-refreshed in the background, every hour.
- 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)
- pick_list_validation (Default value is True)
- 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.
- if True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
- if False - the SDK does not validate the input and makes the API request with the userβs input to the pick list
- connect_timeout (Default value is None)
- A Float field to set connect timeout
- read_timeout (Default value is None)
- A Float field to set read timeout
- """
- config = SDKConfig(auto_refresh_fields=False, pick_list_validation=False, connect_timeout=None, read_timeout=None)
- resource_path = folder
- """
- RequestProxy takes the following parameters
- 1 -> Host
- 2 -> Port Number
- 3 -> User Name. Default value is None
- 4 -> Password. Default value is an empty string
- , proxy=request_proxy (last argument for initializer)
- """
- #request_proxy = RequestProxy(host='http://hoegweb01.holmer.net', port=3128)
- #request_proxy = RequestProxy(host='http://hoegweb01.holmer.net', port=3128, user='username', password='password')
- """
- Call the static initialize method of Initializer class that takes the following arguments
- 1 -> UserSignature instance
- 2 -> Environment instance
- 3 -> Token instance
- 4 -> TokenStore instance
- 5 -> SDKConfig instance
- 6 -> resource_path
- 7 -> Logger instance. Default value is None
- 8 -> RequestProxy instance. Default value is None
- """
- Initializer.initialize(user=user, environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger)
- class Currency(object):
- @staticmethod
- def get_currency(currency_id):
- """
- This method is used to get the details of a specific currency.
- :param currency_id: Specify the unique ID of the currency.
- """
- """
- example
- currency_id = 3409643000002293037
- currency_id = 236065000005271513
- javascript:loadCurrencyDiv('/crm/org20068335649/CurrencyAction.do?action=edit¤cyId=236065000005271513%27);
- """
- # Get instance of CurrenciesOperations Class
- currencies_operations = CurrenciesOperations()
- # Call get_currency method that takes currency_id as parameter
- response = currencies_operations.get_currency(currency_id)
- if response is not None:
- # Get the status code from response
- print('Status Code: ' + str(response.get_status_code()))
- if response.get_status_code() in [204, 304]:
- print('No Content' if response.get_status_code() == 204 else 'Not Modified')
- return
- # Get object from response
- response_object = response.get_object()
- if response_object is not None:
- # Check if expected ResponseWrapper instance is received
- if isinstance(response_object, ResponseWrapper):
- # Get the list of Currency instances
- currencies_list = response_object.get_currencies()
- for currency in currencies_list:
- # Get the Id of each currency
- print("Currency Id: " + str(currency.get_id()))
- # Get the IsoCode of each currency
- print("Currency IsoCode: " + str(currency.get_iso_code()))
- # Get the Symbol of each currency
- print("Currency Symbol: " + str(currency.get_symbol()))
- # Get the CreatedTime of each currency
- print("Currency CreatedTime: " + str(currency.get_created_time()))
- # Get if the currency is active
- print("Currency IsActive: " + str(currency.get_is_active()))
- # Get the ExchangeRate of each currency
- print("Currency ExchangeRate: " + str(currency.get_exchange_rate()))
- # Get the format instance of each currency
- format = currency.get_format()
- if format is not None:
- # Get the DecimalSeparator of the Format
- print("Currency Format DecimalSeparator: " + format.get_decimal_separator().get_value())
- # Get the ThousandSeparator of the Format
- print("Currency Format ThousandSeparator: " + format.get_thousand_separator().get_value())
- # Get the DecimalPlaces of the Format
- print("Currency Format DecimalPlaces: " + format.get_decimal_places().get_value())
- # Get the createdBy User instance of each currency
- created_by = currency.get_created_by()
- # Check if created_by is not None
- if created_by is not None:
- # Get the Name of the created_by User
- print("Currency Created By - Name: " + created_by.get_name())
- # Get the ID of the created_by User
- print("Currency Created By - ID: " + str(created_by.get_id()))
- # Get the createdBy User instance of each currency
- modified_by = currency.get_modified_by()
- # Check if modified_by is not None
- if modified_by is not None:
- # Get the Name of the modifiedBy User
- print("Currency Modified By - Name: " + modified_by.get_name())
- # Get the ID of the modifiedBy User
- print("Currency Modified By - ID: " + str(modified_by.get_id()))
- # Get the PrefixSymbol of each currency
- print("Currency PrefixSymbol: " + str(currency.get_prefix_symbol()))
- # Get the IsBase of each currency
- print("Currency IsBase: " + str(currency.get_is_base()))
- # Get the ModifiedTime of each currency
- print("Currency ModifiedTime: " + str(currency.get_modified_time()))
- # Get the Name of each currency
- print("Currency Name: " + currency.get_name())
- # Check if the request returned an exception
- elif isinstance(response_object, APIException):
- # Get the Status
- print("Status: " + response_object.get_status().get_value())
- # Get the Code
- print("Code: " + response_object.get_code().get_value())
- print("Details")
- # Get the details dict
- details = response_object.get_details()
- for key, value in details.items():
- print(key + ' : ' + str(value))
- # Get the Message
- print("Message: " + response_object.get_message().get_value())
- SDKInitializer.initialize()
- print("Initialized successfully...")
- currency_id = 236065000005271513
- Currency.get_currency(currency_id)
Advertisement
Add Comment
Please, Sign In to add comment