fc2json 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/Gemfile.lock +9 -9
- data/README.md +9 -1
- data/VERSION +1 -1
- data/fc2json.gemspec +4 -3
- data/lib/fc2json.rb +20 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbcd8561a70124820294be6d08cab42839eecc32
|
4
|
+
data.tar.gz: 9d66b0099a955274d165b92b498630e968ca466b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e014021f2a827525ce99f0703185fbe93bad34c3886b5568e1640b813f3ea193385d2b922b80541ef1930f43a5d4671a7638a7a83c526d42477bd4b59cd35a96
|
7
|
+
data.tar.gz: 6d520e944a50863e0ed476856646417688691b9f9948c46c0747f9fe48008ad4eca1d638f5c1afcd47ac462ae0f962135687264719e1dbb191c208127d25e59c
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -5,7 +5,7 @@ GEM
|
|
5
5
|
builder (3.2.2)
|
6
6
|
crack (0.4.1)
|
7
7
|
safe_yaml (~> 0.9.0)
|
8
|
-
diff-lcs (1.
|
8
|
+
diff-lcs (1.2.5)
|
9
9
|
faraday (0.8.8)
|
10
10
|
multipart-post (~> 1.2.0)
|
11
11
|
git (1.2.6)
|
@@ -46,14 +46,14 @@ GEM
|
|
46
46
|
rake (10.1.1)
|
47
47
|
rdoc (4.1.0)
|
48
48
|
json (~> 1.4)
|
49
|
-
rspec (2.
|
50
|
-
rspec-core (~> 2.
|
51
|
-
rspec-expectations (~> 2.
|
52
|
-
rspec-mocks (~> 2.
|
53
|
-
rspec-core (2.
|
54
|
-
rspec-expectations (2.
|
55
|
-
diff-lcs (
|
56
|
-
rspec-mocks (2.
|
49
|
+
rspec (2.14.1)
|
50
|
+
rspec-core (~> 2.14.0)
|
51
|
+
rspec-expectations (~> 2.14.0)
|
52
|
+
rspec-mocks (~> 2.14.0)
|
53
|
+
rspec-core (2.14.7)
|
54
|
+
rspec-expectations (2.14.4)
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
+
rspec-mocks (2.14.4)
|
57
57
|
safe_yaml (0.9.7)
|
58
58
|
vcr (2.8.0)
|
59
59
|
webmock (1.15.2)
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/rpepato/fc2json.png?branch=master)](https://travis-ci.org/rpepato/fc2json) [![Code Climate](https://codeclimate.com/github/rpepato/fc2json.png)](https://codeclimate.com/github/rpepato/fc2json)
|
1
2
|
fc2json
|
2
3
|
==================
|
3
4
|
|
@@ -22,7 +23,7 @@ end
|
|
22
23
|
|
23
24
|
####Initialization parameters
|
24
25
|
|
25
|
-
The constructor of a FC2Json object is
|
26
|
+
The constructor of a FC2Json object is declared as follows:
|
26
27
|
|
27
28
|
```ruby
|
28
29
|
def initialize (service_url, object_identifier_field_name = nil, records_per_request = nil, where_clause = nil)
|
@@ -36,6 +37,13 @@ The construction parameters are:
|
|
36
37
|
* __records_per_request:__ Optional. The number of records returned on each request to the service. Be aware that if you specify a number greater than the max number of records configured on the service, an ArgumentError will be raised. If not provided, defaults to 2000.
|
37
38
|
* __where_clause:__ Optional. The where condition (SQL query) to filter the records on the feature service. If not provided, defaults to "1 = 1"
|
38
39
|
|
40
|
+
####Binary usage
|
41
|
+
If you prefer you can use the binary provided by the gem and redirect the output to a file:
|
42
|
+
|
43
|
+
```shell
|
44
|
+
fc2json "http://services2.arcgis.com/hMIIIBIOpi8Cdgjw/arcgis/rest/services/ubs/FeatureServer/0" "FID" 6 "FID >= 1 and FID <=6" > output.json
|
45
|
+
```
|
46
|
+
|
39
47
|
###Contributing to fc2json
|
40
48
|
|
41
49
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/fc2json.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: fc2json 0.
|
5
|
+
# stub: fc2json 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "fc2json"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Roberto Pepato"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2014-01-10"
|
15
15
|
s.description = "fc2json queries, downloads and formats all data from a remote Esri feature service, exposing it as json representation"
|
16
16
|
s.email = "rpepato@gmail.com"
|
17
17
|
s.executables = ["fc2json"]
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.files = [
|
23
23
|
".document",
|
24
24
|
".rspec",
|
25
|
+
".travis.yml",
|
25
26
|
"Gemfile",
|
26
27
|
"Gemfile.lock",
|
27
28
|
"LICENSE.txt",
|
data/lib/fc2json.rb
CHANGED
@@ -18,21 +18,18 @@ class FC2Json
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get
|
21
|
-
ids =
|
21
|
+
ids = object_identifiers
|
22
22
|
json = {}
|
23
23
|
request_index = 0
|
24
24
|
continue = true
|
25
25
|
|
26
26
|
while continue do
|
27
|
-
if ids[request_index * @records_per_request + (@records_per_request - 1)].nil?
|
28
|
-
continue = false
|
29
|
-
where = "#{@object_identifier_field_name} >= #{ids[request_index * @records_per_request]} AND #{@object_identifier_field_name} <= #{ids.last}"
|
30
|
-
else
|
31
|
-
where = "#{@object_identifier_field_name} >= #{ids[request_index * @records_per_request]} AND #{@object_identifier_field_name} <= #{ids[request_index * @records_per_request + (@records_per_request - 1)]}"
|
32
|
-
end
|
33
|
-
request_url = "#{@service_url}/query?where=#{CGI.escape(where)}&f=pjson&outFields=*"
|
34
27
|
|
35
|
-
|
28
|
+
continue = false if ids[request_index * @records_per_request + (@records_per_request - 1)].nil?
|
29
|
+
|
30
|
+
where = where_clause_for(ids, request_index)
|
31
|
+
|
32
|
+
request_result = request_features(where)
|
36
33
|
if request_result["exceededTransferLimit"]
|
37
34
|
raise ArgumentError, "The batch size of #{@records_per_request} exceeds the capability provided by the service used on this query. Review the service's batch size limit and adjust your query parameters."
|
38
35
|
end
|
@@ -52,13 +49,25 @@ class FC2Json
|
|
52
49
|
if json["error"]
|
53
50
|
return {} if json["error"]["details"] == ["'where' parameter is invalid"]
|
54
51
|
end
|
55
|
-
|
56
52
|
json
|
53
|
+
|
57
54
|
end
|
58
55
|
|
59
56
|
private
|
60
57
|
|
61
|
-
def
|
58
|
+
def request_features(where_clause)
|
59
|
+
JSON.parse(Nokogiri::HTML(open("#{@service_url}/query?where=#{CGI.escape(where_clause)}&f=pjson&outFields=*")))
|
60
|
+
end
|
61
|
+
|
62
|
+
def where_clause_for(dataset, index)
|
63
|
+
if dataset[index * @records_per_request + (@records_per_request - 1)].nil?
|
64
|
+
"#{@object_identifier_field_name} >= #{dataset[index * @records_per_request]} AND #{@object_identifier_field_name} <= #{dataset.last}"
|
65
|
+
else
|
66
|
+
"#{@object_identifier_field_name} >= #{dataset[index * @records_per_request]} AND #{@object_identifier_field_name} <= #{dataset[index * @records_per_request + (@records_per_request - 1)]}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def object_identifiers
|
62
71
|
request_url = "#{self.service_url}/query?where=#{CGI.escape(self.where_clause)}&f=pjson&returnIdsOnly=true"
|
63
72
|
(JSON.parse Nokogiri::HTML(open(request_url)))["objectIds"]
|
64
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fc2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Pepato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -96,6 +96,7 @@ extra_rdoc_files:
|
|
96
96
|
files:
|
97
97
|
- ".document"
|
98
98
|
- ".rspec"
|
99
|
+
- ".travis.yml"
|
99
100
|
- Gemfile
|
100
101
|
- Gemfile.lock
|
101
102
|
- LICENSE.txt
|