class OpenWeather::Client

Attributes

data_format[RW]
units_format[RW]

Public Class Methods

new( opts = {} ) click to toggle source

Open Weather Map Client

@param opts [Hash] A hash of options @option opts [String] :url The Open Weather Map API URL. @option opts [String] :useragent Useragent used for the request @option opts [String] :api_key Your API key if you have one

# 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

Public Instance Methods

load_file(file) click to toggle source
# File lib/OpenWeather.rb, line 40
def load_file(file)
  @city_file = file if File.exist? file
end
unload_file() click to toggle source
# File lib/OpenWeather.rb, line 44
def unload_file
  @city_file = nil
end