sos-core 0.1.3 → 0.1.6
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 +4 -4
- data/lib/{board_of_directors/boss.rb → boss.rb} +5 -1
- data/lib/{sos_helper/capability.rb → capability.rb} +28 -7
- data/lib/company.rb +4 -0
- data/lib/employees/fes.rb +0 -1
- data/lib/employees/gml.rb +0 -1
- data/lib/employees/gml/gmlTime.rb +26 -0
- data/lib/employees/gml/timePeriod.rb +1 -5
- data/lib/employees/mankind/people.rb +3 -3
- data/lib/employees/sos.rb +0 -1
- data/lib/employees/sos/contents.rb +41 -0
- data/lib/employees/sos/offering.rb +2 -0
- data/lib/employees/sos/time.rb +58 -0
- data/lib/employees/swes/offering.rb +79 -0
- data/lib/{board_of_directors/factory/factory.rb → factory.rb} +1 -0
- data/lib/{board_of_directors/factory/hashMerge.rb → hashMerge.rb} +0 -0
- data/lib/{sos_helper/node.rb → node.rb} +0 -0
- data/lib/{sos_helper/observation.rb → observation.rb} +36 -14
- data/lib/{sos_helper → request}/getObservation.xml +0 -0
- data/lib/sos-core.rb +20 -18
- data/lib/sosHelper.rb +26 -0
- data/lib/tags.rb +17 -0
- data/lib/xmlRequest.rb +64 -0
- metadata +17 -12
- data/lib/sos-helper.rb +0 -21
- data/lib/sos_helper/offering.rb +0 -49
- data/lib/sos_helper/xmlRequest.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d24d9de1e66d3babc6b47ae1a25f7b54aeb48301
|
4
|
+
data.tar.gz: 8088d4d5254b2488abf5d3f0389bd02bb40c5ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a420feec4eb02fe24c44231b70bae0bae77767c307c8499e246022dedc9615a276f7dd845a6a74a47a6b4612de59b54a5a405f5694ca357bda106ee216e16a09
|
7
|
+
data.tar.gz: 8a643d43183318cc9da7f6b93d674d12459f77b4fff9ad72a2851c45013a663f3ddfd4783897109467c127fdf2c4136a8287b317985f2ae5edbf7e576762e4f2
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'company.rb'
|
2
|
+
|
1
3
|
module SOSHelper
|
2
4
|
|
3
5
|
# Boss Assign the tasks
|
@@ -19,6 +21,7 @@ module SOSHelper
|
|
19
21
|
results = pm.done
|
20
22
|
summarize @base, results.dup
|
21
23
|
end
|
24
|
+
# p @base.to_xml
|
22
25
|
|
23
26
|
@base
|
24
27
|
end
|
@@ -42,7 +45,8 @@ module SOSHelper
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def recognize_employee
|
45
|
-
|
48
|
+
employee = capitalize @employee
|
49
|
+
eval( employee + ".new")
|
46
50
|
end
|
47
51
|
|
48
52
|
def capitalize(employee)
|
@@ -1,23 +1,44 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require_relative 'employees/sos/contents.rb'
|
3
|
+
|
1
4
|
module SOSHelper
|
5
|
+
class Capability
|
6
|
+
def initialize(args={})
|
7
|
+
@root = args[:root].dup
|
8
|
+
end
|
9
|
+
|
10
|
+
def contents
|
11
|
+
contents = @root.xpath("//sos:Contents")
|
12
|
+
Contents.new(contents)
|
13
|
+
end
|
14
|
+
|
15
|
+
def filterCapabilities
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def extension
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
2
25
|
class GetCapability
|
3
26
|
|
27
|
+
attr_reader :capabilities
|
4
28
|
def initialize(args={})
|
5
29
|
@request = args[:request]
|
6
30
|
@url = args[:url]
|
7
31
|
@query = {}
|
8
|
-
@allowedValue = {}
|
9
32
|
@capabilities = nil
|
10
33
|
end
|
11
34
|
|
12
35
|
def send(query={})
|
13
36
|
query[:service] = query[:service] || "SOS"
|
14
37
|
query[:request] = query[:request] || "GetCapabilities"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@allowedValue = check Relics
|
38
|
+
query[:version] = query[:version] || "2.0.0"
|
39
|
+
@capabilities = request.get(query) do |str| xml = Nokogiri::XML(str)
|
40
|
+
Capability.new(root: xml)
|
41
|
+
end
|
21
42
|
end
|
22
43
|
|
23
44
|
private
|
data/lib/company.rb
ADDED
data/lib/employees/fes.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative 'man.rb'
|
2
1
|
Dir[ File.dirname(__FILE__) + "/fes/expression/*.rb"].each {|file| require file }
|
3
2
|
Dir[ File.dirname(__FILE__) + "/fes/comparisonOps/*.rb"].each {|file| require file }
|
4
3
|
Dir[ File.dirname(__FILE__) + "/fes/extensionOps/*.rb"].each {|file| require file }
|
data/lib/employees/gml.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
|
4
|
+
class Time
|
5
|
+
def toTimeZone(time=nil)
|
6
|
+
return time.utc.iso8601 unless time.nil?
|
7
|
+
self.utc.iso8601
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class GMLTime < Time
|
12
|
+
def initialize(time)
|
13
|
+
@time = toDateTime time
|
14
|
+
super *(@time.to_a[0..5].reverse)
|
15
|
+
end
|
16
|
+
|
17
|
+
def toTimeZone(time=nil)
|
18
|
+
return time.utc.iso8601 unless time.nil?
|
19
|
+
@time.utc.iso8601
|
20
|
+
end
|
21
|
+
|
22
|
+
def toDateTime(time=nil)
|
23
|
+
return Time.parse(time).localtime unless time.nil?
|
24
|
+
Time.parse(@time).localtime
|
25
|
+
end
|
26
|
+
end
|
@@ -11,7 +11,7 @@ class TimePeriod < Complicated
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def custom(value)
|
14
|
-
begin_time, end_time =
|
14
|
+
begin_time, end_time = value.split " "
|
15
15
|
position("begin", begin_time) + position("end", end_time)
|
16
16
|
end
|
17
17
|
|
@@ -19,10 +19,6 @@ class TimePeriod < Complicated
|
|
19
19
|
"<gml:#{where}Position>#{time}</gml:#{where}Position>"
|
20
20
|
end
|
21
21
|
|
22
|
-
def splitPosition(value)
|
23
|
-
value.split " "
|
24
|
-
end
|
25
|
-
|
26
22
|
def tag_name
|
27
23
|
class_name
|
28
24
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class People
|
2
|
-
def initialize(
|
3
|
-
@tasks = tasks.to_a
|
2
|
+
def initialize()
|
4
3
|
@attributes = ""
|
5
4
|
end
|
6
5
|
|
@@ -16,7 +15,7 @@ class People
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def inspect
|
19
|
-
|
18
|
+
self.to_s
|
20
19
|
end
|
21
20
|
|
22
21
|
def inject(task)
|
@@ -44,6 +43,7 @@ class People
|
|
44
43
|
end
|
45
44
|
|
46
45
|
def attributes(attrs)
|
46
|
+
p attrs
|
47
47
|
attrs.each { |k, v| @attributes += " #{namespace}" + k.to_s + "=\"" + v.to_a[0] + "\"" }
|
48
48
|
end
|
49
49
|
|
data/lib/employees/sos.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative '../swes/offering.rb'
|
2
|
+
|
3
|
+
|
4
|
+
class Contents
|
5
|
+
def initialize(contents)
|
6
|
+
@contents = contents
|
7
|
+
end
|
8
|
+
|
9
|
+
def offerings
|
10
|
+
offerings = @contents.xpath("//swes:offering")
|
11
|
+
@offering = @offering || get(offerings) || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(offerings)
|
15
|
+
offerings.map { |offering| SWES::Offering.new(offering) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def procedureDescriptionFormat
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def observableProperty
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def relatedFeature
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def responseFormat
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def featureOfInterestType
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def observationType
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../gml/gmlTime.rb'
|
2
|
+
|
3
|
+
class SOSTime
|
4
|
+
def initialize(time)
|
5
|
+
@time = checkTimeType time
|
6
|
+
end
|
7
|
+
|
8
|
+
def timeInstant(time)
|
9
|
+
time.xpath(".//gml:TimeInstant")
|
10
|
+
end
|
11
|
+
|
12
|
+
def timePeriod(time)
|
13
|
+
time.xpath(".//gml:TimePeriod")
|
14
|
+
end
|
15
|
+
|
16
|
+
def range(beginTime=beginPosition, endTime=endPosition)
|
17
|
+
beginTime.toTimeZone + " " + endTime.toTimeZone
|
18
|
+
end
|
19
|
+
|
20
|
+
def timePosition
|
21
|
+
@instant ||= gmlTime find("gml:timePosition")
|
22
|
+
end
|
23
|
+
|
24
|
+
def beginPosition
|
25
|
+
@begin ||= gmlTime find("gml:beginPosition")
|
26
|
+
end
|
27
|
+
|
28
|
+
def endPosition
|
29
|
+
|
30
|
+
@end ||= gmlTime find("gml:endPosition")
|
31
|
+
end
|
32
|
+
|
33
|
+
def gmlTime(time)
|
34
|
+
GMLTime.new time unless time.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def find(tag)
|
38
|
+
@time.xpath(".//" + tag).text
|
39
|
+
end
|
40
|
+
|
41
|
+
def checkTimeType(time)
|
42
|
+
type = timeInstant time
|
43
|
+
type = timePeriod time if type.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
time = timePosition.nil? ? "@begin: #{beginPosition}, @end: #{endPosition}" : "@intant: #{@instant}"
|
48
|
+
"PhenomenonTime: #{time}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class PhenomenonTime < SOSTime
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class ResultTime < SOSTime
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../mankind/Complicated.rb'
|
2
|
+
require_relative '../sos/time.rb'
|
3
|
+
|
4
|
+
module SWES
|
5
|
+
class Offering < Complicated
|
6
|
+
attr_accessor :keys
|
7
|
+
def initialize(offering)
|
8
|
+
@offering = offering
|
9
|
+
@keys = [ :identifier,
|
10
|
+
:procedure,
|
11
|
+
:procedureDescriptionFormats,
|
12
|
+
:observableProperty,
|
13
|
+
:phenomenonTime,
|
14
|
+
:resultTime,
|
15
|
+
:responseFormat ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def identifier
|
19
|
+
@identifier ||= find("swes:identifier")
|
20
|
+
end
|
21
|
+
|
22
|
+
def procedure
|
23
|
+
@procedure ||= find("swes:procedure")
|
24
|
+
end
|
25
|
+
|
26
|
+
def procedureDescriptionFormats
|
27
|
+
@procedureDescriptionFormats ||=
|
28
|
+
findAll("swes:procedureDescriptionFormat")
|
29
|
+
end
|
30
|
+
|
31
|
+
def observableProperty
|
32
|
+
@observableProperty ||=
|
33
|
+
findAll("swes:observableProperty")
|
34
|
+
end
|
35
|
+
|
36
|
+
def observedArea
|
37
|
+
@observedArea
|
38
|
+
end
|
39
|
+
|
40
|
+
def responseFormat
|
41
|
+
@responseFormat ||=
|
42
|
+
findAll "sos:responseFormat"
|
43
|
+
end
|
44
|
+
|
45
|
+
def phenomenonTime
|
46
|
+
PhenomenonTime.new find("sos:phenomenonTime", false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def resultTime
|
50
|
+
ResultTime.new find("sos:resultTime", false)
|
51
|
+
end
|
52
|
+
|
53
|
+
def find(tag, text=true)
|
54
|
+
return @offering.xpath(".//" + tag).text if text
|
55
|
+
@offering.xpath(".//" + tag)
|
56
|
+
end
|
57
|
+
|
58
|
+
def findAll(tag)
|
59
|
+
@offering.xpath(".//" + tag).map { |tag| tag.text }
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
id = identifier.ascii_only? ? identifier : "UTF-16"
|
64
|
+
"Offering: @id='#{id}'"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.name
|
68
|
+
self.new().class.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def tag_name
|
72
|
+
self.class.to_s.split("::")[1]
|
73
|
+
end
|
74
|
+
|
75
|
+
def namespace
|
76
|
+
"swes:"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
File without changes
|
File without changes
|
@@ -1,8 +1,23 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module SOSHelper
|
2
4
|
|
3
5
|
class Observation
|
4
|
-
def initialize(
|
5
|
-
|
6
|
+
def initialize(str)
|
7
|
+
@xml = Nokogiri::XML(str)
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
datalist = @xml.xpath("//sos:observationData")
|
12
|
+
@output = datalist.map { |data| [data.xpath(".//gml:timePosition").text, data.xpath(".//om:result").text] }
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
{ data: output }.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def output
|
20
|
+
@output ||= []
|
6
21
|
end
|
7
22
|
end
|
8
23
|
|
@@ -15,6 +30,7 @@ module SOSHelper
|
|
15
30
|
@request = args[:request]
|
16
31
|
@xml = ObservationRequest.dup
|
17
32
|
@request_body = nil
|
33
|
+
@tp = []
|
18
34
|
@body = ""
|
19
35
|
end
|
20
36
|
|
@@ -35,7 +51,7 @@ module SOSHelper
|
|
35
51
|
raise ArgumentError, 'Filters need to be hash' unless custom.is_a? Hash
|
36
52
|
return condition.to_s if custom == {}
|
37
53
|
condition.merge! custom
|
38
|
-
|
54
|
+
p condition
|
39
55
|
self
|
40
56
|
end
|
41
57
|
|
@@ -47,19 +63,29 @@ module SOSHelper
|
|
47
63
|
@condition ||= Factory.new()
|
48
64
|
end
|
49
65
|
|
50
|
-
def offering(
|
51
|
-
filter({offering:
|
66
|
+
def offering=(list)
|
67
|
+
filter({offering: list})
|
68
|
+
end
|
69
|
+
|
70
|
+
def procedure=(list)
|
71
|
+
filter({procedure: list})
|
52
72
|
end
|
53
73
|
|
54
|
-
def
|
55
|
-
filter({
|
74
|
+
def observedProperty=(list)
|
75
|
+
filter({observedProperty: list})
|
56
76
|
end
|
57
77
|
|
58
|
-
def
|
59
|
-
|
78
|
+
def randomID
|
79
|
+
tp = "tp_" + rand(100000000).to_s
|
80
|
+
(unique? tp) ? tp : randomID
|
60
81
|
end
|
61
82
|
|
62
|
-
def
|
83
|
+
def unique?(tp)
|
84
|
+
not @tp.include? tp
|
85
|
+
end
|
86
|
+
|
87
|
+
def temporalFilter=(id=randomID, range)
|
88
|
+
@tp << randomID
|
63
89
|
filter({ temporalFilter: {
|
64
90
|
during: {
|
65
91
|
valueReference: "phenomenonTime",
|
@@ -68,10 +94,6 @@ module SOSHelper
|
|
68
94
|
})
|
69
95
|
end
|
70
96
|
|
71
|
-
def responseFormat(text)
|
72
|
-
filter({responseFormat: text})
|
73
|
-
end
|
74
|
-
|
75
97
|
end
|
76
98
|
|
77
99
|
end
|
File without changes
|
data/lib/sos-core.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'xmlRequest.rb'
|
2
|
+
require_relative 'sosHelper.rb'
|
2
3
|
|
3
|
-
|
4
|
+
# Usage:
|
5
|
+
# s = SOS.new("Url")
|
6
|
+
# s.getCapabilities => return All capabilities
|
7
|
+
# s.getObservations(condition)
|
8
|
+
# => set the filter to get observations
|
9
|
+
# s.offering => return all offerings from @capability
|
10
|
+
|
11
|
+
# url = "http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service"
|
12
|
+
# s = SOS.new("YourService")
|
4
13
|
|
14
|
+
class SOS
|
15
|
+
attr_reader :capabilities
|
5
16
|
def initialize(url, args={})
|
6
17
|
# request to http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service
|
7
18
|
@request = XmlRequest.new(url)
|
8
|
-
@capabilities =
|
19
|
+
@capabilities = nil
|
9
20
|
@observations, @gc, @go = nil
|
10
|
-
end
|
11
21
|
|
12
|
-
def allowedValue
|
13
|
-
@allowedValue ||= checkAllowedValues
|
14
22
|
end
|
15
|
-
|
23
|
+
|
16
24
|
def getCapabilities(query={})
|
17
25
|
@gc = SOSHelper::GetCapability.new(request: @request)
|
18
|
-
@
|
19
|
-
|
20
|
-
|
21
|
-
def checkAllowedValues
|
22
|
-
@gc.checkAllowedValues
|
26
|
+
@gc.send
|
27
|
+
@capabilities = @gc.capabilities
|
23
28
|
end
|
24
29
|
|
25
|
-
def getObservations
|
30
|
+
def getObservations
|
26
31
|
@go = SOSHelper::GetObservation.new(request: @request)
|
27
|
-
filter condition unless condition == {}
|
28
|
-
@go
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
@offerings
|
34
|
+
def offerings
|
35
|
+
@offerings ||= @capabilities.contents.offerings
|
33
36
|
end
|
34
|
-
|
35
37
|
end
|
data/lib/sosHelper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'set'
|
3
|
+
require_relative 'boss'
|
4
|
+
require_relative 'factory'
|
5
|
+
require_relative 'capability'
|
6
|
+
require_relative 'observation'
|
7
|
+
|
8
|
+
module SOSHelper
|
9
|
+
Urls = ["http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service",
|
10
|
+
"http://cgis.csrsr.ncu.edu.tw:8080/epa-sos/service",
|
11
|
+
"http://cgis.csrsr.ncu.edu.tw:8080/epa-aqx-sos/service"].freeze
|
12
|
+
|
13
|
+
Relics = ["offering","observedProperty",
|
14
|
+
"featureOfInterest",
|
15
|
+
"procedure", "spatialFilter",
|
16
|
+
"temporalFilter", "responseFormat"].freeze
|
17
|
+
|
18
|
+
fpath = File.dirname(__FILE__) + "/request/getObservation.xml"
|
19
|
+
ObservationRequest = File.open( fpath ) { |f| Nokogiri::XML(f) }.freeze
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# o = SOSHelper::GetObservation.new
|
24
|
+
# o.filter({:offering => "鳳義坑"}).filter({:observedProperty => "urn:ogc:def:phenomenon:OGC:1.0.30:rainfall_1day"})
|
25
|
+
# c = o.filter({:temporalFilter => :during })
|
26
|
+
# p c
|
data/lib/tags.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module SOSHelper
|
2
|
+
Ruler = {offering: "sos:offering",
|
3
|
+
procedure: "sos:procedure",
|
4
|
+
observedProperty: "sos:observedProperty",
|
5
|
+
featureOfInterest: "sos:featureOfInterest",
|
6
|
+
spatialFilter: "sos:spatialFilter",
|
7
|
+
temporalFilter: "sos:temporalFilter",
|
8
|
+
responseFormat: "sos:responseFormat",
|
9
|
+
after: "fes:After",
|
10
|
+
during: "fes:During",
|
11
|
+
tequals: "fes:TEquals",
|
12
|
+
valueReference: "fes:ValueReference",
|
13
|
+
timePeriod: "gml:TimePeriod",
|
14
|
+
beginPosition: "gml:beginPosition",
|
15
|
+
endPosition: "gml:endPosition" }
|
16
|
+
|
17
|
+
end
|
data/lib/xmlRequest.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
# To send get or post request with custom payload.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
# => hello = XmlRequest.new( uri )
|
9
|
+
# => hello.get({service: "SOS", request: "GetCapabilities"})
|
10
|
+
#
|
11
|
+
class XmlRequest
|
12
|
+
|
13
|
+
attr_accessor :uri, :packet, :post
|
14
|
+
|
15
|
+
def initialize(url)
|
16
|
+
@uri = url
|
17
|
+
@packet = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
@query = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(body=nil, &block)
|
22
|
+
@post = Net::HTTP::Post.new(uri.path)
|
23
|
+
@post["Content-type"] = "application/xml"
|
24
|
+
@post.body = body
|
25
|
+
File.new("./response/send_post", "w").write body
|
26
|
+
@res = send @post
|
27
|
+
@result = yield @res.body if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(query={}, &block)
|
31
|
+
fullPath = path_combine query
|
32
|
+
@get = Net::HTTP::Get.new(fullPath)
|
33
|
+
@res = send @get
|
34
|
+
File.new("./response/tmp_GetCapability", "w").write @res.body
|
35
|
+
@result = yield @res.body if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def uri
|
41
|
+
URI(@uri)
|
42
|
+
end
|
43
|
+
|
44
|
+
def path_combine(query={})
|
45
|
+
params = URI.encode_www_form(query)
|
46
|
+
[uri.path, params].join('?')
|
47
|
+
end
|
48
|
+
|
49
|
+
def send(action)
|
50
|
+
@packet.request( action )
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# xml = '<?xml version="1.0" encoding="UTF-8"?>
|
56
|
+
# <GetObservation service="SOS" version="2.0.0" xmlns="http://www.opengis.net/sos/2.0" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/32" xmlns:ogc="http://www.opengis.net/ogc" xmlns:om="http://www.opengis.net/om/1.0" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd">
|
57
|
+
# <procedure>urn:ogc:object:feature:Sensor:SWCB:sensor鳳義坑</procedure>
|
58
|
+
# <offering>鳳義坑</offering>
|
59
|
+
# <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:rainfall_1day</observedProperty>
|
60
|
+
|
61
|
+
# <responseFormat>application/json</responseFormat>
|
62
|
+
# </GetObservation>'
|
63
|
+
|
64
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sos-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A helper for Sensor Observation Service
|
14
14
|
email: k471352@gmail.com
|
@@ -16,9 +16,9 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/
|
20
|
-
- lib/
|
21
|
-
- lib/
|
19
|
+
- lib/boss.rb
|
20
|
+
- lib/capability.rb
|
21
|
+
- lib/company.rb
|
22
22
|
- lib/employees/fes.rb
|
23
23
|
- lib/employees/fes/comparisonOps/propertyIsBetween.rb
|
24
24
|
- lib/employees/fes/comparisonOps/propertyIsEqualTo.rb
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/employees/gml/end.rb
|
67
67
|
- lib/employees/gml/envelope.rb
|
68
68
|
- lib/employees/gml/exterior.rb
|
69
|
+
- lib/employees/gml/gmlTime.rb
|
69
70
|
- lib/employees/gml/linearRing.rb
|
70
71
|
- lib/employees/gml/lowerCorner.rb
|
71
72
|
- lib/employees/gml/polygon.rb
|
@@ -79,16 +80,20 @@ files:
|
|
79
80
|
- lib/employees/mankind/people.rb
|
80
81
|
- lib/employees/mankind/simple.rb
|
81
82
|
- lib/employees/sos.rb
|
83
|
+
- lib/employees/sos/contents.rb
|
82
84
|
- lib/employees/sos/offering.rb
|
83
85
|
- lib/employees/sos/temporalFilter.rb
|
86
|
+
- lib/employees/sos/time.rb
|
87
|
+
- lib/employees/swes/offering.rb
|
88
|
+
- lib/factory.rb
|
89
|
+
- lib/hashMerge.rb
|
90
|
+
- lib/node.rb
|
91
|
+
- lib/observation.rb
|
92
|
+
- lib/request/getObservation.xml
|
84
93
|
- lib/sos-core.rb
|
85
|
-
- lib/
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
- lib/sos_helper/node.rb
|
89
|
-
- lib/sos_helper/observation.rb
|
90
|
-
- lib/sos_helper/offering.rb
|
91
|
-
- lib/sos_helper/xmlRequest.rb
|
94
|
+
- lib/sosHelper.rb
|
95
|
+
- lib/tags.rb
|
96
|
+
- lib/xmlRequest.rb
|
92
97
|
homepage: https://github.com/MOSapeizer/SOS
|
93
98
|
licenses:
|
94
99
|
- MIT
|
data/lib/sos-helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'nokogiri'
|
3
|
-
Dir[ File.dirname(__FILE__) + "/employees/*.rb"].each {|file| require file }
|
4
|
-
require_relative 'board_of_directors/factory/factory.rb'
|
5
|
-
require_relative 'board_of_directors/boss.rb'
|
6
|
-
Dir[ File.dirname(__FILE__) + "/sos_helper/*.rb"].each {|file| require file }
|
7
|
-
|
8
|
-
module SOSHelper
|
9
|
-
Dir[ File.dirname(__FILE__) + "/sos_helper/*.rb"]
|
10
|
-
Urls = ["http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service",
|
11
|
-
"http://cgis.csrsr.ncu.edu.tw:8080/epa-sos/service",
|
12
|
-
"http://cgis.csrsr.ncu.edu.tw:8080/epa-aqx-sos/service"].freeze
|
13
|
-
|
14
|
-
Relics = ["offering","observedProperty",
|
15
|
-
"featureOfInterest",
|
16
|
-
"procedure", "spatialFilter",
|
17
|
-
"temporalFilter", "responseFormat"].freeze
|
18
|
-
|
19
|
-
ObservationRequest = File.open(File.dirname(__FILE__) + '/sos_helper/getObservation.xml') { |f| Nokogiri::XML(f) }.freeze
|
20
|
-
|
21
|
-
end
|
data/lib/sos_helper/offering.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require_relative 'node'
|
2
|
-
|
3
|
-
module SOSHelper
|
4
|
-
class Offering
|
5
|
-
ATRRIBUTES = [ :identifier, :procedure, :observableProperty, :observedArea, :resultTime, :phenomenonTime, :node ]
|
6
|
-
ATRRIBUTES.each { |t| attr_reader t }
|
7
|
-
|
8
|
-
def initialize(xml_offer)
|
9
|
-
@node = Node.new xml_offer
|
10
|
-
@id, @procedure = getText(:id), getText(:procedure)
|
11
|
-
@observableProperty = getList(:observableProperty)
|
12
|
-
@observedArea = getHash(:observedArea, [:lowerCorner, :upperCorner])
|
13
|
-
@phenomenonTime = getHash(:phenomenonTime, [:begin, :end])
|
14
|
-
@resultTime = getHash(:resultTime, [:begin, :end])
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def getText(name)
|
19
|
-
@node[name].text
|
20
|
-
end
|
21
|
-
|
22
|
-
def getList(name)
|
23
|
-
@node[name].children.map { |node| node.text }
|
24
|
-
end
|
25
|
-
|
26
|
-
def getHash(name, scope=[])
|
27
|
-
hash = {}
|
28
|
-
scope.each { |s| hash.store(s, @node[name][s].text )} unless scope.empty?
|
29
|
-
hash
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_json
|
33
|
-
{ "identifier": @id,
|
34
|
-
"procedure": @procedure,
|
35
|
-
"observableProperty": @observableProperty,
|
36
|
-
"observedArea": @observedArea,
|
37
|
-
"phenomenonTime": @phenomenonTime,
|
38
|
-
"resultTime": @resultTime }
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_s
|
42
|
-
to_json.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
# p a.node.inspect
|
49
|
-
# p a.to_json
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require "uri"
|
2
|
-
require "net/http"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
# To send get or post request with custom payload.
|
6
|
-
#
|
7
|
-
# Usage:
|
8
|
-
# => hello = XmlRequest.new( uri )
|
9
|
-
# => hello.get({service: "SOS", request: "GetCapabilities"})
|
10
|
-
#
|
11
|
-
class XmlRequest
|
12
|
-
|
13
|
-
attr_accessor :uri, :packet, :post
|
14
|
-
|
15
|
-
def initialize(url)
|
16
|
-
@uri = url
|
17
|
-
@packet = Net::HTTP.new(uri.host, uri.port)
|
18
|
-
@query = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def post(body=nil, &block)
|
22
|
-
@post = Net::HTTP::Post.new(uri.path)
|
23
|
-
@post["Content-type"] = "application/xml"
|
24
|
-
@post.body = body
|
25
|
-
# File.new("./request/request-tmp", "w").write body.dup
|
26
|
-
p body, "packet sending, it may take times to get response..."
|
27
|
-
@res = send @post
|
28
|
-
@result = yield @res.body if block_given?
|
29
|
-
end
|
30
|
-
|
31
|
-
def get(query={}, &block)
|
32
|
-
fullPath = path_combine query
|
33
|
-
@get = Net::HTTP::Get.new(fullPath)
|
34
|
-
@res = send @get
|
35
|
-
@result = yield @res.body if block_given?
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def uri
|
41
|
-
URI(@uri)
|
42
|
-
end
|
43
|
-
|
44
|
-
def path_combine(query={})
|
45
|
-
params = URI.encode_www_form(query)
|
46
|
-
[uri.path, params].join('?')
|
47
|
-
end
|
48
|
-
|
49
|
-
def send(action)
|
50
|
-
@packet.request( action )
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|