class ArcREST::Layer
a layer
Constants
- ATTRIBUTES
- DATE
- DEFAULT_PARAMS
- PARAMS
- PARAMS_10_1
- PARAMS_10_3
- PARAMS_SP1
Attributes
valid_params[R]
Public Class Methods
new(url, headers = {})
click to toggle source
Calls superclass method
# File lib/arcrest/layer.rb, line 26 def initialize(url, headers = {}) super generate_attributes # dynamically create & assign values to attributes :) @fields = fields end
Public Instance Methods
count()
click to toggle source
# File lib/arcrest/layer.rb, line 32 def count @version > 10 ? count_only_true : object_ids.count # v10.1 onwards end
features(options = {})
click to toggle source
# File lib/arcrest/layer.rb, line 45 def features(options = {}) query(options)['features'] end
object_ids()
click to toggle source
# File lib/arcrest/layer.rb, line 36 def object_ids query(outFields: nil, returnIdsOnly: true)['objectIds'] # care - must specify outFields to overide default '*' end
query(options = {})
click to toggle source
# File lib/arcrest/layer.rb, line 40 def query(options = {}) validate(options.keys.map(&:to_s).sort) valid_resp(DEFAULT_PARAMS.merge(options)) end
valid_opts()
click to toggle source
# File lib/arcrest/layer.rb, line 49 def valid_opts return PARAMS if @version < 10 || @version.to_s == '10.0' return (PARAMS + PARAMS_SP1).sort if @version < 10.1 return (PARAMS + PARAMS_SP1 + PARAMS_10_1).sort if @version < 10.2 (PARAMS + PARAMS_SP1 + PARAMS_10_1 + PARAMS_10_3).sort end
Private Instance Methods
camelify(name)
click to toggle source
# File lib/arcrest/layer.rb, line 67 def camelify(name) words = name.split('_') words[1..-1].map(&:capitalize).unshift(words.first).join end
count_only_true()
click to toggle source
# File lib/arcrest/layer.rb, line 90 def count_only_true query(returnCountOnly: true)['count'] end
generate_attributes()
click to toggle source
# File lib/arcrest/layer.rb, line 59 def generate_attributes ATTRIBUTES.each { |name| set_attr(name, json_value(name)) } end
json_value(name)
click to toggle source
# File lib/arcrest/layer.rb, line 63 def json_value(name) @json[camelify(name)] end
m(options)
click to toggle source
# File lib/arcrest/layer.rb, line 78 def m(options) "The following query parameters resulted in a 400 response:\n#{options}" end
msg(key)
click to toggle source
# File lib/arcrest/layer.rb, line 86 def msg(key) "'#{key}' is an invalid option, valid query options are:\n#{PARAMS}" end
query_url()
click to toggle source
# File lib/arcrest/layer.rb, line 94 def query_url "#{@server_url}/query" end
valid_resp(opts)
click to toggle source
# File lib/arcrest/layer.rb, line 72 def valid_resp(opts) raise BadQuery, m(opts) if (resp = parse_json(query_url, opts)).keys.include? 'error' resp end
validate(keys)
click to toggle source
# File lib/arcrest/layer.rb, line 82 def validate(keys) keys.all? { |k| raise InvalidOption, msg(k) unless valid_opts.include? k } end