Class: DeviceAtlas::Carrier::CarrierApi

Inherits:
Object
  • Object
show all
Defined in:
lib/deviceatlas/carrier/carrier_api.rb

Direct Known Subclasses

CarrierApiWeb

Constant Summary collapse

API_VERSION =
'2.1.0'
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.

%w[
  x-forwarded-for
  client-ip
  x-client-ip
  rlnclientipaddr
  proxy-client-ip
  wl-proxy-client-ip
  x-forwarded
  forwarded-for
  forwarded
].freeze

Instance Method Summary collapse

Constructor Details

#initializeObject

Creates a new DeviceAtlas::Carrier::CarrierApi instance.

Examples:

Create an object

carrier_api = DeviceAtlas::Carrier::CarrierApi.new

Instance Method Details

#get_api_versionString

Get the version of the Carrier API.

Returns:

Get the carrier data file copyright.

Returns:

  • (String)

    the copyright of the Carrier data file

Raises:

#get_data_file_creation_dateString

Get the carrier data file creation date.

Returns:

  • (String)

    the creation date of the Carrier data file

Raises:

#get_data_file_versionString

Get the carrier data file version.

Returns:

  • (String)

    the version of the Carrier data file

Raises:

#get_ip(key_vals) ⇒ Object

Get the most suitable IP address from the given key_vals set of HTTP headers. This function checks the headers defined in HEADERS_TO_CHECK.

#get_properties(data) ⇒ Object

Get the Carrier properties for a given IP address or a given Hash of HTTP headers.

#get_property(data, property_name) ⇒ Object

Try and get a specific property for a given IP address or a given Hash of HTTP headers. In case a Hash of HTTP headers is passed, the API will choose the most appropriate IP to use.

NOTE: if multiple properties are needed for the same IP, it is more efficient to call get_properties() once than repeated calls to get_property().

Parameters:

  • data (String, Hash<String, String>)

    the IP address or a set of HTTP headers

  • property_name (String)

    the property or nil if no property found

Raises:

#get_property_namesObject

A set of all the possible property names. The Set contains objects that each have a name and an associated data type.

return

Array of possible property names.

#load_data_from_file(path) ⇒ Object

Load the Carrier data file from the provided `path`. The data file is reloaded every time this method is called.

Examples:

Load the DeviceAtlas Carrier data file

carrier_api = DeviceAtlas::Carrier::CarrierApi.new
carrier_api.load_data_from_file('/path/to/data.dat')

Parameters:

  • path (String)

    the path to the DeviceAtlas Carrier data file

Raises:

#public_ip?(ip_str) ⇒ Boolean

Check if an IP address is public.

Parameters:

  • ip_str (String)

    the IP address

Returns:

  • (Boolean)

    whether the IP address is public or not