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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations