Class: YandexLocator::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex_locator/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



3
4
5
# File 'lib/yandex_locator/client.rb', line 3

def initialize
  @conn = YandexLocator::API.call
end

Instance Method Details

#insert_data(ip:, mac:, cellid:, lac:, signal_strength:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yandex_locator/client.rb', line 17

def insert_data(ip: , mac: , cellid: , lac: , signal_strength:)
  {common:
    {version: YandexLocator.configuration.version,
     api_key: YandexLocator.configuration.api_key
    },
    ip: {
      address_v4: ip
    },
    wifi_networks: [
      {
        mac: mac
      },
      gsm_cells: [
        {
          cellid: cellid,
          lac: lac,
          signal_strength: signal_strength,
        }
      ]
    ]
  }
end

#lookup(ip: nil, mac: nil, cellid: nil, lac: nil, signal_strength: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/yandex_locator/client.rb', line 7

def lookup(ip: nil, mac: nil, cellid: nil, lac: nil, signal_strength: nil)
  result = @conn.post do |req|
    req.url '/geolocation'
    req.headers['Content-Type'] = 'application/json'
    req.params['json'] = insert_data(ip: ip, mac: mac, cellid: cellid, lac: lac, signal_strength: signal_strength).to_json
  end

  JSON.parse(result.body)
end