accuweather 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/accuweather.gemspec +2 -1
- data/assets/cities.z +0 -0
- data/lib/accuweather.rb +11 -4
- data/lib/accuweather/location/cache.rb +28 -0
- data/lib/accuweather/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1549fa0380c0b2be4d6cf1ff807a1538bcd7db79
|
4
|
+
data.tar.gz: 3efea0be0d68e3fee8c74d0e6913bda363dc09c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d19950635990297ebca3b83f59adb867f73b2d7baee1029ed799ec87cef39872df819ddf3a4c05e6351f320905ec7bb1bb96e1c9626f463dbef536cf91b7f80
|
7
|
+
data.tar.gz: 93a6ead68387820cb2cee8496f7f622b960675ba85b91f4d78fb86f1d1dee38e47c77d56bf2fd85c4722bb1ab864e6efdb0281e5aadf5cce30d6bc36187538f9
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Accuweather
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
A simple wrapper around the accuweather web API written in Ruby
|
4
|
+
|
5
|
+
Get weather information for cities around the world. Includes current current conditions for temperature, pressure and humidity. Forecasts include temperature highs, lows, "real feels", UV, wind speed and direction, rain, snow, ice probabilities and amounts. The web API returns seven days of forecasts with estimates for both day and nighttime.
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
|
@@ -21,7 +22,7 @@ Or install it yourself as:
|
|
21
22
|
|
22
23
|
## Usage
|
23
24
|
|
24
|
-
Search for
|
25
|
+
Search for a city location to determine its id:
|
25
26
|
|
26
27
|
```ruby
|
27
28
|
location_array = Accuweather.city_search(name: 'vancouver')
|
@@ -61,9 +62,7 @@ weather_forecast.map(&:daytime).map(&:high_temperature) # => ["45", "45", "47",
|
|
61
62
|
weather_forecast.map(&:nighttime).map(&:low_temperature) # => ["27", "28", "31", "32", "40", "42", "36"]
|
62
63
|
```
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
`weather_text`,`weather_text_long`,`weather_icon`,`high_temperature`,`low_temperature`,`real_feel_high`,`real_feel_low`,`wind_speed`,`wind_direction`,`wind_gust`,`max_uv`,`rain_amount`,`snow_amount`,`ice_amount`,`precipitation_amount`,`thunderstorm_probability`,`rain_probability`,`snow_probability`,`ice_probability` and `precipitation_probability`
|
65
|
+
See `Accuview::Conditions::ForecastWeather` class for a full list of attributes for daytime and nighttime forecasts.
|
67
66
|
|
68
67
|
Get the units for the conditions:
|
69
68
|
|
@@ -83,7 +82,7 @@ local.time_zone # => '-8'
|
|
83
82
|
local.time_zone_abbreviation # => 'PST'
|
84
83
|
```
|
85
84
|
|
86
|
-
|
85
|
+
English units are returned by default, but metric results are available:
|
87
86
|
|
88
87
|
```ruby
|
89
88
|
Accuweather.get_conditions(location_id: 'cityId:53286', metric: true)
|
data/accuweather.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = 'Access current and future weather reports for cities around the world'
|
13
13
|
spec.description = 'Get weather information for cities around the world using the accuweather web API. Includes current current conditions for temperature, pressure and humidity. Forecasts include temperature highs, lows, "real feels", UV, wind speed, rain, snow, ice probabilities and amounts.'
|
14
14
|
spec.homepage = 'https://github.com/nick-aschenbach/accuweather'
|
15
|
+
spec.licenses = ['MIT']
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
18
|
spec.require_paths = ['lib']
|
@@ -20,5 +21,5 @@ Gem::Specification.new do |spec|
|
|
20
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
21
22
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
22
23
|
|
23
|
-
spec.add_runtime_dependency 'nokogiri'
|
24
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
24
25
|
end
|
data/assets/cities.z
ADDED
Binary file
|
data/lib/accuweather.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'accuweather/version'
|
2
2
|
require 'accuweather/location/city'
|
3
|
+
require 'accuweather/location/cache'
|
3
4
|
require 'accuweather/location/parser'
|
4
5
|
require 'accuweather/conditions/parser'
|
5
6
|
require 'accuweather/conditions/units'
|
@@ -12,13 +13,19 @@ require 'net/http'
|
|
12
13
|
require 'nokogiri'
|
13
14
|
|
14
15
|
module Accuweather
|
16
|
+
class Error < StandardError; end
|
17
|
+
|
15
18
|
def self.city_search(name:)
|
19
|
+
@cache ||= Accuweather::Location::Cache.new
|
20
|
+
cache_result = @cache.cities(name: name)
|
21
|
+
return cache_result unless cache_result == []
|
22
|
+
|
16
23
|
response = Net::HTTP.get('samsungmobile.accu-weather.com',
|
17
24
|
"/widget/samsungmobile/city-find.asp?returnGeoPosition=1&location=#{name}")
|
18
25
|
|
19
26
|
Accuweather::Location::Parser.new(response).cities
|
20
|
-
rescue StandardError
|
21
|
-
|
27
|
+
rescue StandardError => e
|
28
|
+
raise Accuweather::Error.new("#{e.class}: #{e.message}")
|
22
29
|
end
|
23
30
|
|
24
31
|
def self.get_conditions(location_id:, metric: false)
|
@@ -27,7 +34,7 @@ module Accuweather
|
|
27
34
|
"/widget/samsungmobile/weather-data.asp?metric=#{metric_value}&location=#{location_id}")
|
28
35
|
|
29
36
|
Accuweather::Conditions::Parser.new(response)
|
30
|
-
rescue StandardError
|
31
|
-
|
37
|
+
rescue StandardError => e
|
38
|
+
raise Accuweather::Error.new("#{e.class}: #{e.message}")
|
32
39
|
end
|
33
40
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Accuweather
|
2
|
+
module Location
|
3
|
+
class Cache
|
4
|
+
CITIES_CSV_FILE = File.join(File.dirname(__dir__), '..', '..', 'assets', 'cities.z')
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
csv_data = Zlib::Inflate.inflate(File.read(CITIES_CSV_FILE))
|
8
|
+
|
9
|
+
@city_data = {}
|
10
|
+
csv_data.split("\n").each do |line|
|
11
|
+
line_data = line.split('|')
|
12
|
+
arr = @city_data[line_data[1].downcase]
|
13
|
+
arr = [] if arr.nil?
|
14
|
+
arr << Accuweather::Location::City.new(id: line_data[0],
|
15
|
+
city: line_data[1],
|
16
|
+
state: line_data[2],
|
17
|
+
latitude: line_data[3],
|
18
|
+
longitude: line_data[4])
|
19
|
+
@city_data[line_data[1].downcase] = arr
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def cities(name:)
|
24
|
+
@city_data.fetch(name.downcase, [])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/accuweather/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accuweather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Aschenbach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: nokogiri
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.6'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.6'
|
69
69
|
description: Get weather information for cities around the world using the accuweather
|
70
70
|
web API. Includes current current conditions for temperature, pressure and humidity.
|
71
71
|
Forecasts include temperature highs, lows, "real feels", UV, wind speed, rain, snow,
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
87
87
|
- accuweather.gemspec
|
88
|
+
- assets/cities.z
|
88
89
|
- bin/console
|
89
90
|
- bin/setup
|
90
91
|
- lib/accuweather.rb
|
@@ -94,11 +95,13 @@ files:
|
|
94
95
|
- lib/accuweather/conditions/local.rb
|
95
96
|
- lib/accuweather/conditions/parser.rb
|
96
97
|
- lib/accuweather/conditions/units.rb
|
98
|
+
- lib/accuweather/location/cache.rb
|
97
99
|
- lib/accuweather/location/city.rb
|
98
100
|
- lib/accuweather/location/parser.rb
|
99
101
|
- lib/accuweather/version.rb
|
100
102
|
homepage: https://github.com/nick-aschenbach/accuweather
|
101
|
-
licenses:
|
103
|
+
licenses:
|
104
|
+
- MIT
|
102
105
|
metadata: {}
|
103
106
|
post_install_message:
|
104
107
|
rdoc_options: []
|
@@ -116,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
119
|
version: '0'
|
117
120
|
requirements: []
|
118
121
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.5.0
|
120
123
|
signing_key:
|
121
124
|
specification_version: 4
|
122
125
|
summary: Access current and future weather reports for cities around the world
|