Пример #1
0
def buy_intent(product_name):
    products = Product(context.System.apiAccessToken)
    logger.info("PRODUCT: {}".format(product_name))
    buy_card = render_template('buy_card', product=product_name)
    productId = products.productId(product_name)
    if productId is not None:
        session.attributes[PRODUCT_KEY] = productId
    else:
        return statement("I didn't find a product {}".format(product_name))
        raise NotImplementedError()
    return buy(productId).simple_card('Welcome', question_text)
Пример #2
0
def refund_intent(product_name):
    refund_card = render_template('refund_card')
    logger.info("PRODUCT: {}".format(product_name))

    products = Product(context.System.apiAccessToken)
    productId = products.productId(product_name)

    if productId is not None:
        session.attributes[PRODUCT_KEY] = productId
    else:
        raise NotImplementedError()
    return refund(productId)
Пример #3
0
def play_radio(radioname):
    if not radioname:
        logger.info('PlayRadioIntent: Empty intent slot')
        return statement('Sorry, I do not understand the name of this Radio.')
    radio = find_radio(radioname)
    if not radio:
        logger.info('PlayRadioIntent: Cannot find radio {}'.format(radioname))
        msg = 'Sorry, I cannot find the radio {}'.format(radioname)
        return statement(msg).simple_card('French Radio', msg)
    (radio, info) = radio
    msg = 'Playing {}'.format(radio)
    resp = audio(msg).play(info['url']).simple_card(msg)
    return resp
Пример #4
0
    def query(self):
        # Information required to invoke the API is available in the session
        apiEndpoint = "https://api.amazonalexa.com"
        apiPath = "/v1/users/~current/skills/~current/inSkillProducts"
        token = "bearer " + self.token
        language = "en-US"  # self.event.request.locale

        url = apiEndpoint + apiPath
        headers = {
            "Content-Type": "application/json",
            "Accept-Language": language,
            "Authorization": token,
        }
        # Call the API
        res = requests.get(url, headers=headers)
        logger.info("PRODUCTS:" + "*" * 80)
        logger.info(res.status_code)
        logger.info(res.text)
        if res.status_code == 200:
            data = json.loads(res.text)
            return data["inSkillProducts"]
        else:
            return None
Пример #5
0
    def query(self):
        # Information required to invoke the API is available in the session
        apiEndpoint = context.System.apiEndpoint
        apiPath = "/v1/users/~current/skills/~current/inSkillProducts"
        token = "bearer " + self.token
        language = request.locale

        url = apiEndpoint + apiPath
        headers = {
            "Content-Type": 'application/json',
            "Accept-Language": language,
            "Authorization": token
        }
        #Call the API
        res = requests.get(url, headers=headers)
        logger.info('PRODUCTS:' + '*' * 80)
        logger.info(res.status_code)
        logger.info(res.text)
        if res.status_code == 200:
            data = json.loads(res.text)
            return data['inSkillProducts']
        else:
            return None
Пример #6
0
    def query(self):
        # Information required to invoke the API is available in the session
        apiEndpoint = "https://api.amazonalexa.com"
        apiPath     = "/v1/users/~current/skills/~current/inSkillProducts"
        token       = "bearer " + self.token
        language    = "en-US" #self.event.request.locale

        url = apiEndpoint + apiPath
        headers = {
                "Content-Type"      : 'application/json',
                "Accept-Language"   : language,
                "Authorization"     : token
            }
        #Call the API
        res = requests.get(url, headers=headers)
        logger.info('PRODUCTS:' + '*' * 80)
        logger.info(res.status_code)
        logger.info(res.text)
        if res.status_code == 200:
            data = json.loads(res.text)
            return data['inSkillProducts']
        else:
            return None        
Пример #7
0
def _infodump(obj, indent=2):
    msg = json.dumps(obj, indent=indent)
    logger.info(msg)
Пример #8
0
def completed(payload, name, status, token):
    products = Product(context.System.apiAccessToken)
    logger.info('on-purchase-completed {}'.format( request))
    logger.info('payload: {} {}'.format(payload.purchaseResult, payload.productId))
    logger.info('name: {}'.format(name))
    logger.info('token: {}'.format(token))
    logger.info('status: {}'.format( status.code == 200))
    product_name = products.productName(payload.productId)
    logger.info('Product name'.format(product_name))
    if status.code == '200' and ('ACCEPTED' in payload.purchaseResult):
        return question('To listen it just say - play {} '.format(product_name))
    else:      
        return question('Do you want to buy another product?')
Пример #9
0
def started(offset, token, url):
    logger.info('Started to play {}; offset: {}'.format(url, offset))
    return "{}", 200
Пример #10
0
def completed(payload, name, status, token):
    products = Product(context.System.apiAccessToken)
    logger.info("on-purchase-completed {}".format(request))
    logger.info("payload: {} {}".format(payload.purchaseResult,
                                        payload.productId))
    logger.info("name: {}".format(name))
    logger.info("token: {}".format(token))
    logger.info("status: {}".format(status.code == 200))
    product_name = products.productName(payload.productId)
    logger.info("Product name".format(product_name))
    if status.code == "200" and ("ACCEPTED" in payload.purchaseResult):
        return question(
            "To listen it just say - play {} ".format(product_name))
    else:
        return question("Do you want to buy another product?")
Пример #11
0
def _infodump(obj, indent=2):
    msg = json.dumps(obj, indent=indent)
    logger.info(msg)