The DeviceAtlas CarrierApi documentation
Public Member Functions | List of all members
Mobi.Mtld.DA.Carrier.CarrierApiWeb Class Reference

More...

Inheritance diagram for Mobi.Mtld.DA.Carrier.CarrierApiWeb:
Mobi.Mtld.DA.Carrier.CarrierApi

Public Member Functions

Properties GetProperties ()
 Get the Carrier properties for the current client. The most suitable client IP is extracted and used to lookup the Carrier properties. More...
 
Properties GetProperties (HttpRequest request)
 Get the Carrier properties for the given HttpWebRequest object. The most suitable client IP is extracted and used to lookup the Carrier properties. More...
 
Property GetProperty (string propertyName)
 
Property GetProperty (HttpRequest request, string propertyName)
 
- Public Member Functions inherited from Mobi.Mtld.DA.Carrier.CarrierApi
 CarrierApi ()
 Construct a Carrier API object More...
 
 CarrierApi (string path)
 Construct a Carrier API object and Load the data file from the provided path. More...
 
string GetDeviceAtlasApiVersion ()
 Get CarrierApi version. More...
 
void LoadDataFromFile (string path)
 Load the data file from the provided path. The data file is reloaded every time this method is called. More...
 
virtual void DownloadAndLoadDataFile (DataFileConfig dataFileConfig)
 Downloads and loads the DeviceAtlas carrier detection data into the API. The data file is downloaded from the DeviceAtlas web-site. More...
 
virtual void DownloadAndLoadDataFile (string dataFileDownloadUrl)
 Downloads and loads the DeviceAtlas carrier detection data into the API. The data file is downloaded from the DeviceAtlas web-site. More...
 
string GetDataFileCopyright ()
 Returns the data file copyright text. More...
 
string GetDataFileCreationDate ()
 Returns the data file creation date in ISO8601 format. More...
 
string GetDataFileVersion ()
 Returns the version of the data file. More...
 
Properties GetProperties (string ipv4)
 Get the Carrier properties for a given IP address. More...
 
Properties GetProperties (Dictionary< string, string > keyVals)
 
Property GetProperty (string ipv4, string propertyName)
 
Property GetProperty (Dictionary< string, string > keyVals, string propertyName)
 
ReadOnlyCollection< PropertyNameGetPropertyNames ()
 A set of all the possible property names. The Set contains PropertyName objects that each have a string name and an associated data type. More...
 
string GetIp (Dictionary< string, string > keyVals)
 Get the most suitable IP address from the given keyVals set of HTTP headers. This function checks the headers defined in HEADERS_TO_CHECK. More...
 
string ExtractIp (string headerName, string headerValue)
 

Additional Inherited Members

- Static Public Member Functions inherited from Mobi.Mtld.DA.Carrier.CarrierApi
static string GetApiVersion ()
 Get CarrierApi version. More...
 
static bool IsPublicIp (string ipStr)
 An IP address is considered public if it is not in any of the following ranges: More...
 
- Static Public Attributes inherited from Mobi.Mtld.DA.Carrier.CarrierApi
static readonly string API_VERSION = "CARRIER_API_VERSION"
 
static readonly string [] HEADERS_TO_CHECK
 A list of HTTP headers to choose the original client IP address from. In addition to these the RemoteAddr (REMOTE_ADDR) is also used as a final fallback. More...
 

Detailed Description

A small extension to the core CarrierApi to get IP from HttpRequest for current client or permit passing of an HttpRequest object.

The GetProperties() and GetProperty() methods in this class extract the most suitable client IP.

Example usage:

<%
CarrierApiWeb carrierApi = new CarrierApiWeb();
// loading data can be slow - it is recommended wrap the API in a Singleton.
carrierApi.LoadDataFromFile("/path/to/sample.dat");
// get all properties for current client
Properties props = carrierApi.GetProperties(request);
// .... use the properties ....
if (props.ContainsKey("networkOperator")
{
string operatorName = props.Get("networkOperator").AsString();
}
// get a single property
Property countryProp = carrierApi.GetProperty("countryCode");
if (countryProp != null)
{
string countryCode = countryProp.AsString();
}
</summary>
Author
DeviceAtlas Limited

Member Function Documentation

◆ GetProperties() [1/2]

Properties Mobi.Mtld.DA.Carrier.CarrierApiWeb.GetProperties ( )
inline

Get the Carrier properties for the current client. The most suitable client IP is extracted and used to lookup the Carrier properties.

Returns
The found properties or null of no properties found.

◆ GetProperties() [2/2]

Properties Mobi.Mtld.DA.Carrier.CarrierApiWeb.GetProperties ( HttpRequest  request)
inline

Get the Carrier properties for the given HttpWebRequest object. The most suitable client IP is extracted and used to lookup the Carrier properties.

Parameters
requestThe request object to find the most suitable IP from.
Returns
The found properties or null of no properties found.

◆ GetProperty() [1/2]

Property Mobi.Mtld.DA.Carrier.CarrierApiWeb.GetProperty ( string  propertyName)
inline

Get a specific Property from the current client IP found. The most suitable client IP is extracted from the HttpWebRequest object.

Note: if multiple properties are needed for the same IP it is more efficient to call GetProperties() once than repeated calls to GetProperty().

Parameters
propertyName The name of the property to return
Returns
The found property or null of no property found.
Exceptions
InvalidPropertyNameExceptionThrown if the property name does not exist.

◆ GetProperty() [2/2]

Property Mobi.Mtld.DA.Carrier.CarrierApiWeb.GetProperty ( HttpRequest  request,
string  propertyName 
)
inline

Get a specific Property from the IP found in the HttpWebRequest object. The most suitable client IP is extracted from the HttpWebRequest object.

Note: if multiple properties are needed for the same IP it is more efficient to call GetProperties() once than repeated calls to GetProperty().

Parameters
requestThe request object to find the most suitable IP from.
propertyName The name of the property to return
Returns
The found property or null of no property found.
Exceptions
InvalidPropertyNameExceptionThrown if the property name does not exist.

The documentation for this class was generated from the following file: