Class: WifiGeoLocation::Client
- Inherits:
-
Object
- Object
- WifiGeoLocation::Client
- Defined in:
- lib/wifi_geo_location/client.rb
Constant Summary collapse
- DEFAULT_HOST =
'www.googleapis.com'
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/json' }
- DEFAULT_END_POINT =
'/geolocation/v1/geolocate'
Instance Method Summary collapse
-
#initialize(key: nil) ⇒ Client
constructor
A new instance of Client.
- #post(request_params) ⇒ Object
Constructor Details
#initialize(key: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/wifi_geo_location/client.rb', line 11 def initialize(key: nil) @key = key end |
Instance Method Details
#post(request_params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wifi_geo_location/client.rb', line 15 def post(request_params) faraday = Faraday.new(url: "#{url_prefix}?key=#{@key}") response = faraday.post do |request| request.url(DEFAULT_END_POINT) request.headers['Content-Type'] = DEFAULT_HEADERS['Content-Type'] request.body = JSON.dump(request_params) end JSON.parse(response.body) end |