Class: WorldTime

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

Constant Summary collapse

WORLD_TIME_URL =
"http://worldtimeapi.org/api/timezone".freeze

Class Method Summary collapse

Class Method Details

.current_time_for_area(area) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/world_time.rb', line 18

def self.current_time_for_area(area)
  url_with_area = WORLD_TIME_URL + "/#{area}"
  response = Net::HTTP.get_response(URI(url_with_area))
  body = JSON.parse(response.body)
  date = DateTime.parse(body["datetime"])
  date.strftime('%I:%M:%S %p')
end

.timezones(search: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/world_time.rb', line 8

def self.timezones(search: nil)
  response = Net::HTTP.get_response(URI(WORLD_TIME_URL))
  body = JSON.parse(response.body)
  if search
    body.filter { |item| item.include?(search)}
  else
    body
  end
end