Module: Maju::Helpers
- Included in:
- Client
- Defined in:
- lib/maju/support/helpers.rb
Instance Method Summary collapse
- #api_url_base ⇒ Object
- #api_url_current(params) ⇒ Object
- #api_url_forecast(params) ⇒ Object
- #api_url_geocode(params) ⇒ Object
- #check_metric(metric) ⇒ Object
- #headers ⇒ Object
- #json(json) ⇒ Object
- #parsed_params(params) ⇒ Object
Instance Method Details
#api_url_base ⇒ Object
4 5 6 |
# File 'lib/maju/support/helpers.rb', line 4 def api_url_base "https://api.openweathermap.org" end |
#api_url_current(params) ⇒ Object
8 9 10 |
# File 'lib/maju/support/helpers.rb', line 8 def api_url_current(params) "#{api_url_base}/data/2.5/weather?" + parsed_params(params) end |
#api_url_forecast(params) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/maju/support/helpers.rb', line 12 def api_url_forecast(params) days_count = (params[:days_count] && params[:days_count] <= 15) ? params[:days_count] : 15 url = "#{api_url_base}/data/2.5/forecast" + parsed_params(params) url +="&cnt=#{days_count}" if params && params[:days_count] url end |
#api_url_geocode(params) ⇒ Object
21 22 23 24 |
# File 'lib/maju/support/helpers.rb', line 21 def api_url_geocode(params) url = "#{api_url_base}/geo/1.0/direct" + parsed_params(params) url end |
#check_metric(metric) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/maju/support/helpers.rb', line 42 def check_metric(metric) case metric.downcase when 'celsius' 'metric' when 'fahrenheit' 'imperial' when 'Kelvin' 'standard' else 'metric' end end |
#headers ⇒ Object
26 27 28 |
# File 'lib/maju/support/helpers.rb', line 26 def headers {} end |
#json(json) ⇒ Object
38 39 40 |
# File 'lib/maju/support/helpers.rb', line 38 def json(json) JSON.parse(json) end |
#parsed_params(params) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/maju/support/helpers.rb', line 30 def parsed_params(params) if params[:city] "?lang=#{@lang}&units=#{@unit}&q=#{params[:city]}&appid=#{@token}" else "?lang=#{@lang}&units=#{@unit}&appid=#{@token}&lat=#{params[:lat]}&lon=#{params[:long]}" end end |