aemet_opendata 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: d7f4fa2502e57760e72513d608c52257c102f8668dc97f6471cda9db3c352311
4
- data.tar.gz: 191d32de5ce06e1694952686f56d1ba275bfab52534ecc5d9ab758a0b9cfc585
3
+ metadata.gz: 9c932797e860c6c72540fdd3e4183e565964e972acc266ff187962a864b08137
4
+ data.tar.gz: dbd13826f541c2ea9ae085b7579727f3277e8aab20ad429ae06329c51f5760b6
5
5
  SHA512:
6
- metadata.gz: 362054b3c3e879105cf74316f2296278e3c28b14cb3421087a6f3a062cefcce488c89a8186bb8075baa333ac8700e41effd7465b9bae394c8f12bf27f28674ca
7
- data.tar.gz: 4ca70c238d66bc10b6d0e4753a6bb5eb93a6945233fb2efea03a7d6f38f6d12190dda320414f241347a0e6372d9248c9b1da081b6639a766ca7124f44ce13917
6
+ metadata.gz: ab17dfc1819b50c02dd69e2c730f1571285aeb22a03e6a4cd106b7275d1de34fe45728c4156b70bdad684257e7a08aa76b15b78aa89d8574ba189d8ad18f7ff5
7
+ data.tar.gz: 45a448931bb565df2e5aee11de85514caed400e095f7b3ad9d57b05d6a8149d344fe7e7483f3cc926615257253b55ba6d1d696b75f32909935cc95c940ebe898
@@ -1,7 +1,6 @@
1
- ---
2
- sudo: false
1
+ before_install:
2
+ - npm i -g npm
3
+ - gem install bundler
3
4
  language: ruby
4
- cache: bundler
5
5
  rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.16.4
6
+ - 2.2
@@ -1,16 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aemet_opendata (0.0.1)
4
+ aemet_opendata (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.3)
10
+ ethon (0.11.0)
11
+ ffi (>= 1.3.0)
10
12
  faraday (0.15.3)
11
13
  multipart-post (>= 1.2, < 3)
12
14
  faraday-encoding (0.0.5)
13
15
  faraday
16
+ ffi (1.9.25)
14
17
  json (2.1.0)
15
18
  multipart-post (2.0.0)
16
19
  rake (10.5.0)
@@ -27,6 +30,9 @@ GEM
27
30
  diff-lcs (>= 1.2.0, < 2.0)
28
31
  rspec-support (~> 3.8.0)
29
32
  rspec-support (3.8.0)
33
+ typhoeus (1.3.0)
34
+ ethon (>= 0.9.0)
35
+ vcr (4.0.0)
30
36
 
31
37
  PLATFORMS
32
38
  ruby
@@ -34,11 +40,13 @@ PLATFORMS
34
40
  DEPENDENCIES
35
41
  aemet_opendata!
36
42
  bundler (~> 1.16)
37
- faraday
38
- faraday-encoding
39
- json
43
+ faraday (>= 0.15.3)
44
+ faraday-encoding (>= 0.0.5)
45
+ json (>= 1.5.5)
40
46
  rake (~> 10.0)
41
47
  rspec (~> 3.0)
48
+ typhoeus (>= 1.3.0)
49
+ vcr (>= 4.0.0)
42
50
 
43
51
  BUNDLED WITH
44
52
  1.16.5
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # AemetOpendata
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aemet_opendata`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/aemet_opendata.svg)](https://rubygems.org/gems/aemet_opendata)
4
+ [![Code Climate](https://codeclimate.com/github/noloman/aemet_opendata/badges/gpa.svg)](https://codeclimate.com/github/noloman/aemet_opendata)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ ### Información elaborada por la [Agencia Estatal de Meteorología](https://www.aemet.es)
7
+
8
+ Gem that fetches meteorological information from https://opendata.aemet.es, the OpenData web portal from spanish meteorological agency, [AEMET](https://www.aemet.es)
6
9
 
7
10
  ## Installation
8
11
 
@@ -22,7 +25,15 @@ Or install it yourself as:
22
25
 
23
26
  ## Usage
24
27
 
25
- TODO: Write usage instructions here
28
+ First, you need to have a valid API key for making requests. Just go to https://opendata.aemet.es/centrodedescargas/altaUsuario and get one.
29
+
30
+ Once you have a valid API key, you can enter it as in the following example:
31
+ ```
32
+ AemetOpendata.configure do |config|
33
+ config.api_key = 'api-key'
34
+ end
35
+ ```
36
+ Then after you have entered your API key, just `AemetOpendata.fetch_city(city_name)` where `city_name` is the name of the city you want to fetch. (**NOTE**: as this is a gem in a very alpha stage, it will just return an 'idema' number).
26
37
 
27
38
  ## Development
28
39
 
@@ -32,7 +43,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
43
 
33
44
  ## Contributing
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aemet_opendata. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/noloman/aemet_opendata. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
47
 
37
48
  ## License
38
49
 
@@ -24,8 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.16"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "json", "~> 1.5.5"
28
- spec.add_development_dependency "faraday", "~> 0"
29
- spec.add_development_dependency "faraday-encoding", "~> 0"
30
- spec.add_development_dependency 'vcr', "~> 0"
27
+ spec.add_development_dependency "json", ">= 1.5.5"
28
+ spec.add_development_dependency "faraday", ">= 0.15.3"
29
+ spec.add_development_dependency "faraday-encoding", ">= 0.0.5"
30
+ spec.add_development_dependency 'vcr', ">= 4.0.0"
31
+ spec.add_development_dependency 'typhoeus', ">= 1.3.0"
31
32
  end
@@ -4,10 +4,15 @@ require 'json'
4
4
  require 'faraday'
5
5
  require 'faraday-encoding'
6
6
 
7
+ ##
8
+ # Main module
7
9
  module AemetOpendata
8
10
  extend Configuration
9
- # Fetches a city from the stations
11
+ ##
12
+ # Class that handles fetching of a city data from the API
10
13
  class << self
14
+ ##
15
+ # Fetches the 'idema' number from Aemet
11
16
  def fetch_city(city_name)
12
17
  if !AemetOpendata.api_key.nil?
13
18
  conn = Faraday.new "#{AemetOpendata.api_endpoint}", ssl: { verify: false }
@@ -28,6 +33,8 @@ module AemetOpendata
28
33
 
29
34
  private
30
35
 
36
+ ##
37
+ # Parses the API response
31
38
  def parse_response(response, city_name)
32
39
  data_connection = Faraday.new(response['datos'].to_s, ssl: { verify: false }) do |connection|
33
40
  connection.response :encoding # use Faraday::Encoding middleware
@@ -35,16 +42,46 @@ module AemetOpendata
35
42
  end
36
43
 
37
44
  json_array = JSON.parse(data_connection.get.body)
38
- parse_cities(city_name, json_array)
45
+ city_idema = parse_and_fetch_city_idema(city_name, json_array)
46
+ unless city_idema.nil?
47
+ ##
48
+ # Now we have to fetch the conventional observation weather from the idema.
49
+ # It should return a hash containing JSON objects of the weather in
50
+ # the place defined by the idema in the following 24 hours.
51
+ city_weather_url = "#{AemetOpendata.api_endpoint}/opendata/api/observacion/convencional/datos/estacion/#{city_idema}?api_key=#{AemetOpendata.api_key}"
52
+ city_weather_hash =
53
+ get_city_weather_from_idema(city_weather_url)
54
+ end
39
55
  end
40
56
 
41
- def parse_cities(city_name, json_array)
57
+ ##
58
+ # Parses the city name from the JSON array containing the data
59
+ def parse_and_fetch_city_idema(city_name, json_array)
60
+ res = nil
42
61
  json_array.each do |key|
43
62
  city = key.to_h
44
63
  if city['ubi'].force_encoding('UTF-8').include?(city_name.upcase)
45
- return city['idema'].encode('UTF-8')
64
+ res = city['idema'].encode('UTF-8')
46
65
  end
47
66
  end
67
+ res
68
+ end
69
+
70
+ ##
71
+ # Retrieves a hash with the city weather for the next 24 hours.
72
+ def get_city_weather_from_idema(data_url)
73
+ city_connection = Faraday.new(data_url, ssl: { verify: false }) do |connection|
74
+ connection.response :encoding # use Faraday::Encoding middleware
75
+ connection.adapter Faraday.default_adapter # net/http
76
+ end
77
+
78
+ conn_hash = JSON.parse(city_connection.get.body)
79
+ datos_url = conn_hash['datos']
80
+ datos_connection = Faraday.new(datos_url, ssl: { verify: false }) do |connection|
81
+ connection.response :encoding # use Faraday::Encoding middleware
82
+ connection.adapter Faraday.default_adapter # net/http
83
+ end
84
+ JSON.parse(datos_connection.get.body)
48
85
  end
49
86
  end
50
87
  end
@@ -1,3 +1,3 @@
1
1
  module AemetOpendata
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aemet_opendata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Lorenzo Parejo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-26 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,58 +56,72 @@ dependencies:
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.5.5
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.5.5
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.15.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.15.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faraday-encoding
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.0.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.0.5
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: vcr
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 4.0.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 4.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: typhoeus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 1.3.0
111
125
  description:
112
126
  email:
113
127
  - manulorenzop@gmail.com