Module: LiveLocation
- Defined in:
- lib/live_location.rb,
lib/live_location/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- API_URL =
'https://ipinfo.io/json'- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.city ⇒ Object
22 23 24 |
# File 'lib/live_location.rb', line 22 def self.city fetch['city'] end |
.country ⇒ Object
30 31 32 |
# File 'lib/live_location.rb', line 30 def self.country fetch['country'] end |
.fetch ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/live_location.rb', line 9 def self.fetch uri = URI(API_URL) response = Net::HTTP.get_response(uri) unless response.is_a?(Net::HTTPSuccess) raise Error, "Failed to fetch data from API: #{response.code} #{response.message}" end JSON.parse(response.body) rescue StandardError => e raise Error, "Error fetching location: #{e.message}" end |
.loc ⇒ Object
34 35 36 |
# File 'lib/live_location.rb', line 34 def self.loc fetch['loc'] end |
.region ⇒ Object
26 27 28 |
# File 'lib/live_location.rb', line 26 def self.region fetch['region'] end |
.timezone ⇒ Object
38 39 40 |
# File 'lib/live_location.rb', line 38 def self.timezone fetch['timezone'] end |