Class: OpenWeather::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/OpenWeather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Open Weather Map Client

Parameters:

  • opts (Hash) (defaults to: {})

    A hash of options

Options Hash (opts):

  • :url (String)

    The Open Weather Map API URL.

  • :useragent (String)

    Useragent used for the request

  • :api_key (String)

    Your API key if you have one



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/OpenWeather.rb', line 27

def initialize( opts = {} )
  options = {url: "http://api.openweathermap.org/data/2.5", useragent: "Open Weather Ruby v#{VERSION}"}.merge opts
  @baseurl = options[:url]
  @headers = {'User-Agent' => options[:useragent]}
  # For HTTParty
  self.class.base_uri options[:url]
  self.class.headers @headers

  @units_format = 'metric'
  @data_format  = 'json'
  @api_key = options[:api_key] if options[:api_key]
end

Instance Attribute Details

#data_formatObject

Returns the value of attribute data_format.



19
20
21
# File 'lib/OpenWeather.rb', line 19

def data_format
  @data_format
end

#units_formatObject

Returns the value of attribute units_format.



19
20
21
# File 'lib/OpenWeather.rb', line 19

def units_format
  @units_format
end

Instance Method Details

#load_file(file) ⇒ Object



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

def load_file(file)
  @city_file = file if File.exist? file
end

#unload_fileObject



44
45
46
# File 'lib/OpenWeather.rb', line 44

def unload_file
  @city_file = nil
end