cptec_inpe 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29ac7b1643adb286b96e0e93734bbb08889e071e
4
- data.tar.gz: a1527c9a4a1ce9c2e7034443d927b2c655317ebc
3
+ metadata.gz: bc4fb963b8a32b07c6f2aed87bf305789a617b5a
4
+ data.tar.gz: 1d5816dd0a22e13549caf5d7bb279e228cf27bc8
5
5
  SHA512:
6
- metadata.gz: 312a38825d81e5340f7852c61f1402a1fc35519468976fec741d87ab5dfc90fd917a2a1f54bd7861ad46a32ab78a553c49625d0d6cd5f4a025492f3b06383fe9
7
- data.tar.gz: 2e5d5f75bb8b31598592771509b0480ab6e64d75002409675411dcf4d57b501798486b4faacb697224662a402ea92446c2e8bfc25f1e187986c802be915a55fe
6
+ metadata.gz: fe5c79ace5fec704819c52a6a58740df58325c21348978db8d417fc9f778b9faf8a13fc87951d890b601c87167f82cdb773999fdac2ed67f102b9d715b2484f8
7
+ data.tar.gz: d4194737f3b41221251fa4f28179c214f24fa34ca474b339b5e6d2faa9dfeddd8bf6e53aa0803d1f875323dbbd9509c8a8ba7817d47bc5e1afd1d73b97c76fa6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CptecInpe
1
+ # CPTEC/INPE forecast
2
2
 
3
3
  [![Build Status](https://travis-ci.org/t4deu/cptec_inpe.svg?branch=master)](https://travis-ci.org/t4deu/cptec_inpe)
4
4
  [![Coverage Status](https://coveralls.io/repos/t4deu/cptec_inpe/badge.svg?branch=master&service=github)](https://coveralls.io/github/t4deu/cptec_inpe?branch=master)
@@ -25,6 +25,8 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  ```ruby
28
+ require 'cptec_inpe'
29
+
28
30
  client = CptecInpe.new "Rio de janeiro"
29
31
 
30
32
  client.location = "São Paulo" # Change current location
data/lib/cptec_inpe.rb CHANGED
@@ -14,10 +14,12 @@ class CptecInpe
14
14
  end
15
15
 
16
16
  def location=(location)
17
+ @location_code = nil
18
+
17
19
  city = find_location(location)
18
20
 
19
21
  unless city.nil?
20
- @location_code = city['id']
22
+ @location_code = city["id"]
21
23
  end
22
24
  end
23
25
 
@@ -28,34 +30,45 @@ class CptecInpe
28
30
  }
29
31
  }
30
32
 
31
- path = "#{base_path}/listaCidades"
32
- cities = self.class.get(path, options)['cidades']
33
+ path = build_path "/listaCidades"
34
+ cities = self.class.get(path, options)["cidades"]
33
35
 
34
36
  return if cities.nil?
35
- return cities.first if cities['cidate'].is_a?(Array)
37
+ return cities["cidade"].first if cities["cidade"].is_a?(Array)
36
38
 
37
39
  cities["cidade"]
38
40
  end
39
41
 
40
42
  def waves_today
41
- get "#{base_path}/cidade/%s/dia/0/ondas.xml"
43
+ response = get("/cidade/%s/dia/0/ondas.xml")
44
+ response["cidade"] if response
42
45
  end
43
46
 
44
47
  def waves_next_days
45
- get "#{base_path}/cidade/%s/todos/tempos/ondas.xml"
48
+ response = get("/cidade/%s/todos/tempos/ondas.xml")
49
+ get_forecast(response) if response
46
50
  end
47
51
 
48
52
  def forecast
49
- get "#{base_path}/cidade/%s/previsao.xml"
53
+ response = get("/cidade/%s/previsao.xml")
54
+ get_forecast(response) if response
50
55
  end
51
56
 
52
57
  private
53
58
 
54
- def base_path
55
- "/XML"
59
+ def get(path_format)
60
+ unless @location_code.nil?
61
+ path = build_path(path_format % @location_code)
62
+ response = self.class.get(path)
63
+ response if response.success?
64
+ end
65
+ end
66
+
67
+ def build_path(path)
68
+ "/XML#{path}"
56
69
  end
57
70
 
58
- def get(path_format)
59
- self.class.get(path_format % @location_code) unless @location_code.nil?
71
+ def get_forecast(response)
72
+ response["cidade"]["previsao"]
60
73
  end
61
74
  end
@@ -1,3 +1,3 @@
1
1
  class CptecInpe
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cptec_inpe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadeu Valentt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler