Class: FC2Json

Inherits:
Object
  • Object
show all
Defined in:
lib/fc2json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_url, object_identifier_field_name = nil, records_per_request = nil, where_clause = nil) ⇒ FC2Json

Returns a new instance of FC2Json.



13
14
15
16
17
18
# File 'lib/fc2json.rb', line 13

def initialize (service_url, object_identifier_field_name = nil, records_per_request = nil, where_clause = nil)
	@service_url = service_url
	@object_identifier_field_name = object_identifier_field_name || "FID"
	@records_per_request = (records_per_request || 2000).to_i
	@where_clause = where_clause || "1 = 1"
end

Instance Attribute Details

#object_identifier_field_nameObject

Returns the value of attribute object_identifier_field_name.



11
12
13
# File 'lib/fc2json.rb', line 11

def object_identifier_field_name
  @object_identifier_field_name
end

#records_per_requestObject

Returns the value of attribute records_per_request.



11
12
13
# File 'lib/fc2json.rb', line 11

def records_per_request
  @records_per_request
end

#service_urlObject

Returns the value of attribute service_url.



11
12
13
# File 'lib/fc2json.rb', line 11

def service_url
  @service_url
end

#where_clauseObject

Returns the value of attribute where_clause.



11
12
13
# File 'lib/fc2json.rb', line 11

def where_clause
  @where_clause
end

Instance Method Details

#getObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fc2json.rb', line 20

def get
	ids = object_identifiers
	json = {}
	request_index = 0
	continue = true

	while continue do

		continue = false if ids[request_index * @records_per_request + (@records_per_request - 1)].nil?

		where = where_clause_for(ids, request_index)

		request_result = request_features(where)
		if request_result["exceededTransferLimit"]
			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."
		end

		if json.empty?
			json = request_result
		else
			json["features"].concat request_result["features"]
		end

		request_index += 1

		continue = false if continue && json["features"].count == ids.count
	end

	# Esri treats where clauses that returns no data as invalid. We return an empty hash instead.
	if json["error"]
		return {} if json["error"]["details"] == ["'where' parameter is invalid"]
	end
	json

end