Module: OpenWeather::Endpoints::Current

Included in:
Client
Defined in:
lib/open_weather/endpoints/current.rb

Instance Method Summary collapse

Instance Method Details

#current_cities_geo_box(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/open_weather/endpoints/current.rb', line 44

def current_cities_geo_box(*args)
  options = args[-1].is_a?(Hash) ? args.pop.dup : {}
  options[:bbox] = args.join(',') if args.any?
  options[:bbox] ||= [
    options.delete(:lon_left),
    options.delete(:lat_bottom),
    options.delete(:lon_right),
    options.delete(:lat_top),
    options.delete(:zoom)
  ].join(',')
  OpenWeather::Models::List.new(get('2.5/box/city', options), options)
end

#current_cities_geo_circle(*args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/open_weather/endpoints/current.rb', line 57

def current_cities_geo_circle(*args)
  options = args[-1].is_a?(Hash) ? args.pop.dup : {}

  if args.any?
    options[:lat] = args.shift
    options[:lon] = args.shift
    options[:cnt] = args.shift || 1
  end

  OpenWeather::Models::List.new(get('2.5/find', options), options)
end

#current_cities_id(*args) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/open_weather/endpoints/current.rb', line 69

def current_cities_id(*args)
  options = args[-1].is_a?(Hash) ? args.pop.dup : {}
  options[:id] = args.join(',') if args.any?
  options[:id] = options.delete(:ids) if options.key?(:ids)
  options[:id] = options[:id].join(',') if options[:id].is_a?(Array)
  OpenWeather::Models::List.new(get('2.5/group', options), options)
end

#current_city(name, state = nil, country = nil, options = {}) ⇒ Object



16
17
18
19
# File 'lib/open_weather/endpoints/current.rb', line 16

def current_city(name, state = nil, country = nil, options = {})
  options = name.is_a?(Hash) ? options.merge(name) : options.merge(city: name, state: state, country: country)
  current_weather(options)
end

#current_city_id(id, options = {}) ⇒ Object



21
22
23
24
# File 'lib/open_weather/endpoints/current.rb', line 21

def current_city_id(id, options = {})
  options = id.is_a?(Hash) ? options.merge(id) : options.merge(id: id)
  current_weather(options)
end

#current_geo(lat, lon = nil, options = {}) ⇒ Object



11
12
13
14
# File 'lib/open_weather/endpoints/current.rb', line 11

def current_geo(lat, lon = nil, options = {})
  options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon)
  current_weather(options)
end

#current_weather(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/open_weather/endpoints/current.rb', line 26

def current_weather(options = {})
  if options.key?(:zip) && options.key?(:country)
    options = options.dup
    options[:zip] = [
      options.delete(:zip),
      options.delete(:country)
    ].compact.join(',')
  elsif options.key?(:city)
    options = options.dup
    options[:q] = [
      options.delete(:city),
      options.delete(:state),
      options.delete(:country)
    ].compact.join(',')
  end
  OpenWeather::Models::City::Weather.new(get('2.5/weather', options), options)
end

#current_zip(code, country = nil, options = {}) ⇒ Object



6
7
8
9
# File 'lib/open_weather/endpoints/current.rb', line 6

def current_zip(code, country = nil, options = {})
  options = code.is_a?(Hash) ? options.merge(code) : options.merge(zip: code, country: country)
  current_weather(options)
end