Class: WeatherByDcq::Request

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

Overview

export

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Request

Returns a new instance of Request.



13
14
15
# File 'lib/weather_by_dcq/request.rb', line 13

def initialize(location)
  @location = location
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



11
12
13
# File 'lib/weather_by_dcq/request.rb', line 11

def location
  @location
end

Class Method Details

.coordinate_pts(location) ⇒ Object

Convert user entered location to geodetic coordinates



18
19
20
21
22
23
24
25
26
27
# File 'lib/weather_by_dcq/request.rb', line 18

def self.coordinate_pts(location)
  city = Geocoder.search(location)
  if city[0].nil?
    puts "Not Found"
    return WeatherByDcq::View.new.menu
  else
    @lat = city[0].latitude
    @lon = city[0].longitude
  end
end

.fetch(location) ⇒ Object

fetch forecast hash from Dark Sky API



30
31
32
33
34
35
36
37
# File 'lib/weather_by_dcq/request.rb', line 30

def self.fetch(location)
  coordinate_pts(location)
  ForecastIO.configure do |c|
    c.api_key = '4aac124157c348289553a5e7fdc1899d'
    c.default_params = { time: 600, exclude: 'minutely, hourly' }
  end
  @forecast = ForecastIO.forecast(@lat, @lon)
end