· 4 years ago · Jan 26, 2021, 09:44 AM
1from zcrmsdk.src.com.zoho.crm.api.user_signature import UserSignature
2from zcrmsdk.src.com.zoho.crm.api.dc import USDataCenter
3from zcrmsdk.src.com.zoho.api.authenticator.store import DBStore, FileStore
4from zcrmsdk.src.com.zoho.api.logger import Logger
5from zcrmsdk.src.com.zoho.crm.api.initializer import Initializer
6from zcrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken, TokenType
7from zcrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig
8
9
10class SDKInitializer(object):
11
12 @staticmethod
13 def initialize():
14
15 """
16 Create an instance of Logger Class that takes two parameters
17 1 -> Level of the log messages to be logged. Can be configured by typing Logger.Levels "." and choose any level from the list displayed.
18 2 -> Absolute file path, where messages need to be logged.
19 """
20 logger = Logger.get_instance(level=Logger.Levels.INFO, file_path='/Users/user_name/Documents/python_sdk_log.log')
21
22 # Create an UserSignature instance that takes user Email as parameter
23 user = UserSignature(email='abc@zoho.com')
24
25 """
26 Configure the environment
27 which is of the pattern Domain.Environment
28 Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
29 Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
30 """
31 environment = USDataCenter.PRODUCTION()
32
33 """
34 Create a Token instance that takes the following parameters
35 1 -> OAuth client id.
36 2 -> OAuth client secret.
37 3 -> REFRESH/GRANT token.
38 4 -> token type.
39 5 -> OAuth redirect URL.
40 """
41 token = OAuthToken(client_id='clientId', client_secret='clientSecret', token='REFRESH/ GRANT Token', token_type=TokenType.REFRESH / TokenType.GRANT, redirect_url='redirectURL')
42
43 """
44 Create an instance of TokenStore
45 1 -> Absolute file path of the file to persist tokens
46 """
47 store = FileStore(file_path='/Users/username/Documents/python_sdk_tokens.txt')
48
49 """
50 Create an instance of TokenStore
51 1 -> DataBase host name. Default value "localhost"
52 2 -> DataBase name. Default value "zohooauth"
53 3 -> DataBase user name. Default value "root"
54 4 -> DataBase password. Default value ""
55 5 -> DataBase port number. Default value "3306"
56 """
57 store = DBStore()
58 store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password',port_number='port_number')
59
60 """
61 auto_refresh_fields (Default value is False)
62 if True - all the modules' fields will be auto-refreshed in the background, every hour.
63 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)
64
65 pick_list_validation (Default value is True)
66 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.
67 if True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
68 if False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
69 """
70 config = SDKConfig(auto_refresh_fields=True, pick_list_validation=False)
71
72 """
73 The path containing the absolute directory path (in the key resource_path) to store user-specific files containing information about fields in modules.
74 """
75 resource_path = '/Users/user_name/Documents/python-app'
76
77 """
78 Create an instance of RequestProxy class that takes the following parameters
79 1 -> Host
80 2 -> Port Number
81 3 -> User Name. Default value is None
82 4 -> Password. Default value is None
83 """
84 request_proxy = RequestProxy(host='host', port=8080)
85
86 request_proxy = RequestProxy(host='host', port=8080, user='user', password='password')
87
88 """
89 Call the static initialize method of Initializer class that takes the following arguments
90 1 -> UserSignature instance
91 2 -> Environment instance
92 3 -> Token instance
93 4 -> TokenStore instance
94 5 -> SDKConfig instance
95 6 -> resource_path
96 7 -> Logger instance. Default value is None
97 8 -> RequestProxy instance. Default value is None
98 """
99 Initializer.initialize(user=user, environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger, proxy=request_proxy)
100
101
102SDKInitializer.initialize()