Sha256: a291d526829811fc9ce3ca7f3aa7fc794b599a69de3213c89015c7642301946d
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require 'typhoeus' require 'json' module Darksky class API DARKSKY_API_URL = 'https://api.darkskyapp.com/v1' DEFAULT_OPTIONS = { } # Create a new instance of the Darksky::API using your API key. # # @param api_key [String] Dark Sky API key. def initialize(api_key) @api_key = api_key end # Returns a forecast for the next hour at a given location. # # @param latitude [String] Latitude in decimal degrees. # @param longitude [String] Longitude in decimal degrees. # @param option [Hash] (Optional) Options to be passed to the Typhoeus::Request def forecast(latitude, longitude, options = {}) response = Typhoeus::Request.get("#{DARKSKY_API_URL}/forecast/#{@api_key}/#{latitude},#{longitude}", DEFAULT_OPTIONS.dup.merge(options)) JSON.parse(response.body) if response.code == 200 end # Returns forecasts for a collection of arbitrary points. # # @param latitudes_longitudes_times [Array] Triplets of latitude, longitude and time. Example: ['42.7','-73.6',1325607100,'42.0','-73.0',1325607791] # @param option [Hash] (Optional) Options to be passed to the Typhoeus::Request def precipitation(latitudes_longitudes_times, options = {}) return if latitudes_longitudes_times.size % 3 != 0 response = Typhoeus::Request.get("#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{latitudes_longitudes_times.join(',')}", DEFAULT_OPTIONS.dup.merge(options)) JSON.parse(response.body) if response.code == 200 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
darksky-1.0.2 | lib/darksky/api.rb |