Search in sources :

Example 1 with JSONObject

use of com.amazonaws.util.json.JSONObject in project amos-ss17-alexa by c-i-ber.

the class FinanceApi method getStockPrice.

public static String getStockPrice(String stock) {
    try {
        FinanceApi finance = new FinanceApi();
        String response = finance.run("http://finance.google.com/finance/info?client=ig&q=NASDAQ:" + stock);
        response = response.substring(5, response.length() - 2);
        //create a JSON-Object of the String
        final JSONObject obj = new JSONObject(response);
        // read out the current stock price
        //Gson gson = new Gson();
        JsonObject jsonObject = new JsonParser().parse(response).getAsJsonObject();
        // JsonObject jsonObject = new JsonParser().parse("{\"pcls_fix\": \"68.38\"}").getAsJsonObject();
        String stockPrice = jsonObject.get("pcls_fix").getAsString();
        return stockPrice;
    } catch (IOException io) {
        System.out.println("Error: " + io);
    } catch (JSONException json) {
        System.out.println("Error: " + json);
    }
    return null;
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) JsonObject(com.google.gson.JsonObject) JSONException(com.amazonaws.util.json.JSONException) IOException(java.io.IOException) JsonParser(com.google.gson.JsonParser)

Example 2 with JSONObject

use of com.amazonaws.util.json.JSONObject in project amos-ss17-alexa by c-i-ber.

the class SavingsPlanDialog method createSavingsPlanOneOffPayment.

private void createSavingsPlanOneOffPayment(String betrag) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("amount", betrag);
        //TODO Hard coded savings account?
        jsonObject.put("sourceAccount", "DE42100000009999999999");
        jsonObject.put("destinationAccount", "DE39100000007777777777");
        jsonObject.put("valueDate", "2017-05-24");
        jsonObject.put("description", "Savings Plan");
    } catch (JSONException e) {
        LOGGER.error(e.getMessage());
    }
    BankingRESTClient bankingRESTClient = BankingRESTClient.getInstance();
    //TODO Post mapped to Object.class
    bankingRESTClient.postBankingModelObject("/api/v1_0/transactions", jsonObject.toString(), Object.class);
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) JSONException(com.amazonaws.util.json.JSONException) BankingRESTClient(api.BankingRESTClient)

Example 3 with JSONObject

use of com.amazonaws.util.json.JSONObject in project zeppelin by apache.

the class ZeppelinhubClient method runAllParagraph.

boolean runAllParagraph(String noteId, String hubMsg) {
    LOG.info("Running paragraph with noteId {}", noteId);
    try {
        JSONObject data = new JSONObject(hubMsg);
        if (data.equals(JSONObject.NULL) || !(data.get("data") instanceof JSONArray)) {
            LOG.error("Wrong \"data\" format for RUN_NOTEBOOK");
            return false;
        }
        Client client = Client.getInstance();
        if (client == null) {
            LOG.warn("Base client isn't initialized, returning");
            return false;
        }
        Message zeppelinMsg = new Message(OP.RUN_PARAGRAPH);
        JSONArray paragraphs = data.getJSONArray("data");
        for (int i = 0; i < paragraphs.length(); i++) {
            if (!(paragraphs.get(i) instanceof JSONObject)) {
                LOG.warn("Wrong \"paragraph\" format for RUN_NOTEBOOK");
                continue;
            }
            zeppelinMsg.data = gson.fromJson(paragraphs.getString(i), new TypeToken<Map<String, Object>>() {
            }.getType());
            client.relayToZeppelin(zeppelinMsg, noteId);
            LOG.info("\nSending RUN_PARAGRAPH message to Zeppelin ");
        }
    } catch (JSONException e) {
        LOG.error("Failed to parse RUN_NOTEBOOK message from ZeppelinHub ", e);
        return false;
    }
    return true;
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) JSONArray(com.amazonaws.util.json.JSONArray) JSONException(com.amazonaws.util.json.JSONException) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Map(java.util.Map)

Example 4 with JSONObject

use of com.amazonaws.util.json.JSONObject in project amos-ss17-alexa by c-i-ber.

the class AccountFactory method createAccount.

public Account createAccount(String number, Double balance, String openingDate) throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("number", number);
    jsonObject.put("balance", balance);
    jsonObject.put("openingDate", openingDate);
    BankingRESTClient bankingRESTClient = BankingRESTClient.getInstance();
    return (Account) bankingRESTClient.postBankingModelObject("/api/v1_0/accounts/generate", jsonObject.toString(), Account.class);
}
Also used : Account(model.banking.account.Account) JSONObject(com.amazonaws.util.json.JSONObject) BankingRESTClient(api.BankingRESTClient)

Example 5 with JSONObject

use of com.amazonaws.util.json.JSONObject in project amos-ss17-alexa by c-i-ber.

the class SavingsPlanDialog method createSavingsPlanStandingOrder.

private void createSavingsPlanStandingOrder(String monatlicheZahlung) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("payee", "Max Mustermann");
        jsonObject.put("amount", monatlicheZahlung);
        //TODO Hard coded savings account?
        jsonObject.put("destinationAccount", "DE39100000007777777777");
        jsonObject.put("firstExecution", "2017-06-01");
        jsonObject.put("executionRate", "MONTHLY");
        jsonObject.put("description", "Savings Plan");
    } catch (JSONException e) {
        LOGGER.error(e.getMessage());
    }
    BankingRESTClient bankingRESTClient = BankingRESTClient.getInstance();
    bankingRESTClient.postBankingModelObject("/api/v1_0/accounts/9999999999/standingorders", jsonObject.toString(), StandingOrder.class);
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) JSONException(com.amazonaws.util.json.JSONException) BankingRESTClient(api.BankingRESTClient)

Aggregations

JSONObject (com.amazonaws.util.json.JSONObject)8 JSONException (com.amazonaws.util.json.JSONException)7 BankingRESTClient (api.BankingRESTClient)4 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)1 SimpleCard (com.amazon.speech.ui.SimpleCard)1 JSONArray (com.amazonaws.util.json.JSONArray)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 Account (model.banking.account.Account)1 NutchField (org.apache.nutch.indexer.NutchField)1 ZeppelinhubMessage (org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)1