Package org.ulti.dev.powermeter.util

Examples of org.ulti.dev.powermeter.util.Client


  public void createNewVariable(String varId, String description, String title, String location, VariableType varKind) {
    String url = makeUserUrl() + "/variable";
    _log.info("URL:" + url);

    Client http = new Client();

    http.addHeader("Authorization", "AuthSub token=\"" + _authToken + "\"");
    http.setContentType("application/atom+xml");

    String uploadString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
        + "  <entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:meter=\"http://schemas.google.com/meter/2008\">" + "    <meter:variableId>"
        + varId + "</meter:variableId>" + "    <title>" + title + "</title>" + "    <content type=\"text\">" + description + "</content>"
        + "    <meter:location>" + location + "</meter:location> " + "    <meter:type>electricity_consumption</meter:type>"
        + "    <meter:unit>kW h</meter:unit>";

    if (varKind.name().equals(VariableType.CUMULATIVE.name())) {
      uploadString += "<meter:cumulative/>";
    } else if (varKind.name().equals(VariableType.DURATIONAL.name())) {
      uploadString += "<meter:durational/>";
    } else {
      throw new IllegalArgumentException("Unknown kind: " + varKind);
    }

    uploadString += "</entry>";

    String res = http.postToString(url, uploadString);

    if (http.getResult() < 200 || http.getResult() > 210) {
      _log.error("Error POST: code=" + http.getResult() + "\n" + res);

      _log.error("POST error");
      _log.error("url=" + url);
      _log.error("data:\n" + uploadString);
    } else {
View Full Code Here


  /**
   * Get a list of the variable for this account from the server.
   */
  public void getList() {
    _log.info("PowerMeterActions::getList()");
    Client http = new Client();

    String url = makeUserUrl() + "/variable";
    _log.info("URL:" + url);

    http.addHeader("Authorization", "AuthSub token=\"" + _authToken + "\"");
    http.setContentType("application/atom+xml");
    String res = http.getToString(url);

    if (http.getResult() < 200 || http.getResult() > 210) {
      System.err.println("ERROR POST: code=" + http.getResult() + "\n" + res);

      _log.error("POST request error !");
      _log.error("url=" + url);
    }

View Full Code Here

  private String makeUserUrl() {
    return BASE_URL + "user/" + _userId + "/" + _userId;
  }

  private boolean post(String url, String data) {
    Client http = new Client();

    _log.info("PowerMeterActions::post( " + url + ", ... )");

    http.addHeader("Authorization", "AuthSub token=\"" + _authToken + "\"");
    http.setContentType("application/atom+xml");

    _log.trace("POSTing data: " + data);

    Document res = http.postToXML(url, data);

    if (http.getResult() < 200 || http.getResult() > 210) {
      _log.error("POST Error - code=" + http.getResult() + ", " + res);

      _log.error("POST error");
      _log.error("url=" + url);
      _log.error("data:\n" + data);
      return false;
View Full Code Here

TOP

Related Classes of org.ulti.dev.powermeter.util.Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.