air-condition-api 0.1.1
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 +7 -0
- data/lib/air-condition-api.rb +68 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a428a70414a56c0e8524578401e3135177db2709
|
4
|
+
data.tar.gz: cb978eb320aa4977b8430858559048f613a1cf0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 446e2a6a4778e588c435330a520a2eea43638b3c920ec98f89f5d3d13aecb85e36677ef532c6db6262ffc615c13331be0085435f348d4efa97ef77c7b22add70
|
7
|
+
data.tar.gz: 529360eca6f1e06b26cb8988c26e320d467176b28af90f6032b621d371d036345e4a57ee056da6a9f14fa43ecdcbf1f4764813056620769a4b043fbd3f544674
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# Air Condition API Helper
|
3
|
+
#
|
4
|
+
# last update 2017.05.11
|
5
|
+
#
|
6
|
+
# hwj4477@gmail.com
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'net/http'
|
10
|
+
require 'uri'
|
11
|
+
require 'oga'
|
12
|
+
|
13
|
+
REQUEST_API = "http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/"
|
14
|
+
|
15
|
+
API_AREA = "#{REQUEST_API}getCtprvnRltmMesureDnsty"
|
16
|
+
|
17
|
+
class AirCondition
|
18
|
+
|
19
|
+
attr_accessor :data
|
20
|
+
|
21
|
+
def request_api_area(api_key, area_name)
|
22
|
+
|
23
|
+
param = Hash.new
|
24
|
+
param["serviceKey"] = URI.unescape(api_key)
|
25
|
+
param["sidoName"] = area_name
|
26
|
+
param["ver"] = 1.3
|
27
|
+
|
28
|
+
uri = URI.parse(API_AREA)
|
29
|
+
uri.query = URI.encode_www_form(param)
|
30
|
+
|
31
|
+
response = Net::HTTP.get_response(uri)
|
32
|
+
|
33
|
+
unless response.code.to_i == 200
|
34
|
+
|
35
|
+
yield false, response.body
|
36
|
+
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
# parse data
|
41
|
+
xml_data = Oga.parse_xml(response.body)
|
42
|
+
self.data = Array.new
|
43
|
+
|
44
|
+
xml_data.xpath('response/body/items/item').each do |item|
|
45
|
+
|
46
|
+
station_name = item.at_xpath('stationName').text
|
47
|
+
condition_day = item.at_xpath('pm10Grade').text.to_i
|
48
|
+
condition_hour = item.at_xpath('pm10Grade1H').text.to_i
|
49
|
+
|
50
|
+
self.data.push ConditionData.new(station_name, condition_day, condition_hour)
|
51
|
+
end
|
52
|
+
|
53
|
+
yield true, nil
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class ConditionData
|
60
|
+
|
61
|
+
attr_accessor :station_name, :condition_day, :condition_hour
|
62
|
+
|
63
|
+
def initialize(station_name, condition_day, condition_hour)
|
64
|
+
@station_name = station_name
|
65
|
+
@condition_day = condition_day
|
66
|
+
@condition_hour = condition_hour
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: air-condition-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hwj4477
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Air Condition API Helper (from [https://www.data.go.kr])
|
14
|
+
email: hwj4477@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib//air-condition-api.rb
|
20
|
+
homepage: http://github.com/hwj4477/air-condition-api
|
21
|
+
licenses:
|
22
|
+
- hwj4477
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.8
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Air Condition API
|
44
|
+
test_files: []
|