arcserver.rb 0.0.2
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.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/arcserver.rb.gemspec +57 -0
- data/lib/arcserver.rb +3 -0
- data/lib/arcserver/map_server.rb +24 -0
- data/lib/arcserver/rest/map_server.rb +26 -0
- data/lib/arcserver/soap/map_server.rb +86 -0
- data/lib/arcserver/url_helper.rb +25 -0
- data/test/functional/soap/map_server_test.rb +181 -0
- data/test/test_helper.rb +12 -0
- data/test/unit/map_server_test.rb +43 -0
- data/test/unit/url_helper_test.rb +54 -0
- metadata +74 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Colin Casey
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "arcserver.rb"
|
8
|
+
gem.summary = %Q{Library for accessing ESRI ArcServer REST and SOAP APIs.}
|
9
|
+
gem.email = "casey.colin@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/colincasey/arcserver.rb"
|
11
|
+
gem.authors = ["Colin Casey"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "arcserver.rb #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{arcserver.rb}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Colin Casey"]
|
12
|
+
s.date = %q{2009-09-23}
|
13
|
+
s.email = %q{casey.colin@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"arcserver.rb.gemspec",
|
26
|
+
"lib/arcserver.rb",
|
27
|
+
"lib/arcserver/map_server.rb",
|
28
|
+
"lib/arcserver/rest/map_server.rb",
|
29
|
+
"lib/arcserver/soap/map_server.rb",
|
30
|
+
"lib/arcserver/url_helper.rb",
|
31
|
+
"test/functional/soap/map_server_test.rb",
|
32
|
+
"test/test_helper.rb",
|
33
|
+
"test/unit/map_server_test.rb",
|
34
|
+
"test/unit/url_helper_test.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/colincasey/arcserver.rb}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.4}
|
40
|
+
s.summary = %q{Library for accessing ESRI ArcServer REST and SOAP APIs.}
|
41
|
+
s.test_files = [
|
42
|
+
"test/test_helper.rb",
|
43
|
+
"test/functional/soap/map_server_test.rb",
|
44
|
+
"test/unit/url_helper_test.rb",
|
45
|
+
"test/unit/map_server_test.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
else
|
54
|
+
end
|
55
|
+
else
|
56
|
+
end
|
57
|
+
end
|
data/lib/arcserver.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'arcserver/rest/map_server'
|
3
|
+
require 'arcserver/soap/map_server'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module ArcServer
|
7
|
+
class MapServer
|
8
|
+
include UrlHelper
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
attr_reader :soap_service
|
12
|
+
def_delegators :soap_service, :get_default_map_name, :get_legend_info
|
13
|
+
|
14
|
+
attr_reader :rest_service
|
15
|
+
def_delegators :rest_service, :export
|
16
|
+
|
17
|
+
def initialize(url, opts = {})
|
18
|
+
raise Exception, "#{url} is not a valid map server url" unless map_server?(url)
|
19
|
+
|
20
|
+
@soap_service = opts[:soap_service] || SOAP::MapServer.new(to_soap(url))
|
21
|
+
@rest_service = opts[:rest_service] || REST::MapServer.new(to_rest(url))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module ArcServer
|
5
|
+
module REST
|
6
|
+
class MapServer
|
7
|
+
attr_reader :url
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def export(opts = {})
|
14
|
+
query = {
|
15
|
+
:bbox => opts[:bbox],
|
16
|
+
:f => opts[:f] || :image,
|
17
|
+
:format => opts[:format] || :png24,
|
18
|
+
:transparent => opts[:transparent] || true,
|
19
|
+
:size => opts[:size],
|
20
|
+
:dpi => opts[:dpi]
|
21
|
+
}
|
22
|
+
HTTParty.get("#{url}/export", :query => query)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'handsoap'
|
3
|
+
|
4
|
+
module ArcServer
|
5
|
+
module SOAP
|
6
|
+
class MapServer < Handsoap::Service
|
7
|
+
on_create_document do |doc|
|
8
|
+
doc.alias "env", "http://schemas.xmlsoap.org/soap/envelope/"
|
9
|
+
doc.alias "ns", "http://www.esri.com/schemas/ArcGIS/9.3"
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_before_dispatch
|
13
|
+
self.class.endpoint(:uri => @soap_url, :version => 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(soap_url, protocol_version=2)
|
17
|
+
@soap_url = soap_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_default_map_name
|
21
|
+
response = invoke("ns:GetDefaultMapName")
|
22
|
+
node = response.document.xpath('//tns:GetDefaultMapNameResponse/Result', ns).first
|
23
|
+
parse_default_map_name_result(node)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_legend_info(args = {})
|
27
|
+
response = invoke("ns:GetLegendInfo") do |message|
|
28
|
+
message.add "MapName", args[:map_name] || get_default_map_name
|
29
|
+
end
|
30
|
+
node = response.document.xpath('//tns:GetLegendInfoResponse/Result', ns).first
|
31
|
+
parse_legend_info_result(node)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def ns
|
36
|
+
{ 'tns', 'http://www.esri.com/schemas/ArcGIS/9.3' }
|
37
|
+
end
|
38
|
+
|
39
|
+
# helpers
|
40
|
+
def parse_default_map_name_result(node)
|
41
|
+
xml_to_str(node, './text()')
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_legend_info_result(node)
|
45
|
+
node.xpath('./MapServerLegendInfo', ns).collect { |child| parse_map_server_legend_info(child) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_map_server_legend_info(node)
|
49
|
+
{
|
50
|
+
:layer_id => xml_to_int(node, "./LayerID/text()"),
|
51
|
+
:name => xml_to_str(node, "./Name/text()"),
|
52
|
+
:legend_groups => node.xpath('./LegendGroups/MapServerLegendGroup', ns).collect { |child| parse_map_server_legend_group(child) }
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_map_server_legend_group(node)
|
57
|
+
{
|
58
|
+
:heading => xml_to_str(node, "./Heading/text()"),
|
59
|
+
:legend_classes => node.xpath("./LegendClasses/MapServerLegendClass", ns).collect { |child| parse_map_server_legend_class(child) }
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_map_server_legend_class(node)
|
64
|
+
{
|
65
|
+
:label => xml_to_str(node, "./Label/text()"),
|
66
|
+
:descriptions => xml_to_str(node, "./Description/text()"),
|
67
|
+
:symbol_image => {
|
68
|
+
:image_data => xml_to_str(node, "./SymbolImage/ImageData/text()"),
|
69
|
+
:image_url => xml_to_str(node, "./SymbolImage/ImageURL/text()"),
|
70
|
+
:image_height => xml_to_int(node, "./SymbolImage/ImageHeight/text()"),
|
71
|
+
:image_width => xml_to_int(node, "./SymbolImage/ImageWidth/text()"),
|
72
|
+
:image_dpi => xml_to_int(node, "./SymbolImage/ImageDPI/text()")
|
73
|
+
},
|
74
|
+
:transparent_color => {
|
75
|
+
:use_windows_dithering => xml_to_bool(node, "./TransparentColor/UseWindowsDithering/text()"),
|
76
|
+
:alpha_value => xml_to_int(node, "./TransparentColor/AlphaValue/text()"),
|
77
|
+
:red => xml_to_int(node, "./TransparentColor/Red/text()"),
|
78
|
+
:green => xml_to_int(node, "./TransparentColor/Green/text()"),
|
79
|
+
:blue => xml_to_int(node, "./TransparentColor/Blue/text()")
|
80
|
+
}
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
module UrlHelper
|
5
|
+
def rest_service?(url)
|
6
|
+
url.to_s.match(/ArcGIS\/rest\/.*/)
|
7
|
+
end
|
8
|
+
|
9
|
+
def soap_service?(url)
|
10
|
+
url.to_s.match(/ArcGIS\/(?!rest\/).*/)
|
11
|
+
end
|
12
|
+
|
13
|
+
def map_server?(url)
|
14
|
+
url.to_s.match(/\/MapServer$/)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_rest(url)
|
18
|
+
rest_service?(url) ? url : url.sub('/ArcGIS/', '/ArcGIS/rest/')
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_soap(url)
|
22
|
+
soap_service?(url) ? url : url.sub('/ArcGIS/rest/', '/ArcGIS/')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
#ArcServer::SOAP::MapServer.logger = $stdout
|
6
|
+
|
7
|
+
class ArcServer::SOAP::MapServerTest < Test::Unit::TestCase
|
8
|
+
should "be able to use map services at two different locations" do
|
9
|
+
service1 = ArcServer::SOAP::MapServer.new('http://sampleserver1.arcgisonline.com/ArcGIS/services/Portland/ESRI_LandBase_WebMercator/MapServer')
|
10
|
+
service2 = ArcServer::SOAP::MapServer.new('http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics/ESRI_Census_USA/MapServer')
|
11
|
+
|
12
|
+
name1 = service1.get_default_map_name
|
13
|
+
name2 = service2.get_default_map_name
|
14
|
+
|
15
|
+
assert_equal "Portland", name1
|
16
|
+
assert_equal "Layers", name2
|
17
|
+
end
|
18
|
+
|
19
|
+
context "using ESRI's sample Portland Landbase service" do
|
20
|
+
setup do
|
21
|
+
@service = ArcServer::SOAP::MapServer.new('http://sampleserver1.arcgisonline.com/ArcGIS/services/Portland/ESRI_LandBase_WebMercator/MapServer')
|
22
|
+
end
|
23
|
+
|
24
|
+
should "get the default map name" do
|
25
|
+
assert_equal "Portland", @service.get_default_map_name
|
26
|
+
end
|
27
|
+
|
28
|
+
should "get the legend info" do
|
29
|
+
legend_info = @service.get_legend_info(:map_name => 'Portland')
|
30
|
+
legend_info.each do |item|
|
31
|
+
layer_assertion = "assert_legend_info_result_layer_#{item[:layer_id]}".to_sym
|
32
|
+
if respond_to?(layer_assertion)
|
33
|
+
send(layer_assertion, item)
|
34
|
+
else
|
35
|
+
raise "no assertions set for legend info with layer_id=#{item[:layer_id]}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "use the default map name when getting the legend info" do
|
41
|
+
legend_info = @service.get_legend_info
|
42
|
+
legend_info.each do |item|
|
43
|
+
layer_assertion = "assert_legend_info_result_layer_#{item[:layer_id]}".to_sym
|
44
|
+
if respond_to?(layer_assertion)
|
45
|
+
send(layer_assertion, item)
|
46
|
+
else
|
47
|
+
raise "no assertions set for legend info with layer_id=#{item[:layer_id]}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# legend info assertion helpers
|
54
|
+
def assert_legend_info_result_layer_1(item)
|
55
|
+
expected = {
|
56
|
+
:layer_id => 1,
|
57
|
+
:name => 'Zoomed in',
|
58
|
+
:legend_groups => [{
|
59
|
+
:legend_classes => [{
|
60
|
+
:symbol_image => {
|
61
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nR0lEQVR4nGP89/8/AzUBC4wR4O9PkckbNm5kZGBgYGCihmHIZrAgC8JsIdcwBgaoC6kJRg0cNXAw\nGIiSU6iRBanuQkZqF18AsvET5O8fag8AAAAASUVORK5CYII=\n"
|
62
|
+
}
|
63
|
+
}]
|
64
|
+
}]
|
65
|
+
}
|
66
|
+
assert_legend_info_result_layer(expected, item)
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_legend_info_result_layer_2(item)
|
70
|
+
expected = {
|
71
|
+
:layer_id => 2,
|
72
|
+
:name => 'Zoomed out',
|
73
|
+
:legend_groups => [{
|
74
|
+
:legend_classes => [{
|
75
|
+
:symbol_image => {
|
76
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nPklEQVR4nGP89/8/AzUBE1VNY2BgYIExAvz9KXbqho0bGVnQBcg1DOYgqnt51MBRA4elgShZjxr5\nmZHaxRcATwAQChHiw9IAAAAASUVORK5CYII=\n"
|
77
|
+
}
|
78
|
+
}]
|
79
|
+
}]
|
80
|
+
}
|
81
|
+
assert_legend_info_result_layer(expected, item)
|
82
|
+
end
|
83
|
+
|
84
|
+
def assert_legend_info_result_layer_3(item)
|
85
|
+
expected = {
|
86
|
+
:layer_id => 3,
|
87
|
+
:name => 'Buildings',
|
88
|
+
:legend_groups => [{
|
89
|
+
:legend_classes => [{
|
90
|
+
:symbol_image => {
|
91
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIExZtTVUeTUjKYmRgYGGrhw1MBRA0cNJAYwDvrSBgCGTgoZ\ncGsDFQAAAABJRU5ErkJggg==\n"
|
92
|
+
}
|
93
|
+
}]
|
94
|
+
}]
|
95
|
+
}
|
96
|
+
assert_legend_info_result_layer(expected, item)
|
97
|
+
end
|
98
|
+
|
99
|
+
def assert_legend_info_result_layer_4(item)
|
100
|
+
expected = {
|
101
|
+
:layer_id => 4,
|
102
|
+
:name => 'Zoning',
|
103
|
+
:legend_groups => [{
|
104
|
+
:legend_classes => [{
|
105
|
+
:label => 'Commercial',
|
106
|
+
:symbol_image => {
|
107
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIExXjAyUuRUif//GRkYaODCUQNHDRw1kBjAOOhLGwBbzgoZ\npkxTgAAAAABJRU5ErkJggg==\n"
|
108
|
+
}
|
109
|
+
}, {
|
110
|
+
:label => 'Industrial',
|
111
|
+
:symbol_image => {
|
112
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIEx2hhXUuTUqv/hjAwMNHDhqIGjBo4aSAxgHPSlDQBtTgoZ\nvbcuLAAAAABJRU5ErkJggg==\n"
|
113
|
+
}
|
114
|
+
}, {
|
115
|
+
:label => 'Residential',
|
116
|
+
:symbol_image => {
|
117
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIExGBlKKHLqf4YeRgYGGrhw1MBRA0cNJAYwDvrSBgAaUgkZ\nJEjqtwAAAABJRU5ErkJggg==\n"
|
118
|
+
}
|
119
|
+
}, {
|
120
|
+
:label => 'Mixed use',
|
121
|
+
:symbol_image => {
|
122
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIExvuW5UORUrkl7GBkYaODCUQNHDRw1kBjAOOhLGwCLTgoZ\nUbp19QAAAABJRU5ErkJggg==\n"
|
123
|
+
}
|
124
|
+
}, {
|
125
|
+
:label => 'Parks and open space',
|
126
|
+
:symbol_image => {
|
127
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nOUlEQVR4nGP89/8/AzUBE1VNY2BgYIExGBkYKHLqfwYGRgYGGrhw1MBRA0cNJAbA8zIsL1IKqO5C\nAJdcBiBRj7wXAAAAAElFTkSuQmCC\n"
|
128
|
+
}
|
129
|
+
}, {
|
130
|
+
:label => 'Rural',
|
131
|
+
:symbol_image => {
|
132
|
+
:image_data => "iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nNElEQVR4nGP89/8/AzUBE1VNY2BgYIExus+lU+TUUqOZjAwMNHDhqIGjBo4aSAxgHPSlDQCRTgoZ\nWZnonwAAAABJRU5ErkJggg==\n"
|
133
|
+
}
|
134
|
+
}]
|
135
|
+
}]
|
136
|
+
}
|
137
|
+
assert_legend_info_result_layer(expected, item)
|
138
|
+
end
|
139
|
+
|
140
|
+
def assert_legend_info_result_layer(expected, actual)
|
141
|
+
assert_equal expected[:layer_id], actual[:layer_id]
|
142
|
+
assert_equal expected[:name], actual[:name]
|
143
|
+
# check the legend groups
|
144
|
+
assert_equal expected[:legend_groups].length, actual[:legend_groups].length
|
145
|
+
actual[:legend_groups].each do |legend_group|
|
146
|
+
assert_legend_group expected[:legend_groups].shift, legend_group
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def assert_legend_group(expected, actual)
|
151
|
+
assert_equal expected[:heading], actual[:heading]
|
152
|
+
# check the legend classes
|
153
|
+
assert_equal expected[:legend_classes].length, actual[:legend_classes].length
|
154
|
+
actual[:legend_classes].each do |legend_class|
|
155
|
+
assert_legend_class expected[:legend_classes].shift, legend_class
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def assert_legend_class(expected, actual)
|
160
|
+
assert_equal expected[:label], actual[:label]
|
161
|
+
assert_equal expected[:description], actual[:description]
|
162
|
+
assert_symbol_image(expected[:symbol_image] || {}, actual[:symbol_image])
|
163
|
+
assert_transparent_color(expected[:transparent_color] || {}, actual[:transparent_color])
|
164
|
+
end
|
165
|
+
|
166
|
+
def assert_symbol_image(expected, actual)
|
167
|
+
assert_not_nil expected[:image_data] if actual[:image_data]
|
168
|
+
assert_equal expected[:image_url], actual[:image_url]
|
169
|
+
assert_equal expected[:image_height] || 16, actual[:image_height]
|
170
|
+
assert_equal expected[:image_width] || 20, actual[:image_width]
|
171
|
+
assert_equal expected[:image_dpi] || 96, actual[:image_dpi]
|
172
|
+
end
|
173
|
+
|
174
|
+
def assert_transparent_color(expected, actual)
|
175
|
+
assert_equal expected[:use_windows_dithering] || true, actual[:use_windows_dithering]
|
176
|
+
assert_equal expected[:alpha_value] || 255, actual[:alpha_value]
|
177
|
+
assert_equal expected[:red] || 254, actual[:red]
|
178
|
+
assert_equal expected[:green] || 255, actual[:green]
|
179
|
+
assert_equal expected[:blue] || 255, actual[:blue]
|
180
|
+
end
|
181
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'arcserver'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
|
4
|
+
class ArcServer::MapServerTest < Test::Unit::TestCase
|
5
|
+
should "raise an error if the required url is not a map server url" do
|
6
|
+
assert_raise(Exception) { ArcServer::MapServer.new('http://not.a.map/server/url') }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "verifying delegation of actions to the SOAP service" do
|
10
|
+
setup do
|
11
|
+
@mock_soap_service = mock
|
12
|
+
@map_server = ArcServer::MapServer.new(
|
13
|
+
'http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics/ESRI_Census_USA/MapServer',
|
14
|
+
:soap_service => @mock_soap_service
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "forward get_default_map_name" do
|
19
|
+
@mock_soap_service.expects(:get_default_map_name => nil)
|
20
|
+
@map_server.get_default_map_name
|
21
|
+
end
|
22
|
+
|
23
|
+
should "forward get_legend_info" do
|
24
|
+
@mock_soap_service.expects(:get_legend_info => nil)
|
25
|
+
@map_server.get_legend_info
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "verifying delegation of actions to the REST service" do
|
30
|
+
setup do
|
31
|
+
@mock_rest_service = mock
|
32
|
+
@map_server = ArcServer::MapServer.new(
|
33
|
+
'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer',
|
34
|
+
:rest_service => @mock_rest_service
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "forward get_default_map_name" do
|
39
|
+
@mock_rest_service.expects(:export => nil)
|
40
|
+
@map_server.export
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
|
4
|
+
class ArcServer::UrlHelperTest < Test::Unit::TestCase
|
5
|
+
include ArcServer::UrlHelper
|
6
|
+
|
7
|
+
context "when given a rest service url" do
|
8
|
+
setup do
|
9
|
+
@url = 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer'
|
10
|
+
end
|
11
|
+
|
12
|
+
should "be able to recognize it as a rest service" do
|
13
|
+
assert rest_service?(@url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "not be mistaken for a soap service" do
|
17
|
+
assert !soap_service?(@url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to convert to soap service url" do
|
21
|
+
soap_url = to_soap(@url)
|
22
|
+
assert soap_service?(soap_url)
|
23
|
+
assert !rest_service?(soap_url)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when given a soap service url" do
|
28
|
+
setup do
|
29
|
+
@url = 'http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics/ESRI_Census_USA/MapServer'
|
30
|
+
end
|
31
|
+
|
32
|
+
should "be able to recognize it as a soap service" do
|
33
|
+
assert soap_service?(@url)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not be mistaken for a rest service" do
|
37
|
+
assert !rest_service?(@url)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "be able to convert to rest service url" do
|
41
|
+
rest_url = to_rest(@url)
|
42
|
+
assert rest_service?(rest_url)
|
43
|
+
assert !soap_service?(rest_url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
should "recognize a valid map server url" do
|
48
|
+
assert map_server?('http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics/ESRI_Census_USA/MapServer')
|
49
|
+
end
|
50
|
+
|
51
|
+
should "recognize an invalid map server url" do
|
52
|
+
assert !map_server?('http://not.a.map/server/url')
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arcserver.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Colin Casey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-23 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: casey.colin@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- arcserver.rb.gemspec
|
33
|
+
- lib/arcserver.rb
|
34
|
+
- lib/arcserver/map_server.rb
|
35
|
+
- lib/arcserver/rest/map_server.rb
|
36
|
+
- lib/arcserver/soap/map_server.rb
|
37
|
+
- lib/arcserver/url_helper.rb
|
38
|
+
- test/functional/soap/map_server_test.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- test/unit/map_server_test.rb
|
41
|
+
- test/unit/url_helper_test.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/colincasey/arcserver.rb
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.4
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Library for accessing ESRI ArcServer REST and SOAP APIs.
|
70
|
+
test_files:
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/functional/soap/map_server_test.rb
|
73
|
+
- test/unit/url_helper_test.rb
|
74
|
+
- test/unit/map_server_test.rb
|