 
   @api_token "9dbfcd557bbda142ce4ae277b5d24e3b"
   @weather_url_api "api.openweathermap.org/data/2.5/forecast/daily"
+#  api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=json&cnt=3&units=metric&appid=2de143494c0b295cca9337e1e96b00e0
   @weather_url_api_today "api.openweathermap.org/data/2.5/weather"
   @api_no_data_error  "{\"cod\":\"404\",\"message\":\"Error: Not found city\"}\n"
   @api_data_list  "{\"cod\":\"200\",\"list\": forecast_list }\n"

  end

  def show_weather(conn, %{"city" => city}) do
  a_response = fetch(city)
  a_today = fetch_today(city)
  conn

    |> parse_response
  end

  def weather_url_today(city, format \\ "html", units \\"metric") do
      # old way  "#{@weather_url_api_today}?q=#{city}&mode=#{format}&unit=#{unit}&&APPID=#{@api_token}"
    url_params_encoded = URI.encode_query %{
    		       "q" => city , 
		       "mode" => format, 
		       "unit" => units, 
		       "appid" => @api_token
		       }
    "#{@weather_url_api_today}?#{url_params_encoded}"
  end

  def weather_url(city, format \\ "json", units \\"metric", number_of_days \\ 3 ) do
    # old way "#{@weather_url_api}?q=#{city}&mode=#{format}&cnt=#{number_of_days}&unit=#{unit}&&APPID=#{@api_token}"
    url_params_encoded = URI.encode_query %{
    		    "q" => city , 
    		    "mode" => format, 
		    "units" => units, 
		    "cnt" => number_of_days , 
		    "appid" => @api_token
		    }
    IO.inspect "#{@weather_url_api}}?#{url_params_encoded}"
    "#{@weather_url_api}?#{url_params_encoded}"
  end

  def parse_response({:ok, %HTTPoison.Response{status_code: 200, body: body}}) do
    parse_body(body)
  end

