當前位置: 首頁>>代碼示例>>Python>>正文


Python simple_salesforce.Salesforce方法代碼示例

本文整理匯總了Python中simple_salesforce.Salesforce方法的典型用法代碼示例。如果您正苦於以下問題:Python simple_salesforce.Salesforce方法的具體用法?Python simple_salesforce.Salesforce怎麽用?Python simple_salesforce.Salesforce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在simple_salesforce的用法示例。


在下文中一共展示了simple_salesforce.Salesforce方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_query

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def make_query(self, query, include_deleted=False, query_params=None):
        """
        Make a query to Salesforce.

        :param query: The query to make to Salesforce.
        :type query: str
        :param include_deleted: True if the query should include deleted records.
        :type include_deleted: bool
        :param query_params: Additional optional arguments
        :type query_params: dict
        :return: The query result.
        :rtype: dict
        """
        conn = self.get_conn()

        self.log.info("Querying for all objects")
        query_params = query_params or {}
        query_results = conn.query_all(query, include_deleted=include_deleted, **query_params)

        self.log.info("Received results: Total size: %s; Done: %s",
                      query_results['totalSize'], query_results['done'])

        return query_results 
開發者ID:apache,項目名稱:airflow,代碼行數:25,代碼來源:salesforce.py

示例2: get_object_from_salesforce

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def get_object_from_salesforce(self, obj, fields):
        """
        Get all instances of the `object` from Salesforce.
        For each model, only get the fields specified in fields.

        All we really do underneath the hood is run:
            SELECT <fields> FROM <obj>;

        :param obj: The object name to get from Salesforce.
        :type obj: str
        :param fields: The fields to get from the object.
        :type fields: iterable
        :return: all instances of the object from Salesforce.
        :rtype: dict
        """
        query = "SELECT {} FROM {}".format(",".join(fields), obj)

        self.log.info("Making query to Salesforce: %s",
                      query if len(query) < 30 else " ... ".join([query[:15], query[-15:]]))

        return self.make_query(query) 
開發者ID:apache,項目名稱:airflow,代碼行數:23,代碼來源:salesforce.py

示例3: salesforce_request_wrapper

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def salesforce_request_wrapper(method):
    """
    Annotation for querying against Salesforce. Will handle re-authorization if
    the session is logged out, and raise exceptions for unsupported cases.
    """
    def inner(self, *args, **kwargs):
        if self.enabled:
            if self.client:
                try:
                    return method(self, *args, **kwargs)
                except SalesforceExpiredSession:
                    self.login()
                    return method(self, *args, **kwargs)
                # Need to catch OSError for the 'Connection aborted.' error when Salesforce reaps a connection
                except OSError:
                    logger.warning('An OSError occurred while attempting to call {}'.format(method.__name__))
                    self.login()
                    return method(self, *args, **kwargs)
            raise SalesforceNotConfiguredException(
                _('Attempted to query Salesforce with no client for partner={}').format(self.partner.name)
            )
        return None
    return inner 
開發者ID:edx,項目名稱:course-discovery,代碼行數:25,代碼來源:salesforce.py

示例4: login

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def login(self):
            # Need to instantiate a session with multiple retries to avoid OSError
            session = requests.Session()
            adapter = HTTPAdapter(max_retries=2)
            session.mount('https://', adapter)

            salesforce_config = self.partner.salesforce
            sf_kwargs = {
                'username': salesforce_config.username,
                'password': salesforce_config.password,
                'organizationId': salesforce_config.organization_id,
                # security_token must be an empty string if organizationId is set
                'security_token': '' if salesforce_config.organization_id else salesforce_config.token,
                'domain': 'test' if salesforce_config.is_sandbox else None
            }
            self.client = Salesforce(session=session, **sf_kwargs) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:18,代碼來源:salesforce.py

示例5: _create_comment_return_body

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def _create_comment_return_body(user, body, course_run_key=None):
        """
        Salesforce does not return the fully created Object, this method
        creates the equivalent of what we would expect to return from our API
        """
        return {
            'user': {
                'username': user.username,
                'email': user.email or None,
                'first_name': user.first_name or None,
                'last_name': user.last_name or None,
            },
            'course_run_key': course_run_key,
            'comment': body,
            'created': datetime.now(timezone.utc).isoformat(),
        } 
開發者ID:edx,項目名稱:course-discovery,代碼行數:18,代碼來源:salesforce.py

示例6: get_simple_salesforce_connection

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def get_simple_salesforce_connection(project_config, org_config, api_version=None):
    # Retry on long-running metadeploy jobs
    retries = Retry(total=5, status_forcelist=(502, 503, 504), backoff_factor=0.3)
    adapter = HTTPAdapter(max_retries=retries)

    sf = simple_salesforce.Salesforce(
        instance_url=org_config.instance_url,
        session_id=org_config.access_token,
        version=api_version or project_config.project__package__api_version,
    )
    try:
        app = project_config.keychain.get_service("connectedapp")
        client_name = app.client_id
    except (ServiceNotValid, ServiceNotConfigured):
        client_name = "CumulusCI/{}".format(__version__)

    sf.headers.setdefault(CALL_OPTS_HEADER_KEY, "client={}".format(client_name))
    sf.session.mount("http://", adapter)
    sf.session.mount("https://", adapter)

    return sf 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:23,代碼來源:utils.py

示例7: connect

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def connect(connection_name, options):
    table_name = f'salesforce_events_{connection_name}'
    landing_log_table = f'data.{table_name}_connection'

    comment = yaml_dump(module='salesforce_event_log', **options)

    db.create_table(
        name=landing_log_table,
        cols=LANDING_TABLE_COLUMNS,
        comment=comment,
        stage_file_format='TYPE = JSON STRIP_OUTER_ARRAY = TRUE',
        stage_copy_options='PURGE = TRUE',
    )
    db.execute(f'GRANT INSERT, SELECT ON {landing_log_table} TO ROLE {SA_ROLE}')

    return {
        'newStage': 'finalized',
        'newMessage': "Salesforce Event Log ingestion table created!",
    } 
開發者ID:snowflakedb,項目名稱:SnowAlert,代碼行數:21,代碼來源:salesforce_event_log.py

示例8: _post_validate

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def _post_validate(self):
        try:
            self.result.get_global_describe()
        except simple_salesforce.SalesforceError as e:
            self.errors.append("Unable to authenticate to Salesforce: {}".format(e))
            self.result = None 
開發者ID:davidmreed,項目名稱:amaxa,代碼行數:8,代碼來源:credentials.py

示例9: jwt_login

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def jwt_login(consumer_id, username, private_key, api_version, sandbox=False):
    endpoint = (
        "https://test.salesforce.com"
        if sandbox is True
        else "https://login.salesforce.com"
    )
    jwt_payload = jwt.encode(
        {
            "exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=30),
            "iss": consumer_id,
            "aud": endpoint,
            "sub": username,
        },
        private_key,
        algorithm="RS256",
    )

    result = requests.post(
        endpoint + "/services/oauth2/token",
        data={
            "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
            "assertion": jwt_payload,
        },
    )
    body = result.json()

    if result.status_code != 200:
        raise SalesforceAuthenticationFailed(body["error"], body["error_description"])

    return simple_salesforce.Salesforce(
        instance_url=body["instance_url"],
        session_id=body["access_token"],
        version=api_version,
    ) 
開發者ID:davidmreed,項目名稱:amaxa,代碼行數:36,代碼來源:jwt_auth.py

示例10: setUpClass

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def setUpClass(cls):
        cls.connection = Salesforce(
            instance_url=os.environ["INSTANCE_URL"],
            session_id=os.environ["ACCESS_TOKEN"],
            version="48.0",
        ) 
開發者ID:davidmreed,項目名稱:amaxa,代碼行數:8,代碼來源:IntegrationTest.py

示例11: setUp

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def setUp(self):
        self.connection = Salesforce(
            instance_url=os.environ["INSTANCE_URL"],
            session_id=os.environ["ACCESS_TOKEN"],
            version=constants.OPTION_DEFAULTS["api-version"],
        ) 
開發者ID:davidmreed,項目名稱:amaxa,代碼行數:8,代碼來源:test_integration_high_volume.py

示例12: test_get_conn_exists

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def test_get_conn_exists(self):
        self.salesforce_hook.conn = Mock(spec=Salesforce)

        self.salesforce_hook.get_conn()

        self.assertIsNotNone(self.salesforce_hook.conn.return_value) 
開發者ID:apache,項目名稱:airflow,代碼行數:8,代碼來源:test_salesforce.py

示例13: test_describe_object

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def test_describe_object(self, mock_salesforce):
        obj = "obj_name"
        mock_salesforce.return_value.__setattr__(obj, Mock(spec=Salesforce))
        self.salesforce_hook.conn = mock_salesforce.return_value

        obj_description = self.salesforce_hook.describe_object(obj)

        mock_salesforce.return_value.__getattr__(obj).describe.assert_called_once_with()
        self.assertEqual(obj_description, mock_salesforce.return_value.__getattr__(obj).describe.return_value) 
開發者ID:apache,項目名稱:airflow,代碼行數:11,代碼來源:test_salesforce.py

示例14: get_conn

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def get_conn(self):
        """
        Sign into Salesforce, only if we are not already signed in.
        """
        if not self.conn:
            connection = self.get_connection(self.conn_id)
            extras = connection.extra_dejson
            self.conn = Salesforce(
                username=connection.login,
                password=connection.password,
                security_token=extras['security_token'],
                instance_url=connection.host,
                domain=extras.get('domain', None)
            )
        return self.conn 
開發者ID:apache,項目名稱:airflow,代碼行數:17,代碼來源:salesforce.py

示例15: describe_object

# 需要導入模塊: import simple_salesforce [as 別名]
# 或者: from simple_salesforce import Salesforce [as 別名]
def describe_object(self, obj):
        """
        Get the description of an object from Salesforce.
        This description is the object's schema and
        some extra metadata that Salesforce stores for each object.

        :param obj: The name of the Salesforce object that we are getting a description of.
        :type obj: str
        :return: the description of the Salesforce object.
        :rtype: dict
        """
        conn = self.get_conn()

        return conn.__getattr__(obj).describe() 
開發者ID:apache,項目名稱:airflow,代碼行數:16,代碼來源:salesforce.py


注:本文中的simple_salesforce.Salesforce方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。