Class: WorldTime

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.get_current_time(area) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/world_time_ruby.rb', line 17

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

.timezones(search: nil) ⇒ Object



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

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