Esempio n. 1
0
    def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, _request_timeout=None):
        """Perform requests.

        :param method: http request method
        :param url: http request url
        :param query_params: query parameters in the url
        :param headers: http request headers
        :param body: request json body, for `application/json`
        :param post_params: request post parameters,
                            `application/x-www-form-urlencoded`
                            and `multipart/form-data`
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        """
        method = method.upper()
        assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]

        if post_params and body:
            raise ApiValueError("body parameter cannot be used with post_params parameter.")

        post_params = post_params or {}
        headers = headers or {}

        timeout = None
        if _request_timeout:
            if isinstance(_request_timeout, (int,) if six.PY3 else (int, long)):  # noqa: E501,F821
                timeout = urllib3.Timeout(total=_request_timeout)
            elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
                timeout = urllib3.Timeout(connect=_request_timeout[0], read=_request_timeout[1])

        if "Content-Type" not in headers:
            headers["Content-Type"] = "application/json"

        try:
            # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
            if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
                if query_params:
                    url += "?" + urlencode(query_params)
                if re.search("json", headers["Content-Type"], re.IGNORECASE):
                    request_body = None
                    if body is not None:
                        request_body = json.dumps(body)
                    r = self.pool_manager.request(method, url, body=request_body, preload_content=_preload_content, timeout=timeout, headers=headers)
                elif headers["Content-Type"] == "application/x-www-form-urlencoded":  # noqa: E501
                    r = self.pool_manager.request(method, url, fields=post_params, encode_multipart=False, preload_content=_preload_content, timeout=timeout, headers=headers)
                elif headers["Content-Type"] == "multipart/form-data":
                    # must del headers['Content-Type'], or the correct
                    # Content-Type which generated by urllib3 will be
                    # overwritten.
                    del headers["Content-Type"]
                    r = self.pool_manager.request(method, url, fields=post_params, encode_multipart=True, preload_content=_preload_content, timeout=timeout, headers=headers)
                # Pass a `string` parameter directly in the body to support
                # other content types than Json when `body` argument is
                # provided in serialized form
                elif isinstance(body, str) or isinstance(body, bytes):
                    request_body = body
                    r = self.pool_manager.request(method, url, body=request_body, preload_content=_preload_content, timeout=timeout, headers=headers)
                else:
                    # Cannot generate the request from given parameters
                    msg = """Cannot prepare a request message for provided
                             arguments. Please check that your arguments match
                             declared content type."""
                    raise ApiException(status=0, reason=msg)
            # For `GET`, `HEAD`
            else:
                r = self.pool_manager.request(method, url, fields=query_params, preload_content=_preload_content, timeout=timeout, headers=headers)
        except urllib3.exceptions.SSLError as e:
            msg = "{0}\n{1}".format(type(e).__name__, str(e))
            raise ApiException(status=0, reason=msg)

        if _preload_content:
            r = RESTResponse(r)

            # In the python 3, the response.data is bytes.
            # we need to decode it to string.
            if six.PY3:
                r.data = r.data.decode("utf8")

            # log response body
            logger.debug("response body: %s", r.data)

        if not 200 <= r.status <= 299:
            raise ApiException(http_resp=r)

        return r
Esempio n. 2
0
    def do_search_with_http_info(self, q, **kwargs):  # noqa: E501
        """Search for marketing events  # noqa: E501

        Search for marketing events that have an event id that starts with the query string  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.do_search_with_http_info(q, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str q: The partial event id to search for (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(CollectionResponseMarketingEventExternalUniqueIdentifierNoPaging, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ["q"]  # noqa: E501
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'"
                                   " to method do_search" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'q' is set
        if self.api_client.client_side_validation and (
                "q" not in local_var_params
                or local_var_params["q"] is None):  # noqa: E501  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `q` when calling `do_search`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if "q" in local_var_params and local_var_params[
                "q"] is not None:  # noqa: E501
            query_params.append(("q", local_var_params["q"]))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json", "*/*"])  # noqa: E501

        # Authentication setting
        auth_settings = ["hapikey", "oauth2"]  # noqa: E501

        return self.api_client.call_api(
            "/marketing/v3/marketing-events/events/search",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type=
            "CollectionResponseMarketingEventExternalUniqueIdentifierNoPaging",  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get(
                "_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
Esempio n. 3
0
    def update_with_http_info(self, external_event_id, external_account_id,
                              marketing_event_update_request_params,
                              **kwargs):  # noqa: E501
        """Update a marketing event  # noqa: E501

        Updates an existing Marketing Event with the specified id, if one exists.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.update_with_http_info(external_event_id, external_account_id, marketing_event_update_request_params, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str external_event_id: The id of the marketing event to update (required)
        :param str external_account_id: The account id associated with the marketing event (required)
        :param MarketingEventUpdateRequestParams marketing_event_update_request_params: The details of the marketing event to update (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(MarketingEventPublicDefaultResponse, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = [
            "external_event_id", "external_account_id",
            "marketing_event_update_request_params"
        ]  # noqa: E501
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'"
                                   " to method update" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'external_event_id' is set
        if self.api_client.client_side_validation and (
                "external_event_id" not in local_var_params
                or local_var_params["external_event_id"] is None
        ):  # noqa: E501  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `external_event_id` when calling `update`"
            )  # noqa: E501
        # verify the required parameter 'external_account_id' is set
        if self.api_client.client_side_validation and (
                "external_account_id" not in local_var_params
                or local_var_params["external_account_id"] is None
        ):  # noqa: E501  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `external_account_id` when calling `update`"
            )  # noqa: E501
        # verify the required parameter 'marketing_event_update_request_params' is set
        if self.api_client.client_side_validation and (
                "marketing_event_update_request_params" not in local_var_params
                or local_var_params["marketing_event_update_request_params"] is
                None  # noqa: E501
        ):  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `marketing_event_update_request_params` when calling `update`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}
        if "external_event_id" in local_var_params:
            path_params["externalEventId"] = local_var_params[
                "external_event_id"]  # noqa: E501

        query_params = []
        if "external_account_id" in local_var_params and local_var_params[
                "external_account_id"] is not None:  # noqa: E501
            query_params.append(
                ("externalAccountId",
                 local_var_params["external_account_id"]))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "marketing_event_update_request_params" in local_var_params:
            body_params = local_var_params[
                "marketing_event_update_request_params"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json", "*/*"])  # noqa: E501

        # HTTP header `Content-Type`
        header_params[
            "Content-Type"] = self.api_client.select_header_content_type(
                ["application/json"])  # noqa: E501  # noqa: E501

        # Authentication setting
        auth_settings = ["hapikey", "oauth2"]  # noqa: E501

        return self.api_client.call_api(
            "/marketing/v3/marketing-events/events/{externalEventId}",
            "PATCH",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="MarketingEventPublicDefaultResponse",  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get(
                "_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
Esempio n. 4
0
    def do_email_upsert_by_id_with_http_info(self, external_event_id, subscriber_state, external_account_id, batch_input_marketing_event_email_subscriber, **kwargs):  # noqa: E501
        """Record  # noqa: E501

        Record a subscription state between multiple HubSpot contacts and a marketing event, using contact email addresses.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.do_email_upsert_by_id_with_http_info(external_event_id, subscriber_state, external_account_id, batch_input_marketing_event_email_subscriber, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str external_event_id: The id of the marketing event (required)
        :param str subscriber_state: The new subscriber state for the HubSpot contacts and the specified marketing event (required)
        :param str external_account_id: The account id associated with the marketing event (required)
        :param BatchInputMarketingEventEmailSubscriber batch_input_marketing_event_email_subscriber: The details of the contacts to subscribe to the event (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(Error, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ["external_event_id", "subscriber_state", "external_account_id", "batch_input_marketing_event_email_subscriber"]  # noqa: E501
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'" " to method do_email_upsert_by_id" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'external_event_id' is set
        if self.api_client.client_side_validation and ("external_event_id" not in local_var_params or local_var_params["external_event_id"] is None):  # noqa: E501  # noqa: E501
            raise ApiValueError("Missing the required parameter `external_event_id` when calling `do_email_upsert_by_id`")  # noqa: E501
        # verify the required parameter 'subscriber_state' is set
        if self.api_client.client_side_validation and ("subscriber_state" not in local_var_params or local_var_params["subscriber_state"] is None):  # noqa: E501  # noqa: E501
            raise ApiValueError("Missing the required parameter `subscriber_state` when calling `do_email_upsert_by_id`")  # noqa: E501
        # verify the required parameter 'external_account_id' is set
        if self.api_client.client_side_validation and ("external_account_id" not in local_var_params or local_var_params["external_account_id"] is None):  # noqa: E501  # noqa: E501
            raise ApiValueError("Missing the required parameter `external_account_id` when calling `do_email_upsert_by_id`")  # noqa: E501
        # verify the required parameter 'batch_input_marketing_event_email_subscriber' is set
        if self.api_client.client_side_validation and (
            "batch_input_marketing_event_email_subscriber" not in local_var_params or local_var_params["batch_input_marketing_event_email_subscriber"] is None  # noqa: E501
        ):  # noqa: E501
            raise ApiValueError("Missing the required parameter `batch_input_marketing_event_email_subscriber` when calling `do_email_upsert_by_id`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if "external_event_id" in local_var_params:
            path_params["externalEventId"] = local_var_params["external_event_id"]  # noqa: E501
        if "subscriber_state" in local_var_params:
            path_params["subscriberState"] = local_var_params["subscriber_state"]  # noqa: E501

        query_params = []
        if "external_account_id" in local_var_params and local_var_params["external_account_id"] is not None:  # noqa: E501
            query_params.append(("externalAccountId", local_var_params["external_account_id"]))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "batch_input_marketing_event_email_subscriber" in local_var_params:
            body_params = local_var_params["batch_input_marketing_event_email_subscriber"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(["*/*"])  # noqa: E501

        # HTTP header `Content-Type`
        header_params["Content-Type"] = self.api_client.select_header_content_type(["application/json"])  # noqa: E501  # noqa: E501

        # Authentication setting
        auth_settings = ["hapikey", "oauth2"]  # noqa: E501

        return self.api_client.call_api(
            "/marketing/v3/marketing-events/events/{externalEventId}/{subscriberState}/email-upsert",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="Error",  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get("_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
Esempio n. 5
0
    def archive_with_http_info(
            self, batch_input_marketing_event_external_unique_identifier,
            **kwargs):  # noqa: E501
        """Delete multiple marketing events  # noqa: E501

        Bulk delete a number of marketing events in HubSpot  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.archive_with_http_info(batch_input_marketing_event_external_unique_identifier, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param BatchInputMarketingEventExternalUniqueIdentifier batch_input_marketing_event_external_unique_identifier: The details of the marketing events to delete (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(Error, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = [
            "batch_input_marketing_event_external_unique_identifier"
        ]  # noqa: E501
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'"
                                   " to method archive" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'batch_input_marketing_event_external_unique_identifier' is set
        if self.api_client.client_side_validation and (
                "batch_input_marketing_event_external_unique_identifier"
                not in local_var_params or local_var_params[
                    "batch_input_marketing_event_external_unique_identifier"]
                is None  # noqa: E501
        ):  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `batch_input_marketing_event_external_unique_identifier` when calling `archive`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "batch_input_marketing_event_external_unique_identifier" in local_var_params:
            body_params = local_var_params[
                "batch_input_marketing_event_external_unique_identifier"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["*/*"])  # noqa: E501

        # HTTP header `Content-Type`
        header_params[
            "Content-Type"] = self.api_client.select_header_content_type(
                ["application/json"])  # noqa: E501  # noqa: E501

        # Authentication setting
        auth_settings = ["hapikey", "oauth2"]  # noqa: E501

        return self.api_client.call_api(
            "/marketing/v3/marketing-events/events/delete",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="Error",  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get(
                "_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
Esempio n. 6
0
    def create_with_http_info(self, app_id, event_detail_settings_url,
                              **kwargs):  # noqa: E501
        """Update the application settings  # noqa: E501

        Create or update the current settings for the application.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.create_with_http_info(app_id, event_detail_settings_url, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param int app_id: The id of the application to update the settings for. (required)
        :param EventDetailSettingsUrl event_detail_settings_url: The new application settings (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(EventDetailSettings, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ["app_id", "event_detail_settings_url"]  # noqa: E501
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'"
                                   " to method create" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'app_id' is set
        if self.api_client.client_side_validation and (
                "app_id" not in local_var_params or local_var_params["app_id"]
                is None):  # noqa: E501  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `app_id` when calling `create`"
            )  # noqa: E501
        # verify the required parameter 'event_detail_settings_url' is set
        if self.api_client.client_side_validation and (
                "event_detail_settings_url" not in local_var_params
                or local_var_params["event_detail_settings_url"] is None
        ):  # noqa: E501  # noqa: E501
            raise ApiValueError(
                "Missing the required parameter `event_detail_settings_url` when calling `create`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}
        if "app_id" in local_var_params:
            path_params["appId"] = local_var_params["app_id"]  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "event_detail_settings_url" in local_var_params:
            body_params = local_var_params["event_detail_settings_url"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json", "*/*"])  # noqa: E501

        # HTTP header `Content-Type`
        header_params[
            "Content-Type"] = self.api_client.select_header_content_type(
                ["application/json"])  # noqa: E501  # noqa: E501

        # Authentication setting
        auth_settings = ["developer_hapikey", "hapikey"]  # noqa: E501

        return self.api_client.call_api(
            "/marketing/v3/marketing-events/{appId}/settings",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="EventDetailSettings",  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get(
                "_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
        )