Class: Kameleoon::Geolocation

Inherits:
DuplicationUnsafeData show all
Defined in:
lib/kameleoon/data/geolocation.rb

Overview

Geolocation contains the visitor’s geolocation details

Instance Attribute Summary collapse

Attributes inherited from Data

#instance

Instance Method Summary collapse

Methods inherited from Data

#mark_as_sent, #mark_as_transmitting, #mark_as_unsent, #sent, #transmitting, #unsent

Constructor Details

#initialize(country, region = nil, city = nil, postal_code = nil, latitude = Float::NAN, longitude = Float::NAN) ⇒ Geolocation

Returns a new instance of Geolocation.

Parameters:

  • country (String)

    Country of visitor’s geolocation. Required

  • region (String) (defaults to: nil)

    Region of visitor’s geolocation. Optional

  • city (String) (defaults to: nil)

    City of visitor’s geolocation. Optional

  • postal_code (String) (defaults to: nil)

    Postal code of visitor’s geolocation. Optional

  • latitude (Float) (defaults to: Float::NAN)

    Latitude of visitor’s geolocation. Optional

  • longitude (Float) (defaults to: Float::NAN)

    Longitude of visitor’s geolocation. Optional



19
20
21
22
23
24
25
26
27
# File 'lib/kameleoon/data/geolocation.rb', line 19

def initialize(country, region = nil, city = nil, postal_code = nil, latitude = Float::NAN, longitude = Float::NAN)
  super(DataType::GEOLOCATION)
  @country = country
  @region = region
  @city = city
  @postal_code = postal_code
  @latitude = latitude
  @longitude = longitude
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def country
  @country
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def longitude
  @longitude
end

#postal_codeObject (readonly)

Returns the value of attribute postal_code.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def postal_code
  @postal_code
end

#regionObject (readonly)

Returns the value of attribute region.



6
7
8
# File 'lib/kameleoon/data/geolocation.rb', line 6

def region
  @region
end

Instance Method Details

#obtain_full_post_text_lineObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kameleoon/data/geolocation.rb', line 29

def obtain_full_post_text_line
  params = {
    eventType: 'staticData',
    nonce: nonce
  }
  params[:country] = @country if @country.is_a?(String)
  params[:region] = @region if @region.is_a?(String)
  params[:city] = @city if @city.is_a?(String)
  params[:postalCode] = @postal_code if @postal_code.is_a?(String)
  params[:latitude] = @latitude if valid_number?(@latitude)
  params[:longitude] = @longitude if valid_number?(@longitude)
  Kameleoon::Network::UriHelper.encode_query(params)
end

#to_sObject



8
9
10
11
# File 'lib/kameleoon/data/geolocation.rb', line 8

def to_s
  "Geolocation{country:'#{@country}',region:'#{@region}',city:'#{@city}',postal_code:'#{@postal_code}'," \
    "latitude:#{@latitude},longitude:#{@longitude}}"
end