ale_air 0.0.6 → 0.0.8

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: 2a35e5053e3d933d5b7eb69d1584745685ea3fdc
4
- data.tar.gz: bbfbe540eb33fd389185e31fea87e46764363a8d
3
+ metadata.gz: 236de19ba776e22ce1ba00b8ec550acaaee3e6af
4
+ data.tar.gz: 0459e6112e4a416cc0a7371b09dd9047888469c2
5
5
  SHA512:
6
- metadata.gz: 06fe6626332fd4ae0d0fb3ec1b2f3a43e723e51221378a68cbd4a48449f351d0342bdc40e539cb4f94fb1efb97cb2222d198c32ae1088202cbd3ae5d2a27e28a
7
- data.tar.gz: d2813ec13feee278cb1f668111fb3bfe9e75d412e3a873e6f35cb9e266132ae6bcc234bcca5e2b772f5970ddfc682ec3860aab3ea31c4ac3cbafa74c38c854c2
6
+ metadata.gz: a6131fce0250abc79903196bb33e837d03333eb130c60ce8aec8c191e57d1f6a2ae6b9f0d1c210fbd1b30f67385c54e179af4c5fb2541240f4bd9194460deb61
7
+ data.tar.gz: 7c650bae6f188da1e1714e2835dab8ad6b0773a7448fae5e3e153f9ac8bd622a019b2d9999ab4f5983167444bfb806fde6d47123fa4126c6c0737b53202723a9
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ tmp
21
21
  *.a
22
22
  *.swp
23
23
  mkmf.log
24
+ config/key.yml
data/.rspec CHANGED
@@ -1,6 +1,6 @@
1
1
  --color
2
2
  --require spec_helper
3
- --format progress
3
+ --format documentation
4
4
  --profile
5
5
  --no-fail-fast
6
6
  --order define
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'rest-client'
22
+ s.add_dependency "rest-client"
23
23
  s.add_development_dependency "rspec"
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "bundler"
@@ -0,0 +1 @@
1
+ api_key: 'XXX'
@@ -6,7 +6,7 @@ module AleAir
6
6
  attr_writer :secret_token
7
7
  attr_reader :status, :message, :time_measured, :location, :quality, :danger_level, :irc_string
8
8
 
9
- def initialize(token = nil)
9
+ def initialize(token = '')
10
10
  @secret_token = token
11
11
  end
12
12
 
@@ -49,7 +49,6 @@ module AleAir
49
49
  @message = "No Stations Found"
50
50
  end
51
51
  else
52
-
53
52
  if !document["data"].nil?
54
53
  @message = document["data"]
55
54
  else
@@ -1,3 +1,3 @@
1
1
  module AleAir
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'rest-client'
4
+ require 'yaml'
5
+
6
+ describe 'FetchJSON' do
7
+
8
+ describe '#danger_lev' do
9
+
10
+ it "returns danger level of air string according to aqi" do
11
+ fetch_json = AleAir::FetchJSON.new
12
+ levels = [0,51,101,151,201,301]
13
+ danger_array = ["Good", "Moderate", "Unhealthy for Sensitive Groups", "Unhealthy", "Very Unhealthy", "Hazardous"]
14
+ danger_array_append = []
15
+ levels.each do |level|
16
+ danger_array_append << fetch_json.send(:danger_lev, level)
17
+ end
18
+ expect(danger_array).to match_array(danger_array_append)
19
+ end
20
+ end
21
+
22
+ describe '#is_int' do
23
+ fetch_json = AleAir::FetchJSON.new
24
+ it "returns false on a string without value to convert" do
25
+ temp_val = "this is just a string"
26
+ expect(fetch_json.send(:is_int, temp_val)).to be false
27
+ end
28
+
29
+ it "returns int from a string" do
30
+ expect(fetch_json.send(:is_int, "100")).to be true
31
+ end
32
+ end
33
+
34
+ describe "#get_info" do
35
+
36
+ it 'send correctly formatted hash with status ok' do
37
+ hash_correct = {"status" => "ok", "message" => "all good test", "data" => [{"aqi" => "100", "time" => {"stime" => "19:00", "tz" => "+2"}, "station" => {"name" => "test place"}}]}
38
+ correct_array = ["ok", "Air Quality", "Moderate", "100", "19:00 +2", "test place", "Air quality: 100 AQI Moderate @ test place 19:00 +2"]
39
+ fetch_json = AleAir::FetchJSON.new
40
+ got_back = fetch_json.send(:get_info, hash_correct)
41
+ back_array = []
42
+ back_array << fetch_json.status
43
+ back_array << fetch_json.message
44
+ back_array << fetch_json.quality
45
+ back_array << fetch_json.location
46
+ back_array << fetch_json.danger_level
47
+ back_array << fetch_json.time_measured
48
+ back_array << fetch_json.irc_string
49
+ expect(got_back).to be true
50
+ expect(correct_array).to match_array(back_array)
51
+ end
52
+
53
+ it 'send nil hash should receive false' do
54
+ hash_correct = nil
55
+ fetch_json = AleAir::FetchJSON.new
56
+ expect(fetch_json.send(:get_info, hash_correct)).to be false
57
+
58
+ end
59
+
60
+ it 'send error receive false' do
61
+ hash_correct = {"status" => "error"}
62
+ fetch_json = AleAir::FetchJSON.new
63
+ expect(fetch_json.send(:get_info, hash_correct)).to be false
64
+ end
65
+
66
+ end
67
+
68
+ describe "#air_quality" do
69
+
70
+ it 'returns false with nil key with correct city' do
71
+ fetch_json = AleAir::FetchJSON.new
72
+ expect(fetch_json.air_quality('Helsinki')).to be false
73
+ sleep(5)
74
+ end
75
+
76
+ it 'returns false with incorrect key with correct city' do
77
+ fetch_json = AleAir::FetchJSON.new('ABCDSLJ')
78
+ expect(fetch_json.air_quality('Helsinki')).to be false
79
+ sleep(5)
80
+ end
81
+
82
+ it 'returns false with nonexisting name correct key' do
83
+ fetch_json = AleAir::FetchJSON.new(api_key['api_key'])
84
+ expect(fetch_json.air_quality('lkjlkjlkjlkjlkj')).to be false
85
+ sleep(5)
86
+ end
87
+
88
+ it 'returns true with correct place name correct key' do
89
+ fetch_json = AleAir::FetchJSON.new(api_key['api_key'])
90
+ expect(fetch_json.air_quality('Helsinki')).to be true
91
+ end
92
+ end
93
+
94
+ protected
95
+ def api_key
96
+ @config = YAML.load_file("./config/key.yml")
97
+ end
98
+
99
+ end
@@ -0,0 +1,101 @@
1
+ Dir['./lib/**/*.rb'].each { |file| require file }
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
5
+ # this file to always be loaded, without a need to explicitly require it in any
6
+ # files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need
14
+ # it.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
42
+ # have no way to turn it off -- the option exists only for backwards
43
+ # compatibility in RSpec 3). It causes shared context metadata to be
44
+ # inherited by the metadata hash of host groups and examples, rather than
45
+ # triggering implicit auto-inclusion in groups with matching metadata.
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+ =begin
51
+ # This allows you to limit a spec run to individual examples or groups
52
+ # you care about by tagging them with `:focus` metadata. When nothing
53
+ # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ config.filter_run_when_matching :focus
57
+
58
+ # Allows RSpec to persist some state between runs in order to support
59
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # you configure your source control system to ignore this file.
61
+ config.example_status_persistence_file_path = "spec/examples.txt"
62
+
63
+ # Limits the available syntax to the non-monkey patched syntax that is
64
+ # recommended. For more details, see:
65
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ config.disable_monkey_patching!
69
+
70
+ # This setting enables warnings. It's recommended, but in some cases may
71
+ # be too noisy due to issues in dependencies.
72
+ config.warnings = true
73
+
74
+ # Many RSpec users commonly either run the entire suite or an individual
75
+ # file, and it's useful to allow more verbose output when running an
76
+ # individual spec file.
77
+ if config.files_to_run.one?
78
+ # Use the documentation formatter for detailed output,
79
+ # unless a formatter has already been configured
80
+ # (e.g. via a command-line flag).
81
+ config.default_formatter = "doc"
82
+ end
83
+
84
+ # Print the 10 slowest examples and example groups at the
85
+ # end of the spec run, to help surface which specs are running
86
+ # particularly slow.
87
+ config.profile_examples = 10
88
+
89
+ # Run specs in random order to surface order dependencies. If you find an
90
+ # order dependency and want to debug it, you can fix the order by providing
91
+ # the seed, which is printed after each run.
92
+ # --seed 1234
93
+ config.order = :random
94
+
95
+ # Seed global randomization in this process using the `--seed` CLI option.
96
+ # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # test failures related to randomization by passing the same `--seed` value
98
+ # as the one that triggered the failure.
99
+ Kernel.srand config.seed
100
+ =end
101
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ale_air
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - FistOfTheNorthStar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -81,9 +81,12 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - ale_air.gemspec
84
+ - config/key.sample.yml
84
85
  - lib/ale_air.rb
85
86
  - lib/ale_air/fetch_json.rb
86
87
  - lib/ale_air/version.rb
88
+ - spec/fetch_json_spec.rb
89
+ - spec/spec_helper.rb
87
90
  homepage: https://github.com/FistOfTheNorthStar/ale_air
88
91
  licenses:
89
92
  - MIT
@@ -108,4 +111,6 @@ rubygems_version: 2.2.2
108
111
  signing_key:
109
112
  specification_version: 4
110
113
  summary: Air Quality of Major Cities
111
- test_files: []
114
+ test_files:
115
+ - spec/fetch_json_spec.rb
116
+ - spec/spec_helper.rb