<commit_before>package edu.oregonstate.mist.alexa

import com.codahale.metrics.annotation.Timed
import edu.oregonstate.mist.alexa.core.AlexaResponse
import edu.oregonstate.mist.alexa.core.OutputSpeech
import edu.oregonstate.mist.alexa.core.Response
import edu.oregonstate.mist.alexa.db.TermsDAO
import edu.oregonstate.mist.api.Resource

import javax.annotation.security.PermitAll
import javax.ws.rs.Consumes
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Path("alexa")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@groovy.transform.TypeChecked
class AlexaResource extends Resource {
    TermsDAO termsDAO

    AlexaResource(TermsDAO termsDAO) {
        this.termsDAO = termsDAO
    }

    @POST
    @Path("terms/open")
    AlexaResponse openTerms() {
        def openTerms = termsDAO.getOpenTerms()
        new  AlexaResponse(
                response: new Response(
                        outputSpeech: new OutputSpeech(
                                type: "PlainText",
                                text: openTerms
                        )
                )
        )
    }

    @Timed
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    AlexaResponse bennySkill(def alexaRequest) {
        String intent = alexaRequest["request"]["intent"]["name"].toString()
        String responseSpeech = "I don't know what your intent was."

        switch (intent) {
            case "HelloWorld": responseSpeech = "Hello hackathon 2017!"
                break
            case "Terms": responseSpeech = "I will tell you terms when we implement it."
                break
        }

        new AlexaResponse(
                response: new Response(
                        outputSpeech: new OutputSpeech(
                                type: "PlainText",
                                text: responseSpeech
                        )<commit_msg>Fix Terms intent and remove unneccesary openTerms endpoint<commit_after>package edu.oregonstate.mist.alexa

import com.codahale.metrics.annotation.Timed
import edu.oregonstate.mist.alexa.core.AlexaResponse
import edu.oregonstate.mist.alexa.core.OutputSpeech
import edu.oregonstate.mist.alexa.core.Response
import edu.oregonstate.mist.alexa.db.TermsDAO
import edu.oregonstate.mist.api.Resource

import javax.annotation.security.PermitAll
import javax.ws.rs.Consumes
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Path("alexa")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@groovy.transform.TypeChecked
class AlexaResource extends Resource {
    TermsDAO termsDAO

    AlexaResource(TermsDAO termsDAO) {
        this.termsDAO = termsDAO
    }

    @Timed
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    AlexaResponse bennySkill(def alexaRequest) {
        String intent = alexaRequest["request"]["intent"]["name"].toString()
        String responseSpeech = "I don't know what your intent was."

        switch (intent) {
            case "HelloWorld": responseSpeech = "Hello hackathon 2017!"
                break
            case "Terms": responseSpeech = termsDAO.getOpenTerms()
                break
        }

        new AlexaResponse(
                response: new Response(
                        outputSpeech: new OutputSpeech(
                                type: "PlainText",
                                text: responseSpeech
                        )
{'fraction_non_alphanumeric': 0.08441746169413125, 'fraction_numerical': 0.0023128071697022263, 'mean_word_length': 2.2366697848456503, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1371880', 'n_tokens_mistral': 1063, 'n_tokens_neox': 999, 'n_words': 202}