Profile API for Android

Follow

The class com.beemray.android.sdk.io.net.rest.api.ProfileAPI contains methods to access defined profiles and update their values. Those methods are:

ProfileAPI methods

/**
* Starts loading the profile list from the backend which contains all the
* profiles in the current account and returns the request which is executed
* or throws an IOException if any error occurs when accessing the network.
* The given listener is invoked when the response is available.
*
* @param l a listener which will be invoked when the response is available.
* @return the request which was executed.
*/
public AbstractHttpRequest list(ApiListener<List> l);
 
/**
* Loads a profile from the backend which is stored using the given name.
* The given listener is used when the profile is loaded or if any error
* occurs when fetching the data. Throws an IOException if any error occurs
* when processing the data before network access. Returns the request
* which is used to load the profile.
*
* @param name the profile name which will be loaded.
* @param l a listener which is used when there is a server response
* available.
* @return a request which loads the profile from the backend.
* @throws IOException if any error occurs when processing the data before
* the network access.
*/
public AbstractHttpRequest load (String name, ApiListener l);
 
/**
* Saves the given profile into the backend and invokes the given listener
* when the request is finished. Throws an IOException if any error occurs
* when accessing the network. Returns the request which is used to access
* the backend.
*
* @param profile a profile which will be saved.
* @param l a listener which is used when there is a server response available.
* @return a request which is used to access the backend.
* @throws IOException if any error occurs when accessing the network.
*/
public AbstractHttpRequest save (Profile profile, ApiListener l)
    throws IOException;
 
/**
* Saves the given element into backend and invokes the given listener
* when the request is finished. Throws an IOException if any error occurs
* when accessing the backend. Returns the request which is used to access
* the backend.
*
* @param el an element which will be saved into the backend.
* @param l a listener which is used when the process is over.
* @throws java.io.IOException if any error occurs when accessing the network.
*/
public AbstractHttpRequest saveElement (AbstractProfileElement el, ApiListener l)
    throws IOException;

The process of updating profile element values consists on:

1. Load a profile.
2. Update the value for each element according to user input.
3. Save either one element or the whole profile.

 

Updating profile element values example

// 1. Load profile
Api.profile.load(PROFILE_NAME, new ApiListener() {
                 
  @Override
  public void response(HttpURLConnection connection, Profile data, Throwable t) {
 
    ProfileCategory category = data.categories().get(0);
 
    // 2. Update values
    for(AbstractProfileElement<?> element : category.elements()) {
     
      if(element instanceof StringElement)
        ((StringElement)element).value({new value});
      else if(element instanceof LongElement)
        ((LongElement)element).value({new value});
      else if(element instanceof LongRangeElement)
        ((LongRangeElement)element).value({new value});
      else if(element instanceof BooleanElement)
        ((BooleanElement)element).value({new value});
      else if(element instanceof TimestampElement)
        ((TimestampElement)element).value({new value});
      else if(element instanceof TimestampRangeElement)
        ((TimestampRangeElement)element).value({new value});
 
      // 3. Save profile
      Api.profile.save(data, null);
  }
Have more questions? Submit a request

Comments