arcserver.rb 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +274 -0
- data/LICENSE +20 -20
- data/README.md +160 -0
- data/Rakefile +9 -62
- data/arcserver.rb.gemspec +35 -0
- data/lib/arcserver.rb +33 -7
- data/lib/arcserver/Identifiable.rb +10 -0
- data/lib/arcserver/Queryable.rb +10 -0
- data/lib/arcserver/feature_server.rb +19 -0
- data/lib/arcserver/geometry/geometry.rb +91 -0
- data/lib/arcserver/geometry_service.rb +18 -0
- data/lib/arcserver/gp_server.rb +20 -0
- data/lib/arcserver/graphics/feature.rb +23 -0
- data/lib/arcserver/graphics/feature_set.rb +26 -0
- data/lib/arcserver/map_server.rb +34 -40
- data/lib/arcserver/rest/feature_server.rb +30 -0
- data/lib/arcserver/rest/geometry_service.rb +54 -0
- data/lib/arcserver/rest/gp_server.rb +80 -0
- data/lib/arcserver/rest/identify.rb +66 -0
- data/lib/arcserver/rest/map_server.rb +230 -230
- data/lib/arcserver/rest/query.rb +68 -0
- data/lib/arcserver/url_helper.rb +31 -25
- data/lib/arcserver/util/legend_image.rb +0 -0
- data/lib/arcserver/version.rb +6 -6
- data/spec/custom_spec.rb +50 -0
- data/spec/factories/feature.rb +21 -0
- data/spec/feature_server_spec.rb +52 -0
- data/spec/feature_spec.rb +20 -0
- data/spec/geometry_service_spec.rb +31 -0
- data/spec/geometry_spec.rb +80 -0
- data/spec/gp_server_spec.rb +57 -0
- data/spec/identify_spec.rb +21 -0
- data/spec/query_spec.rb +38 -0
- data/spec/shared_context.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- metadata +217 -158
- data/README.rdoc +0 -57
- data/lib/arcserver/soap/map_server.rb +0 -263
- data/test/functional/soap/map_server_test.rb +0 -193
- data/test/test_helper.rb +0 -25
- data/test/unit/map_server_test.rb +0 -61
- data/test/unit/url_helper_test.rb +0 -54
- data/test/unit/util/legend_image_test.rb +0 -69
data/Rakefile
CHANGED
@@ -1,62 +1,9 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
task :default => :test
|
12
|
-
|
13
|
-
namespace :test do
|
14
|
-
desc "Run unit tests"
|
15
|
-
Rake::TestTask.new(:unit) do |test|
|
16
|
-
test.libs << 'lib' << 'test'
|
17
|
-
test.pattern = 'test/unit/**/*_test.rb'
|
18
|
-
test.verbose = true
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "Run functional tests"
|
22
|
-
Rake::TestTask.new(:functional) do |test|
|
23
|
-
test.libs << 'lib' << 'test'
|
24
|
-
test.pattern = 'test/functional/**/*_test.rb'
|
25
|
-
test.verbose = true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
Rake::RDocTask.new do |rdoc|
|
30
|
-
rdoc.rdoc_dir = 'rdoc'
|
31
|
-
rdoc.title = "arcserver.rb #{ArcServer::VERSION}"
|
32
|
-
rdoc.rdoc_files.include('README*')
|
33
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'yard'
|
39
|
-
YARD::Rake::YardocTask.new do |t|
|
40
|
-
t.files = ['lib/**/*.rb']
|
41
|
-
end
|
42
|
-
rescue LoadError
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "Build arcserver.rb gem"
|
47
|
-
task :build do
|
48
|
-
system "gem build arcserver.rb.gemspec"
|
49
|
-
|
50
|
-
base_dir = File.dirname(__FILE__)
|
51
|
-
pkg_dir = File.join(base_dir, "pkg")
|
52
|
-
FileUtils.mkdir_p pkg_dir
|
53
|
-
|
54
|
-
gem_file_name = File.join(base_dir, "arcserver.rb-#{ArcServer::VERSION}.gem")
|
55
|
-
FileUtils.mv(gem_file_name, pkg_dir)
|
56
|
-
end
|
57
|
-
|
58
|
-
desc "Release arcserver.rb gem"
|
59
|
-
task :release => :build do
|
60
|
-
system "gem push pkg/arcserver.rb-#{ArcServer::VERSION}"
|
61
|
-
end
|
62
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'arcserver/version'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
task :test => :spec
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new('spec')
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arcserver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "arcserver.rb"
|
8
|
+
s.version = ArcServer::VERSION
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.authors = ["Luca Simone"]
|
11
|
+
s.date = "2013-08-28"
|
12
|
+
s.email = ["info@lucasimone.info"]
|
13
|
+
s.homepage = "http://github.com/lukefx/arcserver.rb"
|
14
|
+
s.summary = "A library for accessing ESRI ArcServer REST APIs from a unified interface"
|
15
|
+
s.description = "A library for accessing ESRI ArcServer REST APIs from a unified interface"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'activesupport'
|
23
|
+
s.add_runtime_dependency 'httparty'
|
24
|
+
s.add_runtime_dependency 'nokogiri'
|
25
|
+
s.add_runtime_dependency 'httpclient'
|
26
|
+
s.add_runtime_dependency 'json'
|
27
|
+
s.add_runtime_dependency 'rufus-scheduler'
|
28
|
+
|
29
|
+
s.add_development_dependency 'bundler'
|
30
|
+
s.add_development_dependency 'rake'
|
31
|
+
s.add_development_dependency 'sdoc'
|
32
|
+
s.add_development_dependency 'rspec'
|
33
|
+
s.add_development_dependency 'factory_girl'
|
34
|
+
|
35
|
+
end
|
data/lib/arcserver.rb
CHANGED
@@ -1,7 +1,33 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
require '
|
7
|
-
require '
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'httparty'
|
5
|
+
require 'forwardable'
|
6
|
+
require 'rufus-scheduler'
|
7
|
+
require 'active_support/all'
|
8
|
+
# require 'active_support/core_ext/hash/indifferent_access'
|
9
|
+
|
10
|
+
require 'arcserver/version'
|
11
|
+
require 'arcserver/url_helper'
|
12
|
+
require 'arcserver/Identifiable'
|
13
|
+
require 'arcserver/Queryable'
|
14
|
+
require 'arcserver/map_server'
|
15
|
+
require 'arcserver/geometry_service'
|
16
|
+
require 'arcserver/feature_server'
|
17
|
+
require 'arcserver/gp_server'
|
18
|
+
require 'arcserver/geometry/geometry'
|
19
|
+
require 'arcserver/graphics/feature_set'
|
20
|
+
require 'arcserver/graphics/feature'
|
21
|
+
require 'arcserver/rest/map_server'
|
22
|
+
require 'arcserver/rest/geometry_service'
|
23
|
+
require 'arcserver/rest/feature_server'
|
24
|
+
require 'arcserver/rest/query'
|
25
|
+
require 'arcserver/rest/identify'
|
26
|
+
require 'arcserver/rest/gp_server'
|
27
|
+
|
28
|
+
# monkeypath OpenStruct
|
29
|
+
class OpenStruct
|
30
|
+
def as_json(options = nil)
|
31
|
+
table.as_json(options)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
class FeatureServer
|
5
|
+
|
6
|
+
include UrlHelper
|
7
|
+
include Queryable
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
attr_reader :rest_service
|
11
|
+
def_delegators :rest_service, :url, :applyEdits
|
12
|
+
|
13
|
+
def initialize(url, opts = {})
|
14
|
+
raise Exception, "#{url} is not a valid feature server url" unless feature_server?(url)
|
15
|
+
@rest_service = opts[:rest_service] || REST::FeatureServer.new(to_rest(url))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module ArcServer
|
2
|
+
module Geometry
|
3
|
+
|
4
|
+
class Geometry < OpenStruct
|
5
|
+
|
6
|
+
attr_accessor :spatialReference
|
7
|
+
|
8
|
+
def self.build(geometry, geometryType)
|
9
|
+
klass = {
|
10
|
+
esriGeometryPoint: ArcServer::Geometry::Point,
|
11
|
+
esriGeometryMultipoint: ArcServer::Geometry::Multipoint,
|
12
|
+
esriGeometryPolygon: ArcServer::Geometry::Polygon,
|
13
|
+
esriGeometryPolyline: ArcServer::Geometry::Polyline,
|
14
|
+
esriGeometryEnvelope: ArcServer::Geometry::Envelope,
|
15
|
+
}[geometryType.to_sym]
|
16
|
+
klass.new(geometry) rescue nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(json)
|
20
|
+
|
21
|
+
parsed = json.is_a?(Hash) ? json : JSON.parse(json) rescue {}
|
22
|
+
|
23
|
+
if parsed['x']
|
24
|
+
ArcServer::Geometry::Point.new(parsed)
|
25
|
+
elsif parsed['paths']
|
26
|
+
ArcServer::Geometry::Polyline.new(parsed)
|
27
|
+
elsif parsed['rings']
|
28
|
+
ArcServer::Geometry::Polygon.new(parsed)
|
29
|
+
elsif parsed['points']
|
30
|
+
ArcServer::Geometry::Multipoint.new(parsed)
|
31
|
+
elsif parsed['ymax']
|
32
|
+
ArcServer::Geometry::Envelope.new(parsed)
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def geometryType
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def extent
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class Point < Geometry
|
50
|
+
|
51
|
+
def geometryType
|
52
|
+
"esriGeometryPoint"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class Multipoint < Geometry
|
58
|
+
def geometryType
|
59
|
+
"esriGeometryMultipoint"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Polygon < Geometry
|
64
|
+
|
65
|
+
def geometryType
|
66
|
+
"esriGeometryPolygon"
|
67
|
+
end
|
68
|
+
|
69
|
+
def extent
|
70
|
+
poly = self.rings.flatten
|
71
|
+
x = poly.values_at(*poly.each_index.select {|i| i.even?})
|
72
|
+
y = poly.values_at(*poly.each_index.select {|i| i.odd?})
|
73
|
+
[x.min, y.min, x.max, y.max]
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class Polyline < Geometry
|
79
|
+
def geometryType
|
80
|
+
"esriGeometryPolyline"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Envelope < Geometry
|
85
|
+
def geometryType
|
86
|
+
"esriGeometryEnvelope"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
class GeometryService
|
5
|
+
|
6
|
+
include UrlHelper
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
attr_reader :rest_service
|
10
|
+
def_delegators :rest_service, :url, :project, :buffer
|
11
|
+
|
12
|
+
def initialize(url, opts = {})
|
13
|
+
raise Exception, "#{url} is not a valid Geometry Service url" unless geometry_service?(url)
|
14
|
+
@rest_service = opts[:rest_service] || REST::GeometryService.new(to_rest(url))
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
class ArcServerError < StandardError; end
|
5
|
+
|
6
|
+
class GPServer
|
7
|
+
|
8
|
+
include UrlHelper
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
attr_reader :rest_service
|
12
|
+
def_delegators :rest_service, :url, :submitJob, :execute
|
13
|
+
|
14
|
+
def initialize(url, opts = {})
|
15
|
+
raise Exception, "#{url} is not a valid map server url" unless gp_server?(url)
|
16
|
+
@rest_service = opts[:rest_service] || REST::GPServer.new(to_rest(url))
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ArcServer
|
2
|
+
module Graphics
|
3
|
+
class Feature
|
4
|
+
|
5
|
+
attr_accessor :geometry, :attributes
|
6
|
+
|
7
|
+
def initialize(attr={})
|
8
|
+
@geometry = attr[:geometry]
|
9
|
+
@attributes = attr[:attributes] || { }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(json)
|
13
|
+
parsed = (json.is_a?(Hash) ? json : JSON.parse(json)).with_indifferent_access
|
14
|
+
Feature.new({ geometry: ArcServer::Geometry::Geometry.create(parsed['geometry']), attributes: parsed['attributes'] })
|
15
|
+
end
|
16
|
+
|
17
|
+
# def [](key)
|
18
|
+
# send key
|
19
|
+
# end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ArcServer
|
2
|
+
module Graphics
|
3
|
+
class FeatureSet
|
4
|
+
|
5
|
+
# include Enumerable
|
6
|
+
|
7
|
+
attr_accessor :displayFieldName, :geometryType, :fieldAliases, :features
|
8
|
+
|
9
|
+
def initialize(attrs={})
|
10
|
+
@fieldAliases = attrs[:fields] if attrs[:fields]
|
11
|
+
@geometryType = attrs[:geometryType] if attrs[:geometryType]
|
12
|
+
|
13
|
+
if attrs[:features]
|
14
|
+
@features = attrs[:features].map { |f| f.is_a?(Feature) ? f : Feature.create(f) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# self
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty?
|
21
|
+
@features.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/arcserver/map_server.rb
CHANGED
@@ -1,40 +1,34 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
raise ArcServerError, "#{self.class}#get_legend_image needs an optional dependency 'RMagick [>= 2.12.0]' to be installed - try `gem install rmagick`"
|
36
|
-
end
|
37
|
-
Util::LegendImage.new(self).get_image
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
class ArcServerError < StandardError; end
|
5
|
+
|
6
|
+
class MapServer
|
7
|
+
|
8
|
+
include UrlHelper
|
9
|
+
include Identifiable
|
10
|
+
include Queryable
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
attr_reader :rest_service
|
14
|
+
def_delegators :rest_service, :url, :export
|
15
|
+
|
16
|
+
def initialize(url, opts = {})
|
17
|
+
raise Exception, "#{url} is not a valid map server url" unless map_server?(url)
|
18
|
+
@rest_service = opts[:rest_service] || REST::MapServer.new(to_rest(url))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Utility method for generating a legend image
|
22
|
+
# (requires optional dependency, RMagick [>= 2.12.0], to be installed)
|
23
|
+
#
|
24
|
+
# @return [Magick::Image] the legend as an RMagick Image object
|
25
|
+
def get_legend_image
|
26
|
+
begin
|
27
|
+
require 'RMagick' unless Object.const_defined?("Magick")
|
28
|
+
rescue LoadError
|
29
|
+
raise ArcServerError, "#{self.class}#get_legend_image needs an optional dependency 'RMagick [>= 2.12.0]' to be installed - try `gem install rmagick`"
|
30
|
+
end
|
31
|
+
Util::LegendImage.new(self).get_image
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|