Class: Helpers

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

Instance Method Summary collapse

Instance Method Details

#cords_to_url(url, coords, api_key, units, lang) ⇒ Object



32
33
34
# File 'lib/open_weather/helpers/helpers.rb', line 32

def cords_to_url(url, coords, api_key, units, lang)
  "#{url}lat=#{coords[1]}&lon=#{coords[0]}&appid=#{api_key}&lang=#{lang}&units=#{units}"
end

#find_to_url(url, coords, count, api_key, units, lang) ⇒ Object



40
41
42
# File 'lib/open_weather/helpers/helpers.rb', line 40

def find_to_url(url, coords, count, api_key, units, lang)
  "#{url}lat=#{coords[1]}&lon=#{coords[0]}&appid=#{api_key}&cnt=#{count}&lang=#{lang}&units=#{units}"
end

#id_to_url(url, name, api_key, units, lang) ⇒ Object



28
29
30
# File 'lib/open_weather/helpers/helpers.rb', line 28

def id_to_url(url, name, api_key, units, lang)
  "#{url}id=#{name}&appid=#{api_key}&lang=#{lang}&units=#{units}"
end

#name_to_url(url, name, api_key, units, lang) ⇒ Object



24
25
26
# File 'lib/open_weather/helpers/helpers.rb', line 24

def name_to_url(url, name, api_key, units, lang)
  "#{url}q=#{name}&appid=#{api_key}&lang=#{lang}&units=#{units}"
end

#swtich_url(method) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/open_weather/helpers/helpers.rb', line 13

def swtich_url(method)
  case method
  when 'current_wether'
    'https://api.openweathermap.org/data/2.5/weather?'
  when 'hourly'
    'pro.openweathermap.org/data/2.5/forecast/hourly?'
  when 'find'
    'api.openweathermap.org/data/2.5/find?'
  end
end

#to_json(data) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/open_weather/helpers/helpers.rb', line 5

def to_json(data)
  unless data
    tmp = {}
    return JSON.parse(tmp)
  end
  JSON.parse data
end

#zipcode_to_url(url, zip, country, api_key, units, lang) ⇒ Object



36
37
38
# File 'lib/open_weather/helpers/helpers.rb', line 36

def zipcode_to_url(url, zip, country, api_key, units, lang)
  "#{url}zip=#{zip},#{country}&appid=#{api_key}&lang=#{lang}&units=#{units}"
end