All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.backendless.BackendlessPrefs Maven / Gradle / Ivy

There is a newer version: 7.0-alpha
Show newest version
package com.backendless;

import com.backendless.exceptions.ExceptionMessage;

import java.util.Map;

/**
 * Created by dzidzoiev on 11/8/15.
 */
class BackendlessPrefs
{
  protected AuthKeys authKeys;
  protected Map headers;
  protected String url;

  public BackendlessPrefs()
  {
  }

  public void initPreferences( String applicationId, String apiKey )
  {
    this.authKeys = new AuthKeys( applicationId, apiKey );
  }

  public void setHeaders( Map headers )
  {
    this.headers = headers;
  }

  public synchronized void cleanHeaders()
  {
    headers = null;
  }

  /**
   * Should be called before init
   *
   * @param context - mandatory for android service
   */
  public void onCreate( Object context )
  {

  }

  public String getApplicationId()
  {
    return getAuthKeys().getApplicationId();
  }

  public String getApiKey()
  {
    return getAuthKeys().getApiKey();
  }

  public synchronized Map getHeaders()
  {
    return headers;
  }

  private synchronized AuthKeys getAuthKeys()
  {
    if( authKeys == null)
      throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
    
    return authKeys;
  }

  boolean isAuthKeysExist()
  {
    return authKeys != null;
  }

  public void setUrl( String url )
  {
    this.url = url;
  }

  public String getUrl()
  {
    if( this.url == null)
      throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

    return this.url;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy