airvisual_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 99cb795e5895323f25820f36add9b3062e9a6743640990748577d69e22e831e6
4
+ data.tar.gz: c5d9f6ad94f00bb8a792f477a517b8bf7fa1e3c2acdfc38c24ed5aeafd5f92b7
5
+ SHA512:
6
+ metadata.gz: fb9c75b057e4cdb898e06fcd9719efabe42c4f71b45a2278ccdba53a0c97cb3ff7d5ff2a7f8b828438de151328427a1aa2101b8cdda201c2b7124bec1209b237
7
+ data.tar.gz: 384008d2e42b04397f970e98f493e6177dad22a11997d708ba9ea94dcf2c7f77c713ed8efcb98e9a5b4b53fb470f2208d9ce867679a853c30c3963023730b550
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in airvisual_api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ airvisual_api (0.1.0)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.4.4)
11
+ httparty (0.18.1)
12
+ mime-types (~> 3.0)
13
+ multi_xml (>= 0.5.2)
14
+ mime-types (3.3.1)
15
+ mime-types-data (~> 3.2015)
16
+ mime-types-data (3.2020.1104)
17
+ multi_xml (0.6.0)
18
+ rake (12.3.3)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.2)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ airvisual_api!
38
+ rake (~> 12.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # AirvisualApi
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/airvisual_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'airvisual_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install airvisual_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/airvisual_api.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ require_relative 'lib/airvisual_api/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "airvisual_api"
5
+ spec.version = AirVisualApi::VERSION
6
+ spec.authors = ["Joey Ferguson"]
7
+ spec.email = ["fergmastaflex@gmail.com"]
8
+
9
+ spec.summary = 'Ruby wrapper for IQAir\'s AirVisual API'
10
+ spec.description = 'A Ruby interface to retrieve air quality data from the AirVisual API based on various location types'
11
+ spec.homepage = "http://github.com/airvisual_api"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "http://github.com/airvisual_api"
18
+ spec.metadata["changelog_uri"] = "http://github.com/airvisual_api"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency 'rspec'
30
+
31
+ spec.add_runtime_dependency 'httparty'
32
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "airvisual_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "airvisual_api/version"
2
+ require 'airvisual_api/client'
3
+ require 'airvisual_api/city'
4
+
5
+ module AirVisualApi
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,31 @@
1
+ module AirVisualApi
2
+ class City
3
+ # For MVP and prototyping, I'm just going to send back raw
4
+ # HTTParty responses to the main app. Further iterations
5
+ # will see better response parsing and humanizing
6
+ # some of the key names. I can't stand abbreviation
7
+ # and jargon.
8
+
9
+ def nearest_city_by_gps(latitude:, longitude:)
10
+ # coercing to float to ensure proper formatting
11
+ # this should probably be a little smarter with some
12
+ # regex checking coupled with some ruby errors, but
13
+ # for time and prototyping sake I'm just going to coerce
14
+ latitude = latitude.to_f
15
+ longitude = longitude.to_f
16
+ client.get(url: "/nearest_city?lat=#{latitude}&lon=#{longitude}")
17
+ end
18
+
19
+ # Only going to support American states for an MVP
20
+ # Typical American exceptionalism, amirite? ;)
21
+ def city_by_name_and_state(city:, state:)
22
+ client.get(url: "/city?city=#{city}&state=#{state}&country=USA")
23
+ end
24
+
25
+ private
26
+
27
+ def client
28
+ @client ||= AirVisualApi::Client.new
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'httparty'
2
+
3
+ module AirVisualApi
4
+ class Client
5
+ BASE_URI = 'http://api.airvisual.com/v2'
6
+
7
+ def initialize(api_key: ENV['AIRVISUAL_API_KEY'])
8
+ # defaults to env variable but can be specified
9
+ @api_key = api_key
10
+ end
11
+
12
+ def get(url:)
13
+ HTTParty.get(BASE_URI + url + key_param)
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :api_key
19
+
20
+ def key_param
21
+ "&key=#{api_key}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module AirVisualApi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airvisual_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joey Ferguson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Ruby interface to retrieve air quality data from the AirVisual API
42
+ based on various location types
43
+ email:
44
+ - fergmastaflex@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - README.md
55
+ - Rakefile
56
+ - airvisual_api.gemspec
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/airvisual_api.rb
60
+ - lib/airvisual_api/city.rb
61
+ - lib/airvisual_api/client.rb
62
+ - lib/airvisual_api/version.rb
63
+ homepage: http://github.com/airvisual_api
64
+ licenses: []
65
+ metadata:
66
+ homepage_uri: http://github.com/airvisual_api
67
+ source_code_uri: http://github.com/airvisual_api
68
+ changelog_uri: http://github.com/airvisual_api
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.0.3
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Ruby wrapper for IQAir's AirVisual API
88
+ test_files: []