Sha256: 66c35ef2a4d7591dd2b504f26661afcca113d7693652a3f3677043538bc163f3

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'wor/weather/version'
require 'httparty'

module Wor
  module Weather
    API_URL = 'http://api.openweathermap.org/data/2.5'.freeze

    @config = {
      api_key: '',
      unit_type: :metric
    }

    def self.configure
      yield self
    end

    def self.api_key=(api_key)
      @config[:api_key] = api_key
    end

    def self.unit_type=(unit_type)
      @config[:unit_type] = unit_type
    end

    class << self
      def temp(city)
        response = HTTParty.get(
          API_URL + "/weather?q=#{city}&appid=#{@config[:api_key]}&units=#{@config[:unit_type]}"
        )
        response['main']['temp']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wor-weather-0.1.0 lib/wor/weather.rb