Class: Api::V5::UserIpLocationsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::UserIpLocationsController
- Includes:
- Concerns::Authorization
- Defined in:
- app/controllers/api/v5/user_ip_locations_controller.rb
Overview
API to get user location (country) from user IP address
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/api/v5/user_ip_locations_controller.rb', line 7 def index expires_in 24.hours, public: true render json: { country_id: 218, country_name: 'Thailand' } # TODO: restore this code when we have expanded to other countries # ip = request.remote_ip # response = DefaultFaradayClient.create_faraday_connection.get("#{AdminSetting.geo_ip_host}?ip=#{ip}") # reponse_body = JSON.parse(response.body) # return render_default_json if reponse_body['success'] == false # if reponse_body['success'] == true # response_iso_code = reponse_body['country']['iso_code'] # alpha_hash = fetch_countries.pluck(0, 2).to_h # country_id = alpha_hash.key(response_iso_code) # return render_default_json if country_id.nil? # country_name = fetch_countries.pluck(0, 1).to_h[country_id] # render json: { country_id: country_id, country_name: country_name } # end # rescue StandardError # render_default_json end |