arcrest 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/lib/arcrest/layer.rb +8 -8
- data/lib/arcrest/server.rb +11 -5
- data/lib/arcrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118b49ef19eede12dba1c5a14b4f44c312765fac
|
4
|
+
data.tar.gz: a8ff9d6eb9e1ac44416b4d8841945beb67a62237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29051ead9be6f5a6b978d9fa25159a670440820617e900bca47a216df32af9334259d0df5d8cecda96e22d732f44b4c7c6fe2d4a6b37fac8e0fd9ac2acd0aabb
|
7
|
+
data.tar.gz: e4e10b26003115d561d2f4ed2959118763693c991b1e294da93e46180bde880056a47798bce6ed8225c9d0f845978c57f421ac6cd5c913a97389dc60aa1d5d2d
|
data/README.md
CHANGED
@@ -65,8 +65,21 @@ puts layer.fields
|
|
65
65
|
#=> ...
|
66
66
|
```
|
67
67
|
|
68
|
-
|
68
|
+
Catalog, Service and Layer have a ```json``` method which returns information from the relevant server as a Hash (derived from JSON). In addition to the example methods above this can be parsed in the usual way - e.g:
|
69
|
+
```ruby
|
70
|
+
puts layer.json.keys.inspect
|
71
|
+
#=> ["currentVersion", "id", "name", "type", "description", "copyrightText"...
|
72
|
+
```
|
73
|
+
|
74
|
+
Once you have a Layer object, you can perform queries on it. The [documention](http://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/) shows the possibilities. Here is a very simple example:
|
75
|
+
|
76
|
+
The ```query``` method returns the whole server response as a Hash:
|
77
|
+
```ruby
|
78
|
+
puts layer.query(where: '1=0').inspect
|
79
|
+
#=> {"objectIdFieldName"=>"objectid", "globalIdFieldName"=>"", "features"=>[]}
|
80
|
+
```
|
69
81
|
|
82
|
+
If you just want the features, use the ```features``` method:
|
70
83
|
```ruby
|
71
84
|
features = layer.features(where: "agency='BLM'", returnGeometry: false)
|
72
85
|
puts features.count
|
@@ -75,7 +88,7 @@ puts features.first
|
|
75
88
|
#=> {"objectid"=>690, "agency"=>"BLM", "comments"=>" ", "active"=>"Y"...
|
76
89
|
```
|
77
90
|
|
78
|
-
```features```
|
91
|
+
```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:
|
79
92
|
```ruby
|
80
93
|
puts layer.valid_opts.inspect
|
81
94
|
#=> ["dbVersion", "distance", "geometry", "geometryPrecision"...
|
@@ -83,7 +96,7 @@ puts layer.valid_opts.inspect
|
|
83
96
|
or by consulting the [docs](http://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/). One default is set: ```outFields: '*'``` - which requests data for all fields.
|
84
97
|
|
85
98
|
|
86
|
-
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 ```@max_record_count``` value, usually 1,000). An
|
99
|
+
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 ```@max_record_count``` value, usually 1,000). An error is raised if the server gives a 400 error of this form:
|
87
100
|
```json
|
88
101
|
{
|
89
102
|
"error": {
|
data/lib/arcrest/layer.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module ArcREST
|
2
2
|
class InvalidOption < StandardError; end
|
3
|
-
class
|
3
|
+
class BadQuery < StandardError; end
|
4
4
|
# a layer
|
5
5
|
class Layer < Server
|
6
6
|
include Attributable
|
7
7
|
|
8
|
-
|
8
|
+
E = 'error'.freeze
|
9
9
|
ATTRIBUTES = %w(id name type drawing_info fields max_record_count).freeze
|
10
10
|
DEFAULT_PARAMS = { where: '1=1', outFields: '*' }.freeze
|
11
11
|
PARAMS = %w(distance geometry geometryType inSR objectIds
|
@@ -32,6 +32,11 @@ module ArcREST
|
|
32
32
|
query(outFields: nil, returnIdsOnly: true)['objectIds']
|
33
33
|
end
|
34
34
|
|
35
|
+
def query(options = {})
|
36
|
+
validate(options.keys.map(&:to_s).sort)
|
37
|
+
valid_resp(build_uri, DEFAULT_PARAMS.merge(options))
|
38
|
+
end
|
39
|
+
|
35
40
|
def features(options = {})
|
36
41
|
query(options)['features']
|
37
42
|
end
|
@@ -58,13 +63,8 @@ module ArcREST
|
|
58
63
|
words[1..-1].map(&:capitalize).unshift(words.first).join
|
59
64
|
end
|
60
65
|
|
61
|
-
def query(options)
|
62
|
-
validate(options.keys.map(&:to_s).sort)
|
63
|
-
valid_resp(build_uri, DEFAULT_PARAMS.merge(options))
|
64
|
-
end
|
65
|
-
|
66
66
|
def valid_resp(uri, opts)
|
67
|
-
raise
|
67
|
+
raise BadQuery, m(opts) if (resp = parse_json(uri, opts)).keys.include? E
|
68
68
|
resp
|
69
69
|
end
|
70
70
|
|
data/lib/arcrest/server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'open-uri'
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
module ArcREST
|
@@ -13,20 +14,25 @@ module ArcREST
|
|
13
14
|
@url = url
|
14
15
|
@uri = uri
|
15
16
|
@server_uri = server_uri
|
16
|
-
@json = json
|
17
|
+
@json = json
|
17
18
|
@version = version
|
18
19
|
end
|
19
20
|
|
20
|
-
def json
|
21
|
-
|
21
|
+
def json
|
22
|
+
parse_json @uri
|
22
23
|
end
|
23
24
|
|
24
25
|
def version
|
25
|
-
|
26
|
+
parse_json(server_uri)['currentVersion'] # subclasses use server uri
|
26
27
|
end
|
27
28
|
|
28
29
|
protected
|
29
30
|
|
31
|
+
def parse_json(uri, options = {})
|
32
|
+
JSON.parse get(uri, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
30
36
|
def uri
|
31
37
|
raise ArgumentError, BAD_ENDPOINT if (URI(@url).path =~ REGEX) != 0
|
32
38
|
URI @url
|
@@ -42,7 +48,7 @@ module ArcREST
|
|
42
48
|
|
43
49
|
def get(uri, options = {})
|
44
50
|
uri.query = URI.encode_www_form(add_json_param_to(options))
|
45
|
-
|
51
|
+
open(uri).read # net/http doesn't follow redirects..
|
46
52
|
end
|
47
53
|
end
|
48
54
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Steedman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|