powered_wunderground 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb2668ca0a35f6f0f670ca6db9f6ca8315e8cc27
4
- data.tar.gz: d24585de0a8b25a48df6336f3bdd0ca2b8cbd820
3
+ metadata.gz: d321857421d8651732072a87beb863afba9f3ee5
4
+ data.tar.gz: 028461c9f6baef784794606596de32e0df82443c
5
5
  SHA512:
6
- metadata.gz: 449f8cc9df8c3ab1932a73bf3ce054c60564eca5bcff5dd21e247ec8ddf9e0c707c1e76c711a4a11bb9e9b967c6d4351d9209f896052d03fdd7003782d9f595c
7
- data.tar.gz: 79028eeb10d2efcc211ae1efb3a0966a50a6c42b175a71a66d960f13eff685995526e07e56b9e8ce97e21c70ea6a65effa6e030c0188c0f32775acfbbdcd2b43
6
+ metadata.gz: afc48bac85430678b0eab078ebe6816be9cc1aef6aaad6c9375dfffd467f71df0f735d8372157365f8230458305a4ba3c53437f16a618073da774357e0632b4c
7
+ data.tar.gz: e09719742238c235720b241f0ec2eda141ab8ec1164524c8520cb595dab6a9bba90f98d62b9d56cbfd14b16f33547811772982cb3dcb53f8cbae1d53321d9152
data/README.md CHANGED
@@ -20,15 +20,18 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ by coords
23
24
  ```ruby
24
- PoweredWunderground.new(api_key: 'your_api_key', language: 'pt').forecast('pt', 'porto')
25
- => "Nublado. Máxima de 21°C. Ventos O a 10 a 15 km/h."
26
- PoweredWunderground.new(api_key: '84ba182600b17c03', language: 'fr').forecast('pt', 'porto')
27
- => "Nuageux. Maximales : 21 ºC. Vents O soufflant de 10 à 15 km/h."
25
+ pw = PoweredWunderground.new(api_key: api_key, language: 'pt')
26
+ response = pw.coord(37.77, -122.39)
27
+ response.powered_output
28
+ => {
29
+ :text=>"Nuvens matinais seguidas de sol da parte da tarde. Máxima de 68°F. Ventos O a 10 a 20 mph.",
30
+ :city=>"San Francisco",
31
+ :country=>"US"
32
+ }
28
33
  ```
29
34
 
30
- next steps: buff the forecast reply
31
-
32
35
  ## Development
33
36
 
34
37
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -6,6 +6,7 @@ module PoweredWunderground
6
6
 
7
7
  attr_reader :api_key
8
8
  attr_accessor :language
9
+ attr_accessor :units
9
10
 
10
11
  def initialize(api_key)
11
12
  @api_key = api_key
@@ -16,9 +17,24 @@ module PoweredWunderground
16
17
  "http://api.wunderground.com/api/#{api_key}/"
17
18
  end
18
19
 
20
+ def coord(latitude, longitude)
21
+ geo_response = wunderground_geolookup(latitude, longitude)
22
+ city = geo_response['location']['city']
23
+ country = geo_response['location']['country']
24
+ w_response = wunderground_coord_forecast(latitude, longitude)
25
+ hash = w_response['forecast']['txt_forecast']['forecastday'].first
26
+ Response.new(country, city, hash)
27
+ end
28
+
29
+ def city(country, city)
30
+ w_response = wunderground_city_forecast(country, city)
31
+ hash = w_response['forecast']['txt_forecast']['forecastday'].first
32
+ Response.new(country, city, hash)
33
+ end
34
+
19
35
  def forecast(country, city)
20
- wunderground_response = wunderground_forecast(country, city)
21
- wunderground_response['forecast']['txt_forecast']['forecastday'].first['fcttext_metric']
36
+ w_response = wunderground_forecast(country, city)
37
+ w_response['forecast']['txt_forecast']['forecastday'].first
22
38
  end
23
39
 
24
40
  def language
@@ -31,10 +47,30 @@ module PoweredWunderground
31
47
 
32
48
  private
33
49
 
34
- def wunderground_forecast(country, city)
35
- conn = Faraday.new(url: base_api_url)
36
- response = conn.get "forecast/lang:#{language}/q/#{country}/#{city}.json"
50
+ def wunderground_city_forecast(country, city)
51
+ url_suffix = "forecast/lang:#{language}/q/#{country}/#{city}.json"
52
+ response = wunderground_conn.get url_suffix
53
+ JSON.parse response.body
54
+ end
55
+
56
+ def wunderground_coord_forecast(latitude, longitude)
57
+ url_suffix = "forecast/#{coord_url_part(latitude, longitude)}"
58
+ response = wunderground_conn.get url_suffix
37
59
  JSON.parse response.body
38
60
  end
61
+
62
+ def wunderground_geolookup(latitude, longitude)
63
+ url_suffix = "geolookup/#{coord_url_part(latitude, longitude)}"
64
+ response = wunderground_conn.get url_suffix
65
+ JSON.parse response.body
66
+ end
67
+
68
+ def coord_url_part(latitude, longitude)
69
+ "lang:#{language}/q/#{latitude},#{longitude}.json"
70
+ end
71
+
72
+ def wunderground_conn
73
+ Faraday.new(url: base_api_url)
74
+ end
39
75
  end
40
76
  end
@@ -10,4 +10,4 @@ module PoweredWunderground
10
10
  }
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -0,0 +1,39 @@
1
+ module PoweredWunderground
2
+ class Response
3
+ attr_reader :country, :city, :properties
4
+
5
+ def initialize(country, city, properties)
6
+ @country = country
7
+ @city = city
8
+ @properties = properties
9
+ end
10
+
11
+ def to_s
12
+ properties[fcttext_field(country)]
13
+ end
14
+
15
+ def powered_output
16
+ {
17
+ text: to_s,
18
+ city: city,
19
+ country: country
20
+ }
21
+ end
22
+
23
+ alias_method :po, :powered_output
24
+
25
+ private
26
+
27
+ def fcttext_field(country)
28
+ if imperial_system.include? country
29
+ 'fcttext'
30
+ else
31
+ 'fcttext_metric'
32
+ end
33
+ end
34
+
35
+ def imperial_system
36
+ %w(US)
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module PoweredWunderground
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,12 +1,10 @@
1
1
  require 'powered_wunderground/version'
2
2
  require 'powered_wunderground/connection'
3
+ require 'powered_wunderground/response'
3
4
 
4
5
  module PoweredWunderground
5
6
  class << self
6
-
7
7
  def new(args)
8
- extra_params = {}
9
-
10
8
  if args.is_a?(String)
11
9
  start_conection_by_api_key(args)
12
10
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powered_wunderground
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Carneiro
@@ -99,6 +99,7 @@ files:
99
99
  - lib/powered_wunderground.rb
100
100
  - lib/powered_wunderground/connection.rb
101
101
  - lib/powered_wunderground/language_mapper.rb
102
+ - lib/powered_wunderground/response.rb
102
103
  - lib/powered_wunderground/version.rb
103
104
  - powered_wunderground.gemspec
104
105
  homepage: https://github.com/dcarneiro/powered_wunderground