pm25 0.0.1

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
+ SHA1:
3
+ metadata.gz: 9d4e9cf8a047d64cfb512a1b1e34b74c757bca21
4
+ data.tar.gz: 8b3d11aecaec6fd94ee6a3e13f4b8b5b6e77e8c4
5
+ SHA512:
6
+ metadata.gz: f4e2a47f1af8ff811132040b5e92365df8773906129e5af96b127f8352d9e56d24eb0b62787afbeb578c9590649f5711a5452cd78637eab2a42ca1756e49b647
7
+ data.tar.gz: 34a8c136097602f86e226a1b88eea5d1fc21c4866d2e39bbcdfe0f959f8e6f27a0365e542a3c37badaf994eda0c61f86c75f59a24dac211b900c7bae8f3648a5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pm25.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', group: :test
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Xuhao
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # PM25
2
+
3
+ [![Build Status](https://www.travis-ci.org/ekohe/pm25.png?branch=master)](https://www.travis-ci.org/ekohe/pm25)
4
+ [![Code Climate](https://codeclimate.com/github/ekohe/pm25.png)](https://codeclimate.com/github/ekohe/pm25)
5
+
6
+ PM2.5 and ozone readings Data From U.S. Consulate.
7
+
8
+ Include below cities of China:
9
+
10
+ - Beijing
11
+ - Shanghai
12
+ - Chengdu
13
+ - Guangzhou
14
+ - Shenyang
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'pm25'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install pm25
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ # Beijing
34
+ PM25::Beijing.get
35
+ # => return an array include current and history data:
36
+ # [{"title"=>"06/04/2013 6:00:00 PM",
37
+ # "link"=>"http://www.stateair.net/web/post/1/1.html",
38
+ # "description"=>
39
+ # "06-04-2013 18:00; PM2.5; 71.0; 159; Unhealthy (at 24-hour exposure at this level)",
40
+ # "Param"=>"PM2.5",
41
+ # "Conc"=>"71.0",
42
+ # "AQI"=>"159",
43
+ # "Desc"=>"Unhealthy (at 24-hour exposure at this level)",
44
+ # "ReadingDateTime"=>"06/04/2013 6:00:00 PM"},
45
+ # {"title"=>"06/04/2013 5:00:00 PM",
46
+ # ......
47
+
48
+ # Shanghai
49
+ PM25::Shanghai.get
50
+
51
+ # Chengdu
52
+ PM25::Chengdu.get
53
+
54
+ # Guangzhou
55
+ PM25::Guangzhou.get
56
+
57
+ # Shenyang
58
+ PM25::Shenyang.get
59
+ ```
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
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
data/lib/pm25/base.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'httparty'
2
+ require 'active_support/core_ext/class/attribute'
3
+ require 'active_support/core_ext/hash/conversions'
4
+ module PM25
5
+ class Base
6
+ include HTTParty
7
+
8
+ class_attribute :base_uri, :city_id
9
+ self.base_uri = URI::HTTP.build({host: 'www.stateair.net'})
10
+
11
+ def self.get
12
+ Hash.from_xml(HTTParty.get(url).body)['rss']['channel']['item']
13
+ end
14
+
15
+ def self.uri
16
+ raise NotImplementedError, "Please set value for 'city_id' class attributes in '#{self.name}' class." unless self.city_id
17
+ self.base_uri.path = "/web/rss/1/#{self.city_id.to_s}.xml"
18
+ self.base_uri
19
+ end
20
+
21
+ def self.url
22
+ uri.to_s
23
+ end
24
+ end
25
+ end
26
+
27
+ require 'pm25/cities/beijing'
28
+ require 'pm25/cities/chengdu'
29
+ require 'pm25/cities/guangzhou'
30
+ require 'pm25/cities/shanghai'
31
+ require 'pm25/cities/shenyang'
@@ -0,0 +1,5 @@
1
+ module PM25
2
+ class Beijing < Base
3
+ self.city_id = '1'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module PM25
2
+ class Chengdu < Base
3
+ self.city_id = '2'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module PM25
2
+ class Guangzhou < Base
3
+ self.city_id = '3'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module PM25
2
+ class Shanghai < Base
3
+ self.city_id = '4'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module PM25
2
+ class Shenyang < Base
3
+ self.city_id = '5'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PM25
2
+ class NotImplementedError < StandardError; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Pm25
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pm25.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "pm25/version"
2
+
3
+ module PM25;end
4
+
5
+ require "pm25/base"
data/pm25.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pm25/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pm25"
8
+ spec.version = Pm25::VERSION
9
+ spec.authors = ["Xuhao"]
10
+ spec.email = ["xuhao@rubyfans.com"]
11
+ spec.description = %q{PM2.5 reporting from U.S. Consulate}
12
+ spec.summary = %q{PM2.5 reporting from U.S. Consulate}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency 'activesupport'
25
+ spec.add_dependency 'httparty'
26
+ end
data/spec/pm25_spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pm25 do
4
+ it 'should have a version number' do
5
+ Pm25::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_false
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'pm25'
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pm25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Xuhao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: PM2.5 reporting from U.S. Consulate
84
+ email:
85
+ - xuhao@rubyfans.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/pm25.rb
98
+ - lib/pm25/base.rb
99
+ - lib/pm25/cities/beijing.rb
100
+ - lib/pm25/cities/chengdu.rb
101
+ - lib/pm25/cities/guangzhou.rb
102
+ - lib/pm25/cities/shanghai.rb
103
+ - lib/pm25/cities/shenyang.rb
104
+ - lib/pm25/exceptions.rb
105
+ - lib/pm25/version.rb
106
+ - pm25.gemspec
107
+ - spec/pm25_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: ''
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: PM2.5 reporting from U.S. Consulate
133
+ test_files:
134
+ - spec/pm25_spec.rb
135
+ - spec/spec_helper.rb