fc2json 0.2.1 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65ac2311eb61e08baf184b4d6fe92ac1de54c9ef
4
- data.tar.gz: 46a9dea59ca075267d8ef104a12083bdf0ad7cb4
3
+ metadata.gz: dbcd8561a70124820294be6d08cab42839eecc32
4
+ data.tar.gz: 9d66b0099a955274d165b92b498630e968ca466b
5
5
  SHA512:
6
- metadata.gz: d23c7270c47a4f8d0ddf6cd5e69f5dbdb698a9850e6d94c58cd505c961578a054efd5715b57935691d7e353530ffbf1ebbe3f31735ae4d294770f4ebf186aadd
7
- data.tar.gz: 5a0ccd42b1eba1d1732a7af1a0c6c1c48d6db54e181b10f8e58bf8ffccca4ab63c13bd59286775fe179bad2936acbc0673d67333a5ea62307022c581d9928404
6
+ metadata.gz: e014021f2a827525ce99f0703185fbe93bad34c3886b5568e1640b813f3ea193385d2b922b80541ef1930f43a5d4671a7638a7a83c526d42477bd4b59cd35a96
7
+ data.tar.gz: 6d520e944a50863e0ed476856646417688691b9f9948c46c0747f9fe48008ad4eca1d638f5c1afcd47ac462ae0f962135687264719e1dbb191c208127d25e59c
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update bundler
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
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.1.3)
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.8.0)
50
- rspec-core (~> 2.8.0)
51
- rspec-expectations (~> 2.8.0)
52
- rspec-mocks (~> 2.8.0)
53
- rspec-core (2.8.0)
54
- rspec-expectations (2.8.0)
55
- diff-lcs (~> 1.1.2)
56
- rspec-mocks (2.8.0)
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 declares as follows:
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.2.1
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.2.1 ruby lib
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.2.1"
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 = "2013-12-31"
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 = get_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
- request_result = JSON.parse(Nokogiri::HTML(open(request_url)))
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 get_ids
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.2.1
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: 2013-12-31 00:00:00.000000000 Z
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