ale_air 0.1.0 → 0.2.0

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: f60580661ac1dae4b860d496130df098215ec3514a14aba785ccb12b651da6ea
4
- data.tar.gz: cc5816589710c9d61e224099776f42b0485797d0f2774ad67c694385becc6eff
3
+ metadata.gz: a97580cf9de23d6c07b045f34682529d49f781d6bee608318371839c6fa43117
4
+ data.tar.gz: 965e2d3065322e72252b444369ada0c587dc8e5d110b9d5eec26101a746ac1e8
5
5
  SHA512:
6
- metadata.gz: 05c6364bdb707eff52e160a633f713e020140d7d81eb59fb2d3bd65ce6e1f9f0924d046f0c0b51958d47af3b88448065c685e4f25e3e47c8e927099749d82f62
7
- data.tar.gz: ece5caf157b032b0b4ac6585cbd28921cade0e72d39eb5e70b2197483009875e40a1117b4011a44331e5b393699b98343802f80603a57f54c45790d47eedf888
6
+ metadata.gz: 733d1a91d0c92584975394c0643fa60667da849fdf8851bc62af1faa2da4e776404d7fb0825dee3f659477ed70b46774bf0091cbc913c22b327b93f5afe8b525
7
+ data.tar.gz: e1aa5c14cafc9a1960ab404e7da28dd35f5ea981bd70b62fc0e3d77ebea5c033f7a67092133a569d9d51240044ed4936a6a7fc8a58f67d80ffe0cd7d46c48afd
data/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
4
+
5
+ ## [0.2.0] - 2026-04-22
6
+
7
+ ### Added
8
+ - `lib/ale_air.rb` top-level entry point — `require 'ale_air'` now works as advertised.
9
+ - Error class hierarchy: `AleAir::Error`, `MissingTokenError`, `InvalidTokenError`, `ApiError`, `NetworkError`.
10
+ - Configurable `base_url`, `open_timeout`, `read_timeout` on `FetchJSON.new`.
11
+ - GitHub Actions CI matrix across Ruby 3.2, 3.3, 3.4, 4.0.
12
+ - `.rubocop.yml` with `rubocop-performance` and `rubocop-rspec`.
13
+ - `webmock` dev dependency — the test suite no longer hits the real WAQI API.
14
+
15
+ ### Changed
16
+ - HTTP client swapped from `rest-client` (unmaintained) to Ruby stdlib `net/http` — no runtime dependencies.
17
+ - `#air_quality` now consistently returns `true`/`false` and always sets `status`/`message` (previously returned `nil` when the token was missing).
18
+ - Gemspec: added `metadata` (source_code_uri, changelog_uri, rubygems_mfa_required), removed deprecated `test_files`, dropped the unnecessary `bundler` dev dep.
19
+
20
+ ### Removed
21
+ - `rest-client` runtime dependency.
22
+ - `attr_writer :secret_token` (token is now set only via the constructor).
23
+ - `config/key.yml` — no longer needed; tests use WebMock fixtures.
24
+
25
+ ### Fixed
26
+ - `require 'cgi'` is now explicit (previously loaded transitively via rest-client).
27
+ - Typo in `.rspec`: `--order define` → `--order defined`.
28
+
29
+ ## [0.1.0] - Initial release
data/README.md CHANGED
@@ -1,54 +1,109 @@
1
- # Easy Air Quality Ruby Gem for Major Cities
1
+ # AleAir Air Quality for Major Cities
2
2
 
3
- This is an easy to use Gem for your Ruby projects when you wish to add air quality parameters. It uses World Air Quality Projects open api and parses the responses for ease of use. To use it go to [Air Quality Project](aqicn.org) and apply for a token (you will need it).
3
+ [![CI](https://github.com/FistOfTheNorthStar/ale_air/actions/workflows/ci.yml/badge.svg)](https://github.com/FistOfTheNorthStar/ale_air/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/ale_air.svg)](https://rubygems.org/gems/ale_air)
5
+
6
+ A small Ruby gem that wraps the [World Air Quality Index](https://aqicn.org) (WAQI) public API and returns parsed, ready-to-use air-quality data for a given city. No external dependencies — just Ruby standard library.
4
7
 
5
8
  ## Installation
6
9
 
7
- Add this to Gemfile:
10
+ Add to your `Gemfile`:
8
11
 
9
12
  ```ruby
10
13
  gem 'ale_air'
11
14
  ```
12
15
 
13
- And then execute:
16
+ Then:
17
+
18
+ ```sh
19
+ bundle install
20
+ ```
21
+
22
+ Or install directly:
23
+
24
+ ```sh
25
+ gem install ale_air
26
+ ```
14
27
 
15
- $ bundle install
16
-
17
- Or
28
+ ## Configuration
18
29
 
19
- $ gem install ale_air
30
+ You need a free WAQI API token. Request one at <https://aqicn.org/data-platform/token/>.
20
31
 
21
32
  ## Usage
22
- Add
23
33
 
24
- require 'ale_air'
34
+ ```ruby
35
+ require 'ale_air'
25
36
 
26
- Just initialize first with your token
37
+ client = AleAir::FetchJSON.new('YOUR_TOKEN')
27
38
 
28
- air_results = AleAir::FetchJSON.new('YOUR_TOKEN')
39
+ if client.air_quality('Helsinki')
40
+ puts client.descriptive_text
41
+ # => "Air quality: 42 AQI Good @ Kallio 12:00 +02:00"
42
+ else
43
+ warn "Lookup failed: #{client.message}"
44
+ end
45
+ ```
29
46
 
30
- Now you can get the air quality where you wish. This will return true if succesful and false if some error occured
47
+ ### Accessors
31
48
 
32
- air_results.air_quality('Helsinki')
49
+ After a call to `#air_quality`, the client exposes:
33
50
 
34
- Then you can just use the results
51
+ | Method | Description |
52
+ |----------------------|----------------------------------------------------------------------|
53
+ | `status` | `"ok"` or `"error"` |
54
+ | `message` | Human-readable status message or error detail |
55
+ | `location` | Name of the measurement station |
56
+ | `quality` | Air Quality Index (US-EPA 2016 scale) |
57
+ | `time_measured` | Measurement timestamp with timezone |
58
+ | `danger_level` | One of: Good, Moderate, Unhealthy for Sensitive Groups, Unhealthy, Very Unhealthy, Hazardous |
59
+ | `descriptive_text` | Pre-formatted single-line summary |
35
60
 
36
- air_results.status -- will return "ok" or "error"
37
- air_results.message -- what kind of error occured
38
- air_results.location -- the measurement station location
39
- air_results.quality -- Air Quality Index scale as defined by the US-EPA 2016
40
- air_results.time_measured -- time of measurement
41
- air_results.danger_level -- level
42
- air_results.descriptive_text -- Ready string with all the info for IRC for example
43
- ## Development
61
+ ### Options
44
62
 
45
- Install on locally and start developing.
63
+ ```ruby
64
+ AleAir::FetchJSON.new(
65
+ 'YOUR_TOKEN',
66
+ base_url: 'https://api.waqi.info', # override for testing
67
+ open_timeout: 5, # seconds
68
+ read_timeout: 10 # seconds
69
+ )
70
+ ```
46
71
 
47
- ## License
72
+ ### Error handling
48
73
 
49
- MIT License.
74
+ `#air_quality` always returns `true` or `false`. On failure, `status` is set to `"error"` and `message` contains the reason:
75
+
76
+ ```ruby
77
+ client = AleAir::FetchJSON.new('bad-token')
78
+ client.air_quality('Helsinki') # => false
79
+ client.status # => "error"
80
+ client.message # => "Invalid key"
81
+ ```
82
+
83
+ Error classes are also defined under `AleAir::` for callers that prefer to raise:
84
+ `AleAir::Error`, `AleAir::MissingTokenError`, `AleAir::InvalidTokenError`, `AleAir::ApiError`, `AleAir::NetworkError`.
85
+
86
+ ## Development
87
+
88
+ ```sh
89
+ bundle install
90
+ bundle exec rspec # run the test suite
91
+ bundle exec rubocop # run the linter
92
+ bundle exec rake # run both (default task)
93
+ ```
94
+
95
+ Tests use [WebMock](https://github.com/bblimke/webmock) to stub the WAQI API — no real network access is required.
50
96
 
51
97
  ## Contributing
52
98
 
53
- Report bugs and pull requests on GitHub at https://github.com/FistOfTheNorthStar/ale_air
99
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/FistOfTheNorthStar/ale_air>.
100
+
101
+ 1. Fork the repo
102
+ 2. Create a feature branch
103
+ 3. Add tests for your change
104
+ 4. Ensure `bundle exec rake` is green
105
+ 5. Open a pull request
106
+
107
+ ## License
54
108
 
109
+ Released under the [MIT License](LICENSE.txt).
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AleAir
4
+ class Error < StandardError; end
5
+
6
+ class MissingTokenError < Error; end
7
+ class InvalidTokenError < Error; end
8
+ class ApiError < Error; end
9
+ class NetworkError < Error; end
10
+ end
@@ -1,75 +1,89 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
3
4
  require 'json'
4
- require 'rest-client'
5
+ require 'net/http'
6
+ require 'uri'
5
7
 
6
8
  module AleAir
7
- # Fetches JSON from Waqi API
9
+ # Fetches air-quality data from the WAQI (World Air Quality Index) API.
8
10
  class FetchJSON
9
- attr_writer :secret_token
10
- attr_reader :status, :message, :time_measured, :location, :quality, :danger_level, :descriptive_text
11
-
12
- def initialize(secret_token = '')
13
- @secret_token = secret_token
11
+ DEFAULT_BASE_URL = 'https://api.waqi.info'
12
+ DEFAULT_OPEN_TIMEOUT = 5
13
+ DEFAULT_READ_TIMEOUT = 10
14
+
15
+ attr_reader :status, :message, :time_measured, :location, :quality,
16
+ :danger_level, :descriptive_text
17
+
18
+ def initialize(secret_token = nil, base_url: DEFAULT_BASE_URL,
19
+ open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT)
20
+ @secret_token = secret_token.to_s
21
+ @base_url = base_url
22
+ @open_timeout = open_timeout
23
+ @read_timeout = read_timeout
14
24
  end
15
25
 
16
26
  def air_quality(city = '')
17
- return if @secret_token.nil?
18
-
19
- response = RestClient.get("https://api.waqi.info/search/?keyword=#{cleaned(city)}&token=#{@secret_token}")
20
- document = JSON.parse(response.body)
27
+ return error('Missing API token') if @secret_token.empty?
21
28
 
29
+ document = get_json("/search/?keyword=#{cleaned(city)}&token=#{@secret_token}")
22
30
  get_info(document)
23
- rescue RestClient::ExceptionWithResponse => e
24
- @message = e.response&.body || 'Unknown Error'
25
- false
31
+ rescue NetworkError => e
32
+ error("Network error: #{e.message}")
33
+ rescue JSON::ParserError => e
34
+ error("Invalid JSON response: #{e.message}")
26
35
  end
27
36
 
28
37
  private
29
38
 
39
+ def get_json(path)
40
+ uri = URI.join(@base_url, path)
41
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https',
42
+ open_timeout: @open_timeout,
43
+ read_timeout: @read_timeout) do |http|
44
+ http.get(uri.request_uri)
45
+ end
46
+ JSON.parse(response.body.to_s)
47
+ rescue SocketError, Timeout::Error, Errno::ECONNREFUSED, OpenSSL::SSL::SSLError => e
48
+ raise NetworkError, e.message
49
+ end
50
+
30
51
  def cleaned(chars = '')
31
- CGI.escape(chars.downcase.strip)
52
+ CGI.escape(chars.to_s.downcase.strip)
32
53
  end
33
54
 
34
55
  def get_info(document)
35
- if document['status'] == 'ok' && document['data'].any?
36
- air = document['data'].first
37
- aqi = air['aqi']
38
-
39
- return false unless check_aqi(aqi)
40
-
41
- information_message(aqi, air)
42
- else
43
- no_data_available_message(document)
44
- end
45
- end
56
+ return no_data_available_message(document) unless document.is_a?(Hash)
57
+ return no_data_available_message(document) unless document['status'] == 'ok'
58
+ return no_data_available_message(document) unless document['data'].is_a?(Array) && document['data'].any?
46
59
 
47
- def check_aqi(aqi)
48
- return true if integer?(aqi)
60
+ air = document['data'].first
61
+ aqi = air['aqi']
62
+ return error('Invalid Air Quality Value') unless integer?(aqi)
49
63
 
50
- @status = 'error'
51
- @message = 'Invalid Air Quality Value'
52
- false
64
+ information_message(aqi, air)
53
65
  end
54
66
 
55
67
  def information_message(aqi, air)
68
+ station_name = air.dig('station', 'name')
56
69
  @status = 'ok'
57
70
  @message = 'Air Quality'
58
71
  @quality = aqi
59
72
  @time_measured = "#{air.dig('time', 'stime')} #{air.dig('time', 'tz')}"
60
- @location = air.dig('station', 'name')
73
+ @location = station_name
61
74
  @danger_level = danger_lev(aqi)
62
- @descriptive_text = "Air quality: #{aqi} AQI #{danger_lev(aqi)} @ #{air.dig('station',
63
- 'name')} #{@time_measured}"
75
+ @descriptive_text = "Air quality: #{aqi} AQI #{@danger_level} @ #{station_name} #{@time_measured}"
64
76
  true
65
77
  end
66
78
 
67
79
  def no_data_available_message(document)
80
+ detail = document.is_a?(Hash) ? document['data'] : nil
81
+ error(detail.is_a?(String) ? detail : 'No Data Available')
82
+ end
83
+
84
+ def error(message)
68
85
  @status = 'error'
69
- @message = case document['data']
70
- when String then document['data']
71
- else 'No Data Available'
72
- end
86
+ @message = message
73
87
  false
74
88
  end
75
89
 
@@ -86,10 +100,9 @@ module AleAir
86
100
 
87
101
  def integer?(aqi)
88
102
  Integer(aqi)
89
- rescue ArgumentError
90
- false
91
- else
92
103
  true
104
+ rescue ArgumentError, TypeError
105
+ false
93
106
  end
94
107
  end
95
108
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AleAir
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/ale_air.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ale_air/version'
4
- require 'ale_air/fetch_json'
3
+ require_relative 'ale_air/version'
4
+ require_relative 'ale_air/errors'
5
+ require_relative 'ale_air/fetch_json'
5
6
 
6
7
  # Air quality of major cities
7
8
  module AleAir
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ale_air
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FistOfTheNorthStar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-03 00:00:00.000000000 Z
11
+ date: 2026-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -39,7 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-performance
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -53,7 +81,7 @@ dependencies:
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: bundler
84
+ name: webmock
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - ">="
@@ -74,24 +102,22 @@ executables: []
74
102
  extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
- - ".github/dependabot.yml"
78
- - ".gitignore"
79
- - ".rspec"
80
- - Gemfile
105
+ - CHANGELOG.md
81
106
  - LICENSE.txt
82
107
  - README.md
83
- - Rakefile
84
- - ale_air.gemspec
85
- - config/key.sample.yml
86
108
  - lib/ale_air.rb
109
+ - lib/ale_air/errors.rb
87
110
  - lib/ale_air/fetch_json.rb
88
111
  - lib/ale_air/version.rb
89
- - spec/fetch_json_spec.rb
90
- - spec/spec_helper.rb
91
112
  homepage: https://github.com/FistOfTheNorthStar/ale_air
92
113
  licenses:
93
114
  - MIT
94
- metadata: {}
115
+ metadata:
116
+ homepage_uri: https://github.com/FistOfTheNorthStar/ale_air
117
+ source_code_uri: https://github.com/FistOfTheNorthStar/ale_air
118
+ bug_tracker_uri: https://github.com/FistOfTheNorthStar/ale_air/issues
119
+ changelog_uri: https://github.com/FistOfTheNorthStar/ale_air/blob/master/CHANGELOG.md
120
+ rubygems_mfa_required: 'true'
95
121
  post_install_message:
96
122
  rdoc_options: []
97
123
  require_paths:
@@ -100,17 +126,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
126
  requirements:
101
127
  - - ">="
102
128
  - !ruby/object:Gem::Version
103
- version: 3.2.2
129
+ version: '3.2'
104
130
  required_rubygems_version: !ruby/object:Gem::Requirement
105
131
  requirements:
106
132
  - - ">="
107
133
  - !ruby/object:Gem::Version
108
134
  version: '0'
109
135
  requirements: []
110
- rubygems_version: 3.4.10
136
+ rubygems_version: 3.0.3.1
111
137
  signing_key:
112
138
  specification_version: 4
113
139
  summary: Air Quality of Major Cities
114
- test_files:
115
- - spec/fetch_json_spec.rb
116
- - spec/spec_helper.rb
140
+ test_files: []
@@ -1,14 +0,0 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: "bundler" # See documentation for possible values
9
- directory: "/" # Location of package manifests
10
- registries: "*"
11
- schedule:
12
- interval: "weekly"
13
- day: "sunday"
14
- time: "20:00"
data/.gitignore DELETED
@@ -1,25 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- *.swp
23
- mkmf.log
24
- config/key.yml
25
- .idea/
data/.rspec DELETED
@@ -1,7 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --format documentation
4
- --profile
5
- --no-fail-fast
6
- --order define
7
-
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in testGem.gemspec
4
- gemspec
5
-
6
- gem 'rubocop'
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
data/ale_air.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ale_air/version'
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'ale_air'
8
- s.version = AleAir::VERSION
9
- s.required_ruby_version = '>= 3.2.2'
10
- s.summary = "Air Quality of Major Cities"
11
- s.description = "Easy to use air quality of major cities. Everything has been parsed for you and ready to use."
12
- s.authors = ["FistOfTheNorthStar"]
13
- s.email = ["k.kulvik@gmail.com"]
14
- s.homepage =
15
- 'https://github.com/FistOfTheNorthStar/ale_air'
16
- s.license = 'MIT'
17
-
18
- s.files = `git ls-files -z`.split("\x0")
19
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
- s.require_paths = ["lib"]
22
-
23
- s.add_dependency "rest-client"
24
- s.add_development_dependency "rspec"
25
- s.add_development_dependency "rake"
26
- s.add_development_dependency "bundler"
27
- end
@@ -1 +0,0 @@
1
- api_key: 'XXX'
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
-
5
- describe 'FetchJSON' do
6
- describe '#danger_lev' do
7
- let(:fetch_json) { AleAir::FetchJSON.new }
8
-
9
- it 'returns danger level of air according to aqi' do
10
- levels = [0, 51, 101, 151, 201, 301]
11
- danger_array = ['Good', 'Moderate', 'Unhealthy for Sensitive Groups', 'Unhealthy', 'Very Unhealthy', 'Hazardous']
12
- danger_array_append = []
13
- levels.each do |level|
14
- danger_array_append << fetch_json.send(:danger_lev, level)
15
- end
16
- expect(danger_array).to match_array(danger_array_append)
17
- end
18
- end
19
-
20
- describe '#integer?' do
21
- fetch_json = AleAir::FetchJSON.new
22
- it 'returns false on a string without value to convert' do
23
- temp_val = 'this is just a string'
24
- expect(fetch_json.send(:integer?, temp_val)).to be false
25
- end
26
-
27
- it 'returns int from a string' do
28
- expect(fetch_json.send(:integer?, '100')).to be true
29
- end
30
- end
31
-
32
- describe '#get_info' do
33
- before(:example) do
34
- @fetch_json = AleAir::FetchJSON.new
35
- end
36
-
37
- it 'send correctly formatted hash with status ok' do
38
- hash_correct = { 'status' => 'ok', 'message' => 'all good test',
39
- 'data' => [{ 'aqi' => '100', 'time' => { 'stime' => '19:00', 'tz' => '+2' },
40
- 'station' => { 'name' => 'test place' } }] }
41
- correct_array = ['100', '19:00 +2', 'Air Quality', 'Air quality: 100 AQI Moderate @ test place 19:00 +2',
42
- 'Moderate', 'ok', 'test place']
43
- response = @fetch_json.send(:get_info, hash_correct)
44
- back_array = [@fetch_json.status, @fetch_json.message, @fetch_json.quality, @fetch_json.location,
45
- @fetch_json.danger_level, @fetch_json.time_measured, @fetch_json.descriptive_text]
46
- expect(response).to be true
47
- expect(correct_array).to match_array(back_array)
48
- end
49
-
50
- it 'send nil hash should receive false' do
51
- hash_correct = ''
52
- expect(@fetch_json.send(:get_info, hash_correct)).to be false
53
- end
54
-
55
- it 'send error receive false' do
56
- hash_correct = { 'status' => 'error' }
57
- expect(@fetch_json.send(:get_info, hash_correct)).to be false
58
- end
59
- end
60
-
61
- describe '#air_quality' do
62
- it 'returns false with nil key with correct city' do
63
- fetch_json = AleAir::FetchJSON.new
64
- expect(fetch_json.air_quality('Helsinki')).to be false
65
- sleep(5)
66
- end
67
-
68
- it 'returns false with incorrect key with correct city' do
69
- fetch_json = AleAir::FetchJSON.new('ABCDSLJ')
70
- expect(fetch_json.air_quality('Helsinki')).to be false
71
- sleep(5)
72
- end
73
-
74
- it 'returns false with nonexisting name correct key' do
75
- fetch_json = AleAir::FetchJSON.new(api_key['api_key'])
76
- expect(fetch_json.air_quality('lkjlkjlkjlkjlkj')).to be false
77
- sleep(5)
78
- end
79
-
80
- it 'returns true with correct place name correct key' do
81
- fetch_json = AleAir::FetchJSON.new(api_key['api_key'])
82
- expect(fetch_json.air_quality('Helsinki')).to be true
83
- end
84
- end
85
-
86
- protected
87
-
88
- def api_key
89
- @config = YAML.load_file('./config/key.yml')
90
- end
91
- end
data/spec/spec_helper.rb DELETED
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dir['./lib/**/*.rb'].each { |file| require file }
4
- # This file was generated by the `rspec --init` command. Conventionally, all
5
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
- # The generated `.rspec` file contains `--require spec_helper` which will cause
7
- # this file to always be loaded, without a need to explicitly require it in any
8
- # files.
9
- #
10
- # Given that it is always loaded, you are encouraged to keep this file as
11
- # light-weight as possible. Requiring heavyweight dependencies from this file
12
- # will add to the boot time of your test suite on EVERY test run, even for an
13
- # individual file that may not need all of that loaded. Instead, consider making
14
- # a separate helper file that requires the additional dependencies and performs
15
- # the additional setup, and require it from the spec files that actually need
16
- # it.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- end
33
-
34
- # rspec-mocks config goes here. You can use an alternate test double
35
- # library (such as bogus or mocha) by changing the `mock_with` option here.
36
- config.mock_with :rspec do |mocks|
37
- # Prevents you from mocking or stubbing a method that does not exist on
38
- # a real object. This is generally recommended, and will default to
39
- # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
41
- end
42
-
43
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
- # have no way to turn it off -- the option exists only for backwards
45
- # compatibility in RSpec 3). It causes shared context metadata to be
46
- # inherited by the metadata hash of host groups and examples, rather than
47
- # triggering implicit auto-inclusion in groups with matching metadata.
48
- config.shared_context_metadata_behavior = :apply_to_host_groups
49
-
50
- # The settings below are suggested to provide a good initial experience
51
- # with RSpec, but feel free to customize to your heart's content.
52
- # # This allows you to limit a spec run to individual examples or groups
53
- # # you care about by tagging them with `:focus` metadata. When nothing
54
- # # is tagged with `:focus`, all examples get run. RSpec also provides
55
- # # aliases for `it`, `describe`, and `context` that include `:focus`
56
- # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
- # config.filter_run_when_matching :focus
58
- #
59
- # # Allows RSpec to persist some state between runs in order to support
60
- # # the `--only-failures` and `--next-failure` CLI options. We recommend
61
- # # you configure your source control system to ignore this file.
62
- # config.example_status_persistence_file_path = "spec/examples.txt"
63
- #
64
- # # Limits the available syntax to the non-monkey patched syntax that is
65
- # # recommended. For more details, see:
66
- # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67
- # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
- # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69
- # config.disable_monkey_patching!
70
- #
71
- # # This setting enables warnings. It's recommended, but in some cases may
72
- # # be too noisy due to issues in dependencies.
73
- # config.warnings = true
74
- #
75
- # # Many RSpec users commonly either run the entire suite or an individual
76
- # # file, and it's useful to allow more verbose output when running an
77
- # # individual spec file.
78
- # if config.files_to_run.one?
79
- # # Use the documentation formatter for detailed output,
80
- # # unless a formatter has already been configured
81
- # # (e.g. via a command-line flag).
82
- # config.default_formatter = "doc"
83
- # end
84
- #
85
- # # Print the 10 slowest examples and example groups at the
86
- # # end of the spec run, to help surface which specs are running
87
- # # particularly slow.
88
- # config.profile_examples = 10
89
- #
90
- # # Run specs in random order to surface order dependencies. If you find an
91
- # # order dependency and want to debug it, you can fix the order by providing
92
- # # the seed, which is printed after each run.
93
- # # --seed 1234
94
- # config.order = :random
95
- #
96
- # # Seed global randomization in this process using the `--seed` CLI option.
97
- # # Setting this allows you to use `--seed` to deterministically reproduce
98
- # # test failures related to randomization by passing the same `--seed` value
99
- # # as the one that triggered the failure.
100
- # Kernel.srand config.seed
101
- end