How to use ask-sdk-model - 10 common examples

To help you get started, we’ve selected a few ask-sdk-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / base_service_client.py View on Github external
in {} braces
        :type path: str
        :param query_params: Query Parameters to be appended to the url
        :type query_params: list(tuple(str, str)
        :param path_params: Parameters to be interpolated in the path.
            Keys should match variables specified in the path # noqa: E501
        :type path_params: dict(str, str)
        :return Built url
        :rtype: str
        """
        process_endpoint = (
            endpoint[:-1] if endpoint.endswith("/") else endpoint)
        path_with_params = BaseServiceClient.__interpolate_params(path,
                                                                  path_params)
        is_constant_query_present = "?" in path_with_params
        query_string = BaseServiceClient.__build_query_string(
            query_params, is_constant_query_present)

        return '{}{}{}'.format(process_endpoint, path_with_params,
                               query_string)
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / base_service_client.py View on Github external
:param endpoint: Endpoint to be sending the api call
        :type endpoint: str
        :param path: Path to send the api call. Could contain variables
            in {} braces
        :type path: str
        :param query_params: Query Parameters to be appended to the url
        :type query_params: list(tuple(str, str)
        :param path_params: Parameters to be interpolated in the path.
            Keys should match variables specified in the path # noqa: E501
        :type path_params: dict(str, str)
        :return Built url
        :rtype: str
        """
        process_endpoint = (
            endpoint[:-1] if endpoint.endswith("/") else endpoint)
        path_with_params = BaseServiceClient.__interpolate_params(path,
                                                                  path_params)
        is_constant_query_present = "?" in path_with_params
        query_string = BaseServiceClient.__build_query_string(
            query_params, is_constant_query_present)

        return '{}{}{}'.format(process_endpoint, path_with_params,
                               query_string)
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / lwa_client.py View on Github external
from dateutil import tz
from datetime import datetime, timedelta
from ..base_service_client import BaseServiceClient
from ..service_client_response import ServiceClientResponse
from .access_token_request import AccessTokenRequest
from .access_token import AccessToken

if typing.TYPE_CHECKING:
    from .access_token_response import AccessTokenResponse
    from ..api_configuration import ApiConfiguration
    from ..authentication_configuration import AuthenticationConfiguration
    from typing import Any, Dict, List, Optional


class LwaClient(BaseServiceClient):
    """Client to call Login with Amazon (LWA) to retrieve access tokens.

    :param api_configuration: ApiConfiguration instance with valid
        Serializer and ApiClient. The authorization value and api endpoint
        is not used by the LWA Client.
    :type api_configuration:
        ask_sdk_model.services.api_configuration.ApiConfiguration
    :param authentication_configuration: AuthenticationConfiguration
        instance with valid client id and client secret, for making LWA
        calls.
    :type authentication_configuration: ask_sdk_model.services.authentication_configuration.AuthenticationConfiguration
    :param grant_type: The grant type which is used to make the HTTP request.
    :type grant_type: (optional) str
    :raises: :py:class:`ValueError` if authentication configuration is not
        provided.
    """
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / base_service_client.py View on Github external
if body:
            request.body = self._serializer.serialize(body)

        try:
            response = self._api_client.invoke(request)
        except Exception as e:
            raise ServiceException(
                message="Call to service failed: {}".format(str(e)),
                status_code=500, headers=None, body=None)

        if response.status_code is None:
            raise ServiceException(message="Invalid Response, no status code",
                                   status_code=500, headers=None, body=None)

        if BaseServiceClient.__is_code_successful(response.status_code):
            api_response = ApiResponse(headers=response.headers,
                                       status_code=response.status_code)

            # Body of HTTP 204 (No Content) response should be empty, return
            # ApiResponse with empty body, since body is not a valid json
            # value to be deserialized
            if ((response_type is None) or (
                    response.status_code == 204 and not response.body)):
                return api_response

            api_response.body = self._serializer.deserialize(
                payload=response.body, obj_type=response_type)
            return api_response

        if response_definitions:
            exception_metadata_list = ([d for d in response_definitions if
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / base_service_client.py View on Github external
:type path_params: dict(str, str)
        :param response_definitions: Well-known expected responses by
            the ServiceClient
        :type response_definitions: list(ask_sdk_model.services.service_client_response.ServiceClientResponse)
        :param body: Request body
        :type body: object
        :param response_type: Type of the expected response if applicable
        :type response_type: class
        :return: ApiResponse object.
        :rtype: :py:class:`ask_sdk_model.services.api_response.py`
        :raises: :py:class:`ask_sdk_model.services.service_exception.ServiceException`
            if service fails and :py:class:`ValueError` if serializer or API
            Client is not configured in api_configuration # noqa: E501
        """
        request = ApiClientRequest()
        request.url = BaseServiceClient.__build_url(endpoint=endpoint,
                                                    path=path,
                                                    query_params=query_params,
                                                    path_params=path_params)
        request.method = method
        request.headers = header_params

        if self._serializer is None:
            raise ValueError("Serializer is None")

        if self._api_client is None:
            raise ValueError("API client is None")

        if body:
            request.body = self._serializer.serialize(body)

        try:
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / lwa_client.py View on Github external
"""
        if scope is None:
            cache_key = self.REFRESH_ACCESS_TOKEN
        else:
            cache_key = scope

        access_token = self._scoped_token_cache.get(cache_key, None)
        local_now = datetime.now(tz.tzutc())

        if (access_token is not None and
            access_token.expiry >
                local_now + timedelta(
                    milliseconds=self.EXPIRY_OFFSET_IN_MILLIS)):
            return access_token.token

        access_token_request = AccessTokenRequest(
            client_id=self._authentication_configuration.client_id,
            client_secret=self._authentication_configuration.client_secret)

        if self._authentication_configuration.refresh_token is None:
            access_token_request.scope = scope
        else:
            access_token_request.refresh_token = (
                self._authentication_configuration.refresh_token)

        lwa_response = self._generate_access_token(
            access_token_request=access_token_request)

        if lwa_response is None or lwa_response.expires_in is None:
            raise ValueError("Invalid response from LWA Client generate "
                             "access token call")
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / access_token_request.py View on Github external
def __eq__(self, other):
        # type: (object) -> bool
        """Returns true if both objects are equal"""
        if not isinstance(other, AccessTokenRequest):
            return False

        return self.__dict__ == other.__dict__
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / lwa_client.py View on Github external
param_info = "refresh_token={}".format(
                access_token_request.refresh_token)
        else:
            param_info = "scope={}".format(access_token_request.scope)
        body_params += "&{}".format(param_info)
        error_definitions = list()  # type: List
        error_definitions.append(ServiceClientResponse(
            response_type=(
                "ask_sdk_model.services.lwa.access_token_response."
                "AccessTokenResponse"),
            status_code=200, message="Success"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=400,
            message="Bad Request"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=401,
            message="Authentication failed"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=500,
            message="Internal Server Error"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=503,
            message="Service Unavailable"))

        api_response = self.invoke(method="POST", endpoint=endpoint,
                                   path=resource_path, path_params=path_params,
                                   query_params=query_params,
                                   header_params=header_params,
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / lwa_client.py View on Github external
grant_type_param = "grant_type={}".format(self._grant_type)
        client_id_param = "client_id={}".format(access_token_request.client_id)
        client_secret_param = "client_secret={}".format(
            access_token_request.client_secret)

        body_params = "&".join(
            [grant_type_param, client_id_param, client_secret_param])
        if self._grant_type == self.LWA_CREDENTIALS_GRANT_TYPE:
            param_info = "refresh_token={}".format(
                access_token_request.refresh_token)
        else:
            param_info = "scope={}".format(access_token_request.scope)
        body_params += "&{}".format(param_info)
        error_definitions = list()  # type: List
        error_definitions.append(ServiceClientResponse(
            response_type=(
                "ask_sdk_model.services.lwa.access_token_response."
                "AccessTokenResponse"),
            status_code=200, message="Success"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=400,
            message="Bad Request"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=401,
            message="Authentication failed"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=500,
            message="Internal Server Error"))
github alexa / alexa-apis-for-python / ask-sdk-model / ask_sdk_model / services / lwa / lwa_client.py View on Github external
body_params = "&".join(
            [grant_type_param, client_id_param, client_secret_param])
        if self._grant_type == self.LWA_CREDENTIALS_GRANT_TYPE:
            param_info = "refresh_token={}".format(
                access_token_request.refresh_token)
        else:
            param_info = "scope={}".format(access_token_request.scope)
        body_params += "&{}".format(param_info)
        error_definitions = list()  # type: List
        error_definitions.append(ServiceClientResponse(
            response_type=(
                "ask_sdk_model.services.lwa.access_token_response."
                "AccessTokenResponse"),
            status_code=200, message="Success"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=400,
            message="Bad Request"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=401,
            message="Authentication failed"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=500,
            message="Internal Server Error"))
        error_definitions.append(ServiceClientResponse(
            response_type="ask_sdk_model.services.lwa.error.Error",
            status_code=503,
            message="Service Unavailable"))

ask-sdk-model

The ASK SDK Model package provides model definitions, for building Alexa Skills.

Apache-2.0
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis

Popular ask-sdk-model functions

Similar packages