Sha256: 33e201d75057e4ab029dbbac2bbcb881737dcbbafe142bbe1bb81a5a3d50ed4a
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require 'typhoeus' require 'json' module Darksky class API DARKSKY_API_URL = 'https://api.darkskyapp.com/v1' DEFAULT_OPTIONS = { :disable_ssl_peer_verification => true } # 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. 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] 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.1 | lib/darksky/api.rb |