コード例 #1
0
def configure_hubspot_settings():
    """Configure the current Hubspot ecommerce bridge settings for the api key specified in settings"""
    response = send_hubspot_request(
        "", HUBSPOT_SETTINGS_PATH, "PUT", body=HUBSPOT_ECOMMERCE_SETTINGS
    )
    response.raise_for_status()
    return response
コード例 #2
0
ファイル: sync_hubspot.py プロジェクト: mitodl/mitxpro
    def bulk_sync_model(
        objects, make_object_sync_message, object_type, use_email=False
    ):
        """
        Sync all database objects of a certain type with hubspot
        Args:
            objects (iterable) objects to sync
            make_object_sync_message (function) function that takes an objectID and
                returns a sync message for that model
            object_type (str) one of "CONTACT", "DEAL", "PRODUCT", "LINE_ITEM"
            use_email (bool) either we need to pass the object ID or Email in case of "USER" queryset.
        """
        if objects.model is B2BOrder and use_email:
            sync_messages = [make_object_sync_message(obj.email)[0] for obj in objects]
        else:
            sync_messages = [make_object_sync_message(obj.id)[0] for obj in objects]
        while len(sync_messages) > 0:
            staged_messages = sync_messages[0:200]
            sync_messages = sync_messages[200:]

            print("    Sending sync message...")
            response = send_hubspot_request(
                object_type, HUBSPOT_SYNC_URL, "PUT", body=staged_messages
            )
            try:
                response.raise_for_status()
            except HTTPError:
                print(
                    "    Sync message failed with status {} and message {}".format(
                        response.status_code, response.json().get("message")
                    )
                )
コード例 #3
0
def sync_b2b_product_with_hubspot(order_id):
    """Send a sync-message to sync a line with a hubspot line item"""
    body = make_b2b_product_sync_message(order_id)
    response = send_hubspot_request("LINE_ITEM",
                                    HUBSPOT_SYNC_URL,
                                    "PUT",
                                    body=body)
    response.raise_for_status()
コード例 #4
0
def sync_b2b_deal_with_hubspot(self, order_id):  # pylint: disable=unused-argument
    """Send a sync-message to sync a b2b order with a hubspot deal"""
    body = make_b2b_deal_sync_message(order_id)
    response = send_hubspot_request("DEAL", HUBSPOT_SYNC_URL, "PUT", body=body)
    response.raise_for_status()

    index_tasks = celery.group([sync_b2b_product_with_hubspot.si(order_id)])
    raise self.replace(celery.chain(index_tasks))
コード例 #5
0
def sync_b2b_contact_with_hubspot(email):
    """Send a sync-message to sync a user with a hubspot b2b contact"""
    body = make_b2b_contact_sync_message(email)
    response = send_hubspot_request("CONTACT",
                                    HUBSPOT_SYNC_URL,
                                    "PUT",
                                    body=body)
    response.raise_for_status()
コード例 #6
0
def sync_product_with_hubspot(product_id):
    """Send a sync-message to sync a product with a hubspot product"""
    body = make_product_sync_message(product_id)
    response = send_hubspot_request("PRODUCT",
                                    HUBSPOT_SYNC_URL,
                                    "PUT",
                                    body=body)
    response.raise_for_status()
コード例 #7
0
def sync_deal_with_hubspot(self, order_id):
    """Send a sync-message to sync an order with a hubspot deal"""
    order = Order.objects.get(id=order_id)
    body = make_deal_sync_message(order_id)
    response = send_hubspot_request("DEAL", HUBSPOT_SYNC_URL, "PUT", body=body)
    response.raise_for_status()
    index_tasks = celery.group([
        sync_line_item_with_hubspot.si(line.id) for line in order.lines.all()
    ])
    raise self.replace(celery.chain(index_tasks))
コード例 #8
0
def test_send_hubspot_request(mocker, request_method, endpoint, api_url, expected_url):
    """Test sending hubspot request with method = GET"""
    value = fake.pyint()
    query_params = {"param": value}

    # Include hapikey when generating url to match request call against
    full_query_params = {"param": value, "hapikey": settings.HUBSPOT_API_KEY}
    mock_request = mocker.patch(f"hubspot.api.requests.{request_method.lower()}")
    url_params = urlencode(full_query_params)
    url = f"{expected_url}?{url_params}"
    if request_method == "GET":
        api.send_hubspot_request(
            endpoint, api_url, request_method, query_params=query_params
        )
        mock_request.assert_called_once_with(url=url)
    else:
        body = fake.pydict()
        api.send_hubspot_request(
            endpoint, api_url, request_method, query_params=query_params, body=body
        )
        mock_request.assert_called_once_with(url=url, json=body)
コード例 #9
0
def get_hubspot_settings():
    """Get the current Hubspot ecommerce bridge settings for the api key specified in settings"""
    response = send_hubspot_request("", HUBSPOT_SETTINGS_PATH, "GET")
    response.raise_for_status()
    return response
コード例 #10
0
def get_hubspot_installation_status():
    """Get the Hubspot ecommerce bridge installation status for the api key specified in settings"""
    response = send_hubspot_request("status", HUBSPOT_INSTALL_PATH, "GET")
    response.raise_for_status()
    return response
コード例 #11
0
def uninstall_hubspot_ecommerce_bridge():
    """Install the Hubspot ecommerce bridge for the api key specified in settings"""
    response = send_hubspot_request("uninstall", HUBSPOT_INSTALL_PATH, "POST")
    response.raise_for_status()
    return response