use of com.amazonaws.util.json.JSONException 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.JSONException 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.JSONException 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.JSONException in project ice by Netflix.
the class EddaResourceService method getResource.
@Override
public String getResource(Account account, Region region, Product product, String resourceId, String[] lineItem, long millisStart) {
// currently we support ec2
if (Product.ec2.equals(product) || Product.ec2_instance.equals(product)) {
if (StringUtils.isEmpty(resourceId)) {
logger.warn("Had empty resourceId");
return "Error";
}
try {
JSONArray instances = readInstanceArray();
boolean found = false;
for (int i = 0; i < instances.length(); i++) {
String instance = instances.getString(i);
if (resourceId.equals(instance)) {
found = true;
break;
}
}
if (!found) {
logger.warn("Did not find resourceId in edda: " + resourceId);
return "Unknown";
}
InputStream stream = new URL(EDDA_ROOT_URL + "view/instances/" + resourceId).openStream();
final String json;
try {
json = IOUtils.toString(stream);
} finally {
stream.close();
}
JSONObject object = new JSONObject(json);
JSONArray tags = object.getJSONArray("tags");
for (int i = 0; i < tags.length(); i++) {
JSONObject tag = tags.getJSONObject(i);
String key = tag.getString("key");
if (key.equals(EDDA_TAG_NAME)) {
String usage = tag.getString("value");
logger.debug("Found usage: " + usage + " for resource " + resourceId);
return usage;
}
}
logger.debug("Did not find tag 'Usage' for resource " + resourceId);
return "Unknown";
} catch (JSONException e) {
logger.warn("error parsing json", e);
return "Error";
} catch (MalformedURLException e) {
logger.warn("error parsing url", e);
return "Error";
} catch (IOException e) {
logger.warn("error fetching data from edda at " + EDDA_ROOT_URL, e);
return "Error";
}
}
logger.debug("Product: " + product + " not handled, resourceId: " + resourceId);
//logger.info("get resource for account " + account + " region " + region + " product " + product + " resource: " + resourceId + " lineItem: " + Arrays.toString(lineItem));
return super.getResource(account, region, product, resourceId, lineItem, millisStart);
}
use of com.amazonaws.util.json.JSONException 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