class Swissforecast::Client

Constants

DEFAULT_DOMAIN

Public Instance Methods

find_by(param) click to toggle source

> find weather by city or by gps position

# File lib/swissforecast.rb, line 13
def find_by(param)
  if param.key?(:city)
    perform(param[:city].sub(' ', '-'))
  elsif param.key?(:lat) && param.key?(:lng)
    perform("lat=#{param[:lat]}lng=#{param[:lng]}")
  end
end

Private Instance Methods

perform(params = '') click to toggle source
# File lib/swissforecast.rb, line 23
def perform(params = '')
  response = Net::HTTP.get(URI("#{DEFAULT_DOMAIN}/#{params}"))

  # Uncomment the line below to dump the response in order to generate
  # a file to use as response stub in tests.
  # File.write('/tmp/response.json', response)

  JSON.parse(response, object_class: OpenStruct)
end