public void authenticate(String authenticationKey, String password) {
    ActionRequestBase actionRequest = new ActionRequestBase(Api.V1.getAuthenticationURL());
    actionRequest.setPostParam("authentication_key", authenticationKey);
    actionRequest.setPostParam("password", password);
    JSONObject actionResponse = actionRequest.post();

    try {
      actionResponse = actionResponse.getJSONObject("responseObject");
      switch (actionRequest.getResponseCode()) {
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
          mAuthenticationStatus = INTERNAL_SERVER_ERROR;
          break;
        case HttpStatus.SC_OK:
          User user = new User(actionResponse.getJSONObject("user"));
          if (user.save()) {
            Session.setUser(user);
            mAuthenticationStatus = AUTHENTICATED;
          } else {
            mAuthenticationStatus = INTERNAL_SERVER_ERROR;
          }
          break;
        case HttpStatus.SC_UNPROCESSABLE_ENTITY:
          mAuthenticationStatus = INVALID_CREDENTIALS;
          mAuthenticationErrors = actionResponse.getJSONObject("errors");
          break;
      }
    } catch (JSONException jsone) {
      mAuthenticationStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }
  }
Пример #2
0
  public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

      JSONObject o = a.getJSONObject(i);
      Contact c = new Contact();
      c.unserializeJSON(o.getJSONObject("contact"));
      v.addElement(c);
    }

    contacts = new Contact[v.size()];
    v.copyInto(contacts);
  }
Пример #3
0
    public Object convertToUseForm(Object key, byte[] bytes) {
      JSONObject responseJson;

      try {
        responseJson = new JSONObject(new String(bytes));
      } catch (JSONException ex) {
        // #debug
        L.e("bytes are not a JSON object", featURL, ex);
        return null;
      }

      JSONArray entries = new JSONArray();
      final Vector vector = new Vector();

      try {
        final JSONObject feed = ((JSONObject) responseJson).getJSONObject("feed");
        entries = feed.getJSONArray("entry");
      } catch (JSONException e) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));

        // #debug
        L.e("JSON no result", featURL, e);
      }

      for (int i = 0; i < entries.length(); i++) {
        try {
          final JSONObject jsonObject = entries.getJSONObject(i);
          final String title = jsonObject.getJSONObject("title").getString("$t");
          final String author =
              jsonObject
                  .getJSONArray("author")
                  .getJSONObject(0)
                  .getJSONObject("name")
                  .getString("$t");
          final String thumbUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$thumbnail")
                  .getJSONObject(0)
                  .getString("url");
          final String imageUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$content")
                  .getJSONObject(0)
                  .getString("url");

          // #mdebug
          L.i("JSON parsed title: ", title);
          L.i("JSON parsed author: ", author);
          L.i("JSON parsed thumb url: ", thumbUrl);
          L.i("JSON parsed image url: ", imageUrl);
          // #enddebug

          vector.addElement(new PicasaImageObject(title, author, thumbUrl, imageUrl));
        } catch (JSONException e) {
          // #debug
          L.e("JSON item parse error", featURL, e);
        }
      }

      if (entries.length() == 0) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));
      }

      return vector;
    }