arcrest 0.0.0.pre → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.gitlab-ci.yml +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/Gemfile +2 -0
- data/Guardfile +9 -0
- data/README.md +134 -4
- data/Rakefile +2 -0
- data/arcrest.gemspec +17 -9
- data/bin/console +3 -8
- data/bin/setup +0 -2
- data/lib/arcrest.rb +8 -3
- data/lib/arcrest/attributable.rb +22 -0
- data/lib/arcrest/catalog.rb +24 -0
- data/lib/arcrest/curlable.rb +32 -0
- data/lib/arcrest/layer.rb +96 -0
- data/lib/arcrest/server.rb +62 -0
- data/lib/arcrest/service.rb +29 -0
- data/lib/arcrest/version.rb +3 -1
- metadata +94 -17
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 948d7b288f2b704e1437945ec175ad399e2d419edce9692c042009f36af2f072
|
4
|
+
data.tar.gz: a63cb3c9e7efacff80129324d6a3ad5f947170b6932fef3fa117bed207b0096f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb831237a571a7928ca0736094545c4bd3ef530faad8c6d9873d7eb6c9a55718d2b5acf006586ae87850aa43f3f00de85d2e14bb197cf8a986d6a1641a6f5645
|
7
|
+
data.tar.gz: f53a0d06535c3a932571e369ffa98a429d17db3edb70cf9b7eee6ad0f09ad38c09b0c0baeed8a62bacfb6825ce2ff4c01297136bbdb03e5891160283de4fcf0e
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
before_script:
|
3
|
+
- apt-get update -qq
|
4
|
+
- gem install bundler
|
5
|
+
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
6
|
+
|
7
|
+
.job_template: &job_definition
|
8
|
+
image: ruby:2.7.2
|
9
|
+
|
10
|
+
test:
|
11
|
+
<<: *job_definition
|
12
|
+
timeout: 10m
|
13
|
+
script:
|
14
|
+
- bundle exec rake spec
|
15
|
+
- bundle exec rubocop
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
notification :libnotify, transient: true, append: false, urgency: :critical
|
4
|
+
|
5
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
6
|
+
watch(%r{^lib/(.+).rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^spec/(.+).rb$}) { |m| "spec/#{m[1]}.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
9
|
+
end
|
data/README.md
CHANGED
@@ -1,19 +1,149 @@
|
|
1
|
-
#
|
1
|
+
# ArcREST
|
2
2
|
|
3
|
-
|
3
|
+
Ruby Gem wrapper around the [ArcGIS REST API](https://services.arcgisonline.com/arcgis/sdk/rest/)
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
Ruby >= 2.4
|
8
|
+
|
9
|
+
|
10
|
+
## Current Limitations
|
11
|
+
|
12
|
+
API FeatureServer query capabilities only at present.
|
4
13
|
|
5
14
|
## Installation
|
6
15
|
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
$ gem 'arcrest'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
7
26
|
$ gem install arcrest
|
8
27
|
|
28
|
+
|
9
29
|
## Usage
|
10
30
|
|
11
|
-
|
31
|
+
The API defines a [resource heirarchy](http://services.arcgisonline.com/arcgis/sdk/rest/#/Resource_hierarchy) which includes a Catalog of Services (MapServer or FeatureServer). Services have one or more Layers and Layers have Features, which may be queried in various ways, including by spatial coordinates.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'arcrest'
|
35
|
+
|
36
|
+
catalog = ArcREST::Catalog.new 'https://sampleserver6.arcgisonline.com/arcgis/rest/services'
|
37
|
+
puts catalog.services
|
38
|
+
#=> {"name"=>"911CallsHotspot", "type"=>"GPServer"}
|
39
|
+
#=> {"name"=>"911CallsHotspot", "type"=>"MapServer"}
|
40
|
+
#=> {"name"=>"Census", "type"=>"MapServer"}
|
41
|
+
...
|
42
|
+
|
43
|
+
puts catalog.folders
|
44
|
+
#=> AGP
|
45
|
+
#=> Elevation
|
46
|
+
#=> Energy
|
47
|
+
...
|
48
|
+
```
|
49
|
+
It is also possible to pass a Referer (or any other) header which will be added to all HTTP requests:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
catalog = ArcREST::Catalog.new('https://gojdippmaps.azurewebsites.net/proxy.ashx?https://maps.gov.je/arcgis/rest/services', headers: {referer: 'https://www.gov.je//citizen/Planning/Pages/HistoricEnvironmentDetail.aspx'})
|
53
|
+
```
|
54
|
+
|
55
|
+
A Service (FeatureServer) is instantiated like this:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
service = ArcREST::Service.new 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/FeatureServer'
|
59
|
+
puts service.layers
|
60
|
+
#=> {"id"=>0, "name"=>"Emergency Facilities", "parentLayerId"=>-1, "defaultVisibility"=>true, "subLayerIds"=>nil, "minScale"=>150000, "maxScale"=>0, "type"=>"Feature Layer", "geometryType"=>"esriGeometryPoint"}
|
61
|
+
|
62
|
+
layer = ArcREST::Layer.new "#{service.url}/0"
|
63
|
+
puts layer.name
|
64
|
+
#=> Emergency Facilities
|
65
|
+
|
66
|
+
puts layer.type
|
67
|
+
#=> Feature Layer
|
68
|
+
|
69
|
+
puts layer.max_record_count
|
70
|
+
#=> 1000 # maximum number of features that can be queried, see below
|
71
|
+
|
72
|
+
puts layer.count
|
73
|
+
#=> 16 # count of the layer's features
|
74
|
+
|
75
|
+
puts layer.object_ids.inspect
|
76
|
+
#=> [29489, 29503, 29490, 29491, 29492, 29493, 29494, 29495, 29496, 29497, 29498, 29499, 29500, 29501, 29502, 29504]
|
77
|
+
|
78
|
+
puts layer.fields
|
79
|
+
#=> {"name"=>"objectid", "type"=>"esriFieldTypeOID", "alias"=>"OBJECTID", "domain"=>nil, "editable"=>false, "nullable"=>false, "defaultValue"=>nil, "modelName"=>"System-maintained ObjectID"}
|
80
|
+
#=> {"name"=>"facilityid", "type"=>"esriFieldTypeString", "alias"=>"Emergency Facility ID", "domain"=>nil, "editable"=>true, "nullable"=>true, "length"=>20, "defaultValue"=>nil, "modelName"=>"FACILITYID"},
|
81
|
+
...
|
82
|
+
```
|
83
|
+
|
84
|
+
Catalog, Service and Layer have a ```json``` method which returns information from the relevant server as a Hash. In addition to the example methods above this can be parsed in the usual way - e.g:
|
85
|
+
```ruby
|
86
|
+
puts layer.json.keys.inspect
|
87
|
+
#=> ["currentVersion", "id", "name", "type", "parentLayer", "defaultVisibility", ...
|
88
|
+
```
|
89
|
+
|
90
|
+
Once you have a Layer object, you can perform queries on it. The [documention](https://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/02ss0000002r000000/) shows the possibilities. Here is a very simple example:
|
91
|
+
|
92
|
+
The ```query``` method returns the whole server response as a Hash:
|
93
|
+
```ruby
|
94
|
+
puts layer.query(where: '1=0').inspect
|
95
|
+
#=> {"objectIdFieldName"=>"objectid", "globalIdFieldName"=>"globalid", "geometryType"=>"esriGeometryPoint", "spatialReference"=>{"wkid"=>4326, "latestWkid"=>4326}, "features"=>[]}
|
96
|
+
```
|
97
|
+
|
98
|
+
If you just want the features, use the ```features``` method:
|
99
|
+
```ruby
|
100
|
+
puts features.count
|
101
|
+
#=> 16
|
102
|
+
|
103
|
+
puts features[1]
|
104
|
+
#=> {"attributes"=>{"objectid"=>29503, "facilityid"=>"K2032", "facname"=>"Redlands Mall", "factype"=>3, ...
|
105
|
+
|
106
|
+
features = layer.features(where: "factype=3", returnGeometry: false)
|
107
|
+
puts features.size
|
108
|
+
#=> 7
|
109
|
+
|
110
|
+
puts features.first['attributes']
|
111
|
+
#=> {"objectid"=>29503, "facilityid"=>"K2032", "facname"=>"Redlands Mall", "factype"=>3, "organiz"=>"City of Redlands", ...
|
112
|
+
```
|
113
|
+
|
114
|
+
```query``` and ```features``` take an options hash of API call params. Invalid key values raise an error. Valid params for the server can be listed like this:
|
115
|
+
```ruby
|
116
|
+
puts layer.valid_opts.inspect
|
117
|
+
#=> ["dbVersion", "distance", "geometry", "geometryPrecision", ... , "where"]
|
118
|
+
```
|
119
|
+
or by consulting the [docs](https://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/02ss0000002r000000/). One default is set: ```outFields: '*'``` - which requests data for all fields.
|
120
|
+
|
121
|
+
|
122
|
+
The ```:where``` key is used with any valid SQL to query the layer fields. The default is '1=1' which returns all records (up to the ```layer.max_record_count``` value, usually 1,000). An error is raised if the server gives a 400 error of this form:
|
123
|
+
```json
|
124
|
+
{
|
125
|
+
"error": {
|
126
|
+
"code": 400,
|
127
|
+
"message": "Unable to complete operation.",
|
128
|
+
"details": [
|
129
|
+
"Unable to perform query operation.",
|
130
|
+
"Invalid query"
|
131
|
+
]
|
132
|
+
}
|
133
|
+
}
|
134
|
+
```
|
135
|
+
|
136
|
+
|
137
|
+
## Specification & Tests
|
138
|
+
|
139
|
+
Full specification documentation is available by running the test suite thus:
|
140
|
+
|
141
|
+
$ bundle exec rake spec
|
12
142
|
|
13
143
|
|
14
144
|
## Contributing
|
15
145
|
|
16
|
-
Bug reports and pull requests are welcome on GitHub at https://
|
146
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/matzfan/arcrest
|
17
147
|
|
18
148
|
|
19
149
|
## License
|
data/Rakefile
CHANGED
data/arcrest.gemspec
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'arcrest/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = 'arcrest'
|
8
9
|
spec.version = ArcREST::VERSION
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['
|
10
|
+
spec.authors = ['matzfan']
|
11
|
+
spec.email = ['matzfan@yandex.com']
|
11
12
|
|
12
13
|
spec.summary = 'Wrapper for ArcGIS REST API'
|
13
14
|
spec.description = 'Wrapper for ArcGIS REST API'
|
14
|
-
spec.homepage = 'https://
|
15
|
-
spec.
|
15
|
+
spec.homepage = 'https://gitlab.com/matzfan/arcrest'
|
16
|
+
spec.required_ruby_version = '>= 2.4'
|
17
|
+
spec.license = 'MIT'
|
16
18
|
|
17
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
20
|
f.match(%r{^(test|spec|features)/})
|
@@ -21,7 +23,13 @@ Gem::Specification.new do |spec|
|
|
21
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
24
|
spec.require_paths = ['lib']
|
23
25
|
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency 'rspec', '~>
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
27
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
28
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
29
|
+
spec.add_development_dependency 'libnotify', '~> 0.9' # guard notifications
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.3'
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'curb', '~> 0.9.11'
|
27
35
|
end
|
data/bin/console
CHANGED
@@ -1,14 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# !/usr/bin/env ruby
|
2
4
|
|
3
5
|
require 'bundler/setup'
|
4
6
|
require 'arcrest'
|
5
7
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
8
|
require 'irb'
|
14
9
|
IRB.start
|
data/bin/setup
CHANGED
data/lib/arcrest.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arcrest/attributable' # module
|
1
4
|
require 'arcrest/version'
|
5
|
+
require 'arcrest/server'
|
6
|
+
require 'arcrest/catalog'
|
7
|
+
require 'arcrest/service'
|
8
|
+
require 'arcrest/layer'
|
2
9
|
|
3
10
|
# namespace
|
4
|
-
module
|
5
|
-
# Your code goes here...
|
6
|
-
end
|
11
|
+
module ArcRest; end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# adds ability to dynamically set instance vars & accessors
|
4
|
+
module Attributable
|
5
|
+
def create_method(name, &block)
|
6
|
+
self.class.send(:define_method, name.to_sym, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_setter(method)
|
10
|
+
create_method("#{method}=".to_sym) { |v| instance_variable_set("@#{method}", v) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_getter(method)
|
14
|
+
create_method(method.to_sym) { instance_variable_get("@#{method}") }
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_attr(method, value)
|
18
|
+
create_setter(method)
|
19
|
+
send "#{method}=".to_sym, value
|
20
|
+
create_getter(method)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ArcREST
|
4
|
+
# a catalog of services
|
5
|
+
class Catalog < Server
|
6
|
+
attr_reader :folders, :services
|
7
|
+
|
8
|
+
def initialize(url, headers = {})
|
9
|
+
super
|
10
|
+
@folders = folders_
|
11
|
+
@services = services_
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def folders_
|
17
|
+
@json['folders']
|
18
|
+
end
|
19
|
+
|
20
|
+
def services_
|
21
|
+
@json['services']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'curb'
|
4
|
+
|
5
|
+
# methods to curl a url
|
6
|
+
module Curlable
|
7
|
+
RETRIES = 5
|
8
|
+
|
9
|
+
class BadHttpResponse < StandardError; end
|
10
|
+
|
11
|
+
def curl_get(url, opts = {})
|
12
|
+
c = Curl::Easy.new(url) { |curl| configure(curl, opts[:headers] || {}) }
|
13
|
+
try(c, opts[:retries] || RETRIES)
|
14
|
+
c.perform
|
15
|
+
code = c.response_code
|
16
|
+
raise BadHttpResponse, "#{code} at #{url}" unless [2, 3].include? code / 100
|
17
|
+
|
18
|
+
c.body_str
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def try(curl, tries)
|
24
|
+
curl.perform
|
25
|
+
curl.on_failure { |c, _e| try(c, tries -= 1) if tries > 1 } # recurse
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure(curl, headers)
|
29
|
+
curl.follow_location = true
|
30
|
+
headers.each { |k, v| curl.headers[k.capitalize] = v }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ArcREST
|
4
|
+
class InvalidOption < StandardError; end
|
5
|
+
class BadQuery < StandardError; end
|
6
|
+
# a layer
|
7
|
+
class Layer < Server
|
8
|
+
include Attributable
|
9
|
+
|
10
|
+
DATE = 'esriFieldTypeDate'
|
11
|
+
ATTRIBUTES = %w[id name type drawing_info fields max_record_count].freeze
|
12
|
+
DEFAULT_PARAMS = { where: '1=1', outFields: '*' }.freeze
|
13
|
+
PARAMS = %w[distance geometry geometryType inSR objectIds
|
14
|
+
outFields outSR relationParam returnDistinceValues
|
15
|
+
returnIdsOnly spatialRel time where].freeze
|
16
|
+
PARAMS_SP1 = %w[returnCountOnly].freeze
|
17
|
+
PARAMS_10_1 = %w[dbVersion geometryPrecision groupByFieldsForStatistics
|
18
|
+
maxAllowableOffset multiPatchOption orderByFields
|
19
|
+
outStatistics returnGeometry returnM returnZ].freeze
|
20
|
+
PARAMS_10_3 = %w[returnExtentOnly resultOffset resultRecordCount].freeze
|
21
|
+
|
22
|
+
attr_reader :valid_params # other accessors set in constructor
|
23
|
+
|
24
|
+
def initialize(url, headers = {})
|
25
|
+
super
|
26
|
+
generate_attributes # dynamically create & assign values to attributes :)
|
27
|
+
@fields = fields
|
28
|
+
end
|
29
|
+
|
30
|
+
def count
|
31
|
+
@version > 10 ? count_only_true : object_ids.count # v10.1 onwards
|
32
|
+
end
|
33
|
+
|
34
|
+
def object_ids
|
35
|
+
query(outFields: nil, returnIdsOnly: true)['objectIds'] # care - must specify outFields to overide default '*'
|
36
|
+
end
|
37
|
+
|
38
|
+
def query(options = {})
|
39
|
+
validate(options.keys.map(&:to_s).sort)
|
40
|
+
valid_resp(DEFAULT_PARAMS.merge(options))
|
41
|
+
end
|
42
|
+
|
43
|
+
def features(options = {})
|
44
|
+
query(options)['features']
|
45
|
+
end
|
46
|
+
|
47
|
+
def valid_opts
|
48
|
+
return PARAMS if @version < 10 || @version.to_s == '10.0'
|
49
|
+
return (PARAMS + PARAMS_SP1).sort if @version < 10.1
|
50
|
+
return (PARAMS + PARAMS_SP1 + PARAMS_10_1).sort if @version < 10.2
|
51
|
+
|
52
|
+
(PARAMS + PARAMS_SP1 + PARAMS_10_1 + PARAMS_10_3).sort
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def generate_attributes
|
58
|
+
ATTRIBUTES.each { |name| set_attr(name, json_value(name)) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def json_value(name)
|
62
|
+
@json[camelify(name)]
|
63
|
+
end
|
64
|
+
|
65
|
+
def camelify(name)
|
66
|
+
words = name.split('_')
|
67
|
+
words[1..-1].map(&:capitalize).unshift(words.first).join
|
68
|
+
end
|
69
|
+
|
70
|
+
def valid_resp(opts)
|
71
|
+
raise BadQuery, m(opts) if (resp = parse_json(query_url, opts)).keys.include? 'error'
|
72
|
+
|
73
|
+
resp
|
74
|
+
end
|
75
|
+
|
76
|
+
def m(options)
|
77
|
+
"The following query parameters resulted in a 400 response:\n#{options}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate(keys)
|
81
|
+
keys.all? { |k| raise InvalidOption, msg(k) unless valid_opts.include? k }
|
82
|
+
end
|
83
|
+
|
84
|
+
def msg(key)
|
85
|
+
"'#{key}' is an invalid option, valid query options are:\n#{PARAMS}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def count_only_true
|
89
|
+
query(returnCountOnly: true)['count']
|
90
|
+
end
|
91
|
+
|
92
|
+
def query_url
|
93
|
+
"#{@server_url}/query"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require_relative 'curlable'
|
8
|
+
|
9
|
+
module ArcREST
|
10
|
+
# superclass
|
11
|
+
class Server
|
12
|
+
include Curlable # for #curl_get
|
13
|
+
|
14
|
+
ENDPOINT_REGEX = %r{/arcgis/rest/services/?}i.freeze
|
15
|
+
BAD_ENDPOINT = 'Invalid ArcGIS endpoint'
|
16
|
+
|
17
|
+
attr_reader :url, :json, :version
|
18
|
+
|
19
|
+
def initialize(url, headers = {})
|
20
|
+
@url = url
|
21
|
+
@headers = headers
|
22
|
+
validate_endpoint_url
|
23
|
+
@server_url = server_url
|
24
|
+
@json = json_
|
25
|
+
@version = version_
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def server_url
|
31
|
+
@url[-1] == '/' ? @url[0..-2] : @url
|
32
|
+
end
|
33
|
+
|
34
|
+
def json_
|
35
|
+
parse_json
|
36
|
+
end
|
37
|
+
|
38
|
+
def version_
|
39
|
+
parse_json['currentVersion'] # subclasses use server uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_json(url = @server_url, options = {})
|
43
|
+
JSON.parse get(url, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_endpoint_url
|
47
|
+
raise ArgumentError, BAD_ENDPOINT unless @url =~ ENDPOINT_REGEX
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_json_param_to(hash)
|
51
|
+
{ f: 'json' }.merge(hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(url, options = {})
|
55
|
+
curl_get(query_string(url, options), @headers)
|
56
|
+
end
|
57
|
+
|
58
|
+
def query_string(url, options)
|
59
|
+
"#{url}?#{URI.encode_www_form(add_json_param_to(options))}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ArcREST
|
4
|
+
# a FeatureService or a MapService
|
5
|
+
class Service < Server
|
6
|
+
attr_reader :max_record_count, :capabilities, :layers
|
7
|
+
|
8
|
+
def initialize(url, headers = {})
|
9
|
+
super
|
10
|
+
@max_record_count = max_record_count_
|
11
|
+
@capabilities = capabilities_
|
12
|
+
@layers = layers_
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def max_record_count_
|
18
|
+
@json['maxRecordCount']
|
19
|
+
end
|
20
|
+
|
21
|
+
def capabilities_
|
22
|
+
@json['capabilities'] ? @json['capabilities'].split(',') : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def layers_
|
26
|
+
@json['layers']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/arcrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arcrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- matzfan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,53 +16,125 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: libnotify
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rake
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
73
|
- - "~>"
|
32
74
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
75
|
+
version: '13.0'
|
34
76
|
type: :development
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
80
|
- - "~>"
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
82
|
+
version: '13.0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: rspec
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - "~>"
|
46
88
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
89
|
+
version: '3.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
48
104
|
type: :development
|
49
105
|
prerelease: false
|
50
106
|
version_requirements: !ruby/object:Gem::Requirement
|
51
107
|
requirements:
|
52
108
|
- - "~>"
|
53
109
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: curb
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.11
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.11
|
55
125
|
description: Wrapper for ArcGIS REST API
|
56
126
|
email:
|
57
|
-
-
|
127
|
+
- matzfan@yandex.com
|
58
128
|
executables: []
|
59
129
|
extensions: []
|
60
130
|
extra_rdoc_files: []
|
61
131
|
files:
|
62
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
63
134
|
- ".rspec"
|
64
|
-
- ".
|
135
|
+
- ".rubocop.yml"
|
65
136
|
- Gemfile
|
137
|
+
- Guardfile
|
66
138
|
- LICENSE.txt
|
67
139
|
- README.md
|
68
140
|
- Rakefile
|
@@ -70,8 +142,14 @@ files:
|
|
70
142
|
- bin/console
|
71
143
|
- bin/setup
|
72
144
|
- lib/arcrest.rb
|
145
|
+
- lib/arcrest/attributable.rb
|
146
|
+
- lib/arcrest/catalog.rb
|
147
|
+
- lib/arcrest/curlable.rb
|
148
|
+
- lib/arcrest/layer.rb
|
149
|
+
- lib/arcrest/server.rb
|
150
|
+
- lib/arcrest/service.rb
|
73
151
|
- lib/arcrest/version.rb
|
74
|
-
homepage: https://
|
152
|
+
homepage: https://gitlab.com/matzfan/arcrest
|
75
153
|
licenses:
|
76
154
|
- MIT
|
77
155
|
metadata: {}
|
@@ -83,15 +161,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
161
|
requirements:
|
84
162
|
- - ">="
|
85
163
|
- !ruby/object:Gem::Version
|
86
|
-
version: '
|
164
|
+
version: '2.4'
|
87
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
166
|
requirements:
|
89
|
-
- - "
|
167
|
+
- - ">="
|
90
168
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
169
|
+
version: '0'
|
92
170
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.6.2
|
171
|
+
rubygems_version: 3.1.4
|
95
172
|
signing_key:
|
96
173
|
specification_version: 4
|
97
174
|
summary: Wrapper for ArcGIS REST API
|