CloudPlugs REST Library  1.0.0
for Android
Opts Class Reference

An instance of this class contains all the options for connecting and making requests to the server, including the authentication credentials required for most HTTP requests. This class mainly offers getter and setter methods to manage all the options. More...

Public Member Functions

 Opts ()
 
 Opts (JSONObject jso)
 
 Opts (String json)
 
 Opts (Opts opts)
 
String getUrl ()
 
Opts setUrl (String url)
 
boolean hasSSL ()
 
Opts enableSSL (boolean enable)
 
boolean hasAuth ()
 
String getAuthId ()
 
String getAuthPass ()
 
boolean isAuthMaster ()
 
boolean hasAuthDevice ()
 
boolean hasAuthEmail ()
 
Opts setAuth (String id, String pass, boolean master)
 
Opts setAuth (String id, String pass)
 
int getTimeout ()
 
Opts setTimeout (int timeout)
 
Opts fromOpts (Opts opts)
 
Opts fromString (String json)
 
Opts fromJSON (String json)
 
Opts fromJSON (JSONObject jso)
 
JSONObject toJSON ()
 
String toString ()
 

Static Public Attributes

static final String K_AUTHID = "authId"
 
static final String K_AUTHPASS = "authPass"
 
static final String K_AUTHMASTER = "authMaster"
 
static final String K_URL = "url"
 
static final String K_TIMEOUT = "timeout"
 
static final boolean DEF_SSL = Const.DEFAULT_URL.startsWith("https")
 
static final String DEF_URL = makeUrl(Const.DEFAULT_URL, DEF_SSL)
 
static final int DEF_TIMEOUT = Const.DEFAULT_TIMEOUT
 
static final String DEF_AUTHID = Const.DEFAULT_AUTHID
 
static final String DEF_AUTHPASS = Const.DEFAULT_AUTHPASS
 
static final boolean DEF_AUTHMASTER = Const.DEFAULT_MASTER
 

Detailed Description

An instance of this class contains all the options for connecting and making requests to the server, including the authentication credentials required for most HTTP requests. This class mainly offers getter and setter methods to manage all the options.

Constructor & Destructor Documentation

◆ Opts() [1/4]

Opts ( )

Create a new instance using all the default values.

◆ Opts() [2/4]

Opts ( JSONObject  jso)

Create a new instance using the options in the specified instance of org.json.JSONObject.

Parameters
jsothe JSON object to import
Exceptions
RestExceptionfor invalid argument

◆ Opts() [3/4]

Opts ( String  json)

Create a new instance using the options in the specified JSON string.

Parameters
jsonthe JSON string to import
Exceptions
RestExceptionfor invalid argument

◆ Opts() [4/4]

Opts ( Opts  opts)

Create a new instance by cloning the specified options

Parameters
optsthe options to clone
Exceptions
java.lang.NullPointerExceptionfor null argument

Member Function Documentation

◆ enableSSL()

Opts enableSSL ( boolean  enable)

Enable or disable SSL connection by changing the connection URL.

Parameters
enabletrue to enable SSL, false to disable it
Returns
this instance

◆ fromJSON() [1/2]

Opts fromJSON ( String  json)

Import options from a JSON string.

Parameters
jsonthe JSON string to import
Returns
this instance
Exceptions
IllegalArgumentExceptionfor invalid JSON

◆ fromJSON() [2/2]

Opts fromJSON ( JSONObject  jso)

Import options from a JSON object.

Parameters
jsothe org.json.JSONObject to import
Returns
this instance
Exceptions
IllegalArgumentExceptionif fails

◆ fromOpts()

Opts fromOpts ( Opts  opts)

Import options from another Opts instance.

Parameters
optsthe options to import
Returns
this instance
Exceptions
NullPointerExceptionif the argument is null

◆ fromString()

Opts fromString ( String  json)

Alias of fromJSON(String).

Parameters
jsonthe JSON string to import
Returns
this instance
Exceptions
IllegalArgumentExceptionfor invalid JSON

◆ getAuthId()

String getAuthId ( )

Authentication identifier getter.

Returns
the current authentication identifier

◆ getAuthPass()

String getAuthPass ( )

Authentication password getter.

Returns
the current authentication password

◆ getTimeout()

int getTimeout ( )

Connection timeout getter.

Returns
the current connection timeout in seconds

◆ getUrl()

String getUrl ( )

Connection URL option getter.

Returns
the current connection URL string

◆ hasAuth()

boolean hasAuth ( )
Returns
true if this instance contains authentication id and password

◆ hasAuthDevice()

boolean hasAuthDevice ( )
Returns
true if using a PlugID as authentication identifier

◆ hasAuthEmail()

boolean hasAuthEmail ( )
Returns
true if using an email as authentication identifier

◆ hasSSL()

boolean hasSSL ( )
Returns
true if the currenct connection URL is using HTTPS, false if using plain HTTP

◆ isAuthMaster()

boolean isAuthMaster ( )
Returns
true if using master authentication

◆ setAuth() [1/2]

Opts setAuth ( String  id,
String  pass,
boolean  master 
)

Authentication setter.

Parameters
idthe authentication identifier to set
passthe authentication password to set
mastertrue if the given pass is a master password
Returns
this instance

◆ setAuth() [2/2]

Opts setAuth ( String  id,
String  pass 
)

Authentication setter using the default master setting.

Parameters
idthe authentication identifier to set
passthe authentication password to set
Returns
this instance

◆ setTimeout()

Opts setTimeout ( int  timeout)

Connection timeout setter.

Parameters
timeoutthe connection timeout (in seconds) to set
Returns
this instance

◆ setUrl()

Opts setUrl ( String  url)

Connection URL option setter.

Parameters
urlthe new connection URL to use
Returns
this instance
Exceptions
RestExceptionfor invalid url

◆ toJSON()

JSONObject toJSON ( )

Export this instance as a JSON object.

Returns
a new instance of org.json.JSONObject equivalent to this instance
Exceptions
RestExceptionif fails

◆ toString()

String toString ( )

Export this instance as a JSON string.

Returns
the JSON string equivalent to this instance
Exceptions
RestExceptionif fails

Member Data Documentation

◆ DEF_AUTHID

final String DEF_AUTHID = Const.DEFAULT_AUTHID
static

The default authentication identifier.

◆ DEF_AUTHMASTER

final boolean DEF_AUTHMASTER = Const.DEFAULT_MASTER
static

The default master authentication.

◆ DEF_AUTHPASS

final String DEF_AUTHPASS = Const.DEFAULT_AUTHPASS
static

The default authentication password.

◆ DEF_SSL

final boolean DEF_SSL = Const.DEFAULT_URL.startsWith("https")
static

The default SSL state: true if enabled, otherwise disabled.

◆ DEF_TIMEOUT

final int DEF_TIMEOUT = Const.DEFAULT_TIMEOUT
static

The default connection timeout.

◆ DEF_URL

final String DEF_URL = makeUrl(Const.DEFAULT_URL, DEF_SSL)
static

The default connection url, it is the official CloudPlugs server.

◆ K_AUTHID

final String K_AUTHID = "authId"
static

Key name of authentication identifier when importing or exporting options to JSON.

◆ K_AUTHMASTER

final String K_AUTHMASTER = "authMaster"
static

Key name of master authentication when importing or exporting options to JSON.

◆ K_AUTHPASS

final String K_AUTHPASS = "authPass"
static

Key name of authentication password when importing or exporting options to JSON.

◆ K_TIMEOUT

final String K_TIMEOUT = "timeout"
static

Key name of connection timeout when importing or exporting options to JSON.

◆ K_URL

final String K_URL = "url"
static

Key name of connection url when importing or exporting options to JSON.