arcrest 0.0.1 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 948887626e3cbf6c38a60ab4d3f3f96f38815a64
4
- data.tar.gz: ee36b210de6e5354e2afae62ec6b3ba3bdbb44d4
2
+ SHA256:
3
+ metadata.gz: '0926148a508e0d0c5786d3016065bb1588667f1a31f73baedf9d7c414a883dfb'
4
+ data.tar.gz: 7dfff2271f6423932dba2d6e478188ec1b8d095b694c6bfaf4813c119da78d17
5
5
  SHA512:
6
- metadata.gz: a3bfa45f4ea1fa30629e216122fe40783d3519b78e9e592e6e14ea41082b0e88d18bc8e284f101da40a07610ec69154772a99256b9748cf30f62e4905d89edbd
7
- data.tar.gz: 736154f7a57441c74bb37234b500a3126c258ce173adc4aa5e0a7b5af2ca2be38f7c55d7aad7952cace2f82337d7529a638538ff238e02cf630b7f578ccf9509
6
+ metadata.gz: b831ce217e8070a627ccd061469dad381bce10e2358e3e929bcbf856f0d5012e05d03f85cb2bb95371df469fc818edc0a8a6c8481b88652d1eeea8d9fac50a66
7
+ data.tar.gz: fac1baab6010b743b3a3e520a6eea847da6f0809c9223c256df8027c10f446f447c3a9c9ee91f61cb7006bb9cf59db2316777d7971f7e6f6136c69229792134a
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /bin/guard
11
+ /bin/_guard-core
@@ -0,0 +1,15 @@
1
+ ---
2
+ before_script:
3
+ - apt-get update -qq
4
+ - gem install bundler
5
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
6
+
7
+ .job_template: &job_definition
8
+ image: ruby:2.7.2
9
+
10
+ test:
11
+ <<: *job_definition
12
+ timeout: 10m
13
+ script:
14
+ - bundle exec rake spec
15
+ - bundle exec rubocop
@@ -0,0 +1,6 @@
1
+ ---
2
+ AllCops:
3
+ NewCops: enable
4
+
5
+ Metrics/BlockLength:
6
+ Enabled: false
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
data/Guardfile CHANGED
@@ -1,13 +1,9 @@
1
- notification :gntp
1
+ # frozen_string_literal: true
2
2
 
3
- guard :rspec, cmd: 'bundle exec rspec' do
4
- watch(%r{^lib/(.+).rb$}) do |m| # watch /lib/ files
5
- "spec/#{m[1]}_spec.rb"
6
- end
7
-
8
- watch(%r{^spec/(.+).rb$}) do |m| # watch /spec/ files
9
- "spec/#{m[1]}.rb"
10
- end
3
+ notification :libnotify, transient: true, append: false, urgency: :critical
11
4
 
5
+ guard :rspec, cmd: 'bundle exec rspec' do
6
+ watch(%r{^lib/(.+).rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch(%r{^spec/(.+).rb$}) { |m| "spec/#{m[1]}.rb" }
12
8
  watch('spec/spec_helper.rb') { 'spec' }
13
9
  end
data/README.md CHANGED
@@ -1,18 +1,15 @@
1
1
  # ArcREST
2
- [![Build status](https://secure.travis-ci.org/MatzFan/ArcREST.svg)](http://travis-ci.org/MatzFan/ArcREST)
3
- [![Gem Version](https://badge.fury.io/rb/arcrest.svg)](http://badge.fury.io/rb/arcrest)
4
2
 
5
- Ruby Gem wrapper around the [ArcGIS REST API](http://services.arcgisonline.com/arcgis/sdk/rest/)
3
+ Ruby Gem wrapper around the [ArcGIS REST API](https://services.arcgisonline.com/arcgis/sdk/rest/)
6
4
 
7
5
  ## Requirements
8
6
 
9
- bundler
7
+ Ruby >= 2.4
10
8
 
11
9
 
12
10
  ## Current Limitations
13
11
 
14
- API FeatureServer query capabilities only at present. Unauthenticated calls only (please raise an issue if you wish this to be supported)
15
-
12
+ API FeatureServer query capabilities only at present.
16
13
 
17
14
  ## Installation
18
15
 
@@ -36,54 +33,93 @@ The API defines a [resource heirarchy](http://services.arcgisonline.com/arcgis/s
36
33
  ```ruby
37
34
  require 'arcrest'
38
35
 
39
- catalog = ArcREST::Catalog.new('http://rmgsc.cr.usgs.gov/arcgis/rest/services')
36
+ catalog = ArcREST::Catalog.new 'https://sampleserver6.arcgisonline.com/arcgis/rest/services'
40
37
  puts catalog.services
41
- #=> {"name"=>"cwqdr_main", "type"=>"MapServer"}
42
- #=> {"name"=>"ecosys_Africa", "type"=>"MapServer"}
43
- #=> {"name"=>"ecosys_SA", "type"=>"MapServer"}
44
- #=> ...
38
+ #=> {"name"=>"911CallsHotspot", "type"=>"GPServer"}
39
+ #=> {"name"=>"911CallsHotspot", "type"=>"MapServer"}
40
+ #=> {"name"=>"Census", "type"=>"MapServer"}
41
+ ...
42
+
43
+ puts catalog.folders
44
+ #=> AGP
45
+ #=> Elevation
46
+ #=> Energy
47
+ ...
48
+ ```
49
+ It is also possible to pass a Referer (or any other) header which will be added to all HTTP requests:
50
+
51
+ ```ruby
52
+ catalog = ArcREST::Catalog.new('https://gojdippmaps.azurewebsites.net/proxy.ashx?https://maps.gov.je/arcgis/rest/services', headers: {referer: 'https://www.gov.je//citizen/Planning/Pages/HistoricEnvironmentDetail.aspx'})
53
+ ```
54
+
55
+ A Service (FeatureServer) is instantiated like this:
45
56
 
46
- service = ArcREST::Service.new('http://rmgsc.cr.usgs.gov/arcgis/rest/services/geomac_fires/FeatureServer')
57
+ ```ruby
58
+ service = ArcREST::Service.new 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/FeatureServer'
47
59
  puts service.layers
48
- #=> {"id"=>1, "name"=>"Large Fire Points"}
49
- #=> {"id"=>2, "name"=>"Fire Perimeters"}
50
- #=> {"id"=>3, "name"=>"MODIS Thermal Satellite"}
51
- #=> {"id"=>4, "name"=>"Inactive Fire Perimeters"}
60
+ #=> {"id"=>0, "name"=>"Emergency Facilities", "parentLayerId"=>-1, "defaultVisibility"=>true, "subLayerIds"=>nil, "minScale"=>150000, "maxScale"=>0, "type"=>"Feature Layer", "geometryType"=>"esriGeometryPoint"}
52
61
 
53
- layer = ArcREST::Layer.new("#{service.url}/2")
62
+ layer = ArcREST::Layer.new "#{service.url}/0"
54
63
  puts layer.name
55
- #=> Fire Perimeters
64
+ #=> Emergency Facilities
65
+
56
66
  puts layer.type
57
67
  #=> Feature Layer
68
+
69
+ puts layer.max_record_count
70
+ #=> 1000 # maximum number of features that can be queried, see below
71
+
58
72
  puts layer.count
59
- #=> 14 # count of the layer's features
73
+ #=> 16 # count of the layer's features
74
+
60
75
  puts layer.object_ids.inspect
61
- #=> [681, 682, 688, 690, 614, 618, 619, 653, 683, 684, 685, 686, 687, 689]
76
+ #=> [29489, 29503, 29490, 29491, 29492, 29493, 29494, 29495, 29496, 29497, 29498, 29499, 29500, 29501, 29502, 29504]
77
+
62
78
  puts layer.fields
63
- #=> {"name"=>"objectid", "type"=>"esriFieldTypeOID", "alias"=>"OBJECTID", "domain"=>nil, "editable"=>false, "nullable"=>false}
64
- #=> {"name"=>"agency", "type"=>"esriFieldTypeString", "alias"=>"agency", "domain"=>nil, "editable"=>true, "nullable"=>true, "length"=>15}
65
- #=> ...
79
+ #=> {"name"=>"objectid", "type"=>"esriFieldTypeOID", "alias"=>"OBJECTID", "domain"=>nil, "editable"=>false, "nullable"=>false, "defaultValue"=>nil, "modelName"=>"System-maintained ObjectID"}
80
+ #=> {"name"=>"facilityid", "type"=>"esriFieldTypeString", "alias"=>"Emergency Facility ID", "domain"=>nil, "editable"=>true, "nullable"=>true, "length"=>20, "defaultValue"=>nil, "modelName"=>"FACILITYID"},
81
+ ...
66
82
  ```
67
83
 
68
- Once you have a Layer object, you can query it's features. The [documention](http://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/) shows the possibilities. Here is a very simple example:
84
+ Catalog, Service and Layer have a ```json``` method which returns information from the relevant server as a Hash. In addition to the example methods above this can be parsed in the usual way - e.g:
85
+ ```ruby
86
+ puts layer.json.keys.inspect
87
+ #=> ["currentVersion", "id", "name", "type", "parentLayer", "defaultVisibility", ...
88
+ ```
89
+
90
+ Once you have a Layer object, you can perform queries on it. The [documention](https://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/02ss0000002r000000/) shows the possibilities. Here is a very simple example:
91
+
92
+ The ```query``` method returns the whole server response as a Hash:
93
+ ```ruby
94
+ puts layer.query(where: '1=0').inspect
95
+ #=> {"objectIdFieldName"=>"objectid", "globalIdFieldName"=>"globalid", "geometryType"=>"esriGeometryPoint", "spatialReference"=>{"wkid"=>4326, "latestWkid"=>4326}, "features"=>[]}
96
+ ```
69
97
 
98
+ If you just want the features, use the ```features``` method:
70
99
  ```ruby
71
- features = layer.features(where: "agency='BLM'", returnGeometry: false)
72
100
  puts features.count
73
- #=> 2
74
- puts features.first
75
- #=> {"objectid"=>690, "agency"=>"BLM", "comments"=>" ", "active"=>"Y"...
101
+ #=> 16
102
+
103
+ puts features[1]
104
+ #=> {"attributes"=>{"objectid"=>29503, "facilityid"=>"K2032", "facname"=>"Redlands Mall", "factype"=>3, ...
105
+
106
+ features = layer.features(where: "factype=3", returnGeometry: false)
107
+ puts features.size
108
+ #=> 7
109
+
110
+ puts features.first['attributes']
111
+ #=> {"objectid"=>29503, "facilityid"=>"K2032", "facname"=>"Redlands Mall", "factype"=>3, "organiz"=>"City of Redlands", ...
76
112
  ```
77
113
 
78
- ```features``` takes an options hash of API call params. Invalid key values raise an error. Valid params for the server can be listed like this:
114
+ ```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
115
  ```ruby
80
116
  puts layer.valid_opts.inspect
81
- #=> ["dbVersion", "distance", "geometry", "geometryPrecision"...
117
+ #=> ["dbVersion", "distance", "geometry", "geometryPrecision", ... , "where"]
82
118
  ```
83
- 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.
119
+ or by consulting the [docs](https://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/02ss0000002r000000/). One default is set: ```outFields: '*'``` - which requests data for all fields.
84
120
 
85
121
 
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 InvalidQuery error is raised if the server gives a 400 error of this form:
122
+ 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 ```layer.max_record_count``` value, usually 1,000). An error is raised if the server gives a 400 error of this form:
87
123
  ```json
88
124
  {
89
125
  "error": {
@@ -100,14 +136,14 @@ The ```:where``` key is used with any valid SQL to query the layer fields. The d
100
136
 
101
137
  ## Specification & Tests
102
138
 
103
- Full specification documentation is available for each build at [Travis](https://travis-ci.org/MatzFan/ArcREST). To run the tests yourself clone this repo and run:
139
+ Full specification documentation is available by running the test suite thus:
104
140
 
105
- $ rake spec
141
+ $ bundle exec rake spec
106
142
 
107
143
 
108
144
  ## Contributing
109
145
 
110
- Bug reports and pull requests are welcome on GitHub at https://github.com/MatzFan/arcrest
146
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/matzfan/arcrest
111
147
 
112
148
 
113
149
  ## License
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,18 +1,20 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'arcrest/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'arcrest'
8
9
  spec.version = ArcREST::VERSION
9
- spec.authors = ['Bruce Steedman']
10
- spec.email = ['bruce.steedman@gmail.com']
10
+ spec.authors = ['matzfan']
11
+ spec.email = ['matzfan@yandex.com']
11
12
 
12
13
  spec.summary = 'Wrapper for ArcGIS REST API'
13
14
  spec.description = 'Wrapper for ArcGIS REST API'
14
- spec.homepage = 'https://github.com/MatzFan/arcrest'
15
- spec.license = 'MIT'
15
+ spec.homepage = 'https://gitlab.com/matzfan/arcrest'
16
+ spec.required_ruby_version = '>= 2.4'
17
+ spec.license = 'MIT'
16
18
 
17
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
@@ -21,10 +23,13 @@ Gem::Specification.new do |spec|
21
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
24
  spec.require_paths = ['lib']
23
25
 
24
- spec.add_development_dependency 'bundler', '~> 1.12'
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'bundler', '~> 2.1'
27
27
  spec.add_development_dependency 'guard', '~> 2.14'
28
28
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
29
- spec.add_development_dependency 'ruby_gntp', '~> 0.3' # guard notifications
29
+ spec.add_development_dependency 'libnotify', '~> 0.9' # guard notifications
30
+ spec.add_development_dependency 'rake', '~> 13.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.10'
32
+ spec.add_development_dependency 'rubocop', '~> 1.3'
33
+
34
+ spec.add_runtime_dependency 'curb', '~> 0.9.11'
30
35
  end
@@ -1,14 +1,9 @@
1
- #!/usr/bin/env ruby
1
+ # frozen_string_literal: true
2
+
3
+ # !/usr/bin/env ruby
2
4
 
3
5
  require 'bundler/setup'
4
6
  require 'arcrest'
5
7
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
8
  require 'irb'
14
9
  IRB.start
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'arcrest/attributable' # module
2
4
  require 'arcrest/version'
3
5
  require 'arcrest/server'
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # adds ability to dynamically set instance vars & accessors
2
4
  module Attributable
3
5
  def create_method(name, &block)
4
6
  self.class.send(:define_method, name.to_sym, &block)
5
7
  end
6
8
 
7
- def create_setter(m)
8
- create_method("#{m}=".to_sym) { |v| instance_variable_set("@#{m}", v) }
9
+ def create_setter(method)
10
+ create_method("#{method}=".to_sym) { |v| instance_variable_set("@#{method}", v) }
9
11
  end
10
12
 
11
- def create_getter(m)
12
- create_method(m.to_sym) { instance_variable_get("@#{m}") }
13
+ def create_getter(method)
14
+ create_method(method.to_sym) { instance_variable_get("@#{method}") }
13
15
  end
14
16
 
15
17
  def set_attr(method, value)
@@ -1,18 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
4
  # a catalog of services
3
5
  class Catalog < Server
4
6
  attr_reader :folders, :services
5
7
 
6
- def initialize(url)
8
+ def initialize(url, headers = {})
7
9
  super
8
- @services = services
10
+ @folders = folders_
11
+ @services = services_
9
12
  end
10
13
 
11
- def folders
14
+ private
15
+
16
+ def folders_
12
17
  @json['folders']
13
18
  end
14
19
 
15
- def services
20
+ def services_
16
21
  @json['services']
17
22
  end
18
23
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'curb'
4
+
5
+ # methods to curl a url
6
+ module Curlable
7
+ RETRIES = 5
8
+
9
+ class BadHttpResponse < StandardError; end
10
+
11
+ def curl_get(url, opts = {})
12
+ c = Curl::Easy.new(url) { |curl| configure(curl, opts[:headers] || {}) }
13
+ try(c, opts[:retries] || RETRIES)
14
+ c.perform
15
+ code = c.response_code
16
+ raise BadHttpResponse, "#{code} at #{url}" unless [2, 3].include? code / 100
17
+
18
+ c.body_str
19
+ end
20
+
21
+ private
22
+
23
+ def try(curl, tries)
24
+ curl.perform
25
+ curl.on_failure { |c, _e| try(c, tries -= 1) if tries > 1 } # recurse
26
+ end
27
+
28
+ def configure(curl, headers)
29
+ curl.follow_location = true
30
+ curl.encoding = 'gzip'
31
+ headers.each { |k, v| curl.headers[k.capitalize] = v }
32
+ end
33
+ end
@@ -1,35 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
4
  class InvalidOption < StandardError; end
3
- class InvalidQuery < StandardError; end
5
+
6
+ class BadQuery < StandardError; end
7
+
4
8
  # a layer
5
9
  class Layer < Server
6
10
  include Attributable
7
11
 
8
- ERR = 'error'.freeze
9
- ATTRIBUTES = %w(id name type drawing_info fields max_record_count).freeze
12
+ DATE = 'esriFieldTypeDate'
13
+ ATTRIBUTES = %w[id name type drawing_info fields max_record_count].freeze
10
14
  DEFAULT_PARAMS = { where: '1=1', outFields: '*' }.freeze
11
- PARAMS = %w(distance geometry geometryType inSR objectIds
15
+ PARAMS = %w[distance geometry geometryType inSR objectIds
12
16
  outFields outSR relationParam returnDistinceValues
13
- returnIdsOnly spatialRel time where).freeze
14
- PARAMS_SP1 = %w(returnCountOnly).freeze
15
- PARAMS_10_1 = %w(dbVersion geometryPrecision groupByFieldsForStatistics
17
+ returnIdsOnly spatialRel time where].freeze
18
+ PARAMS_SP1 = %w[returnCountOnly].freeze
19
+ PARAMS_10_1 = %w[dbVersion geometryPrecision groupByFieldsForStatistics
16
20
  maxAllowableOffset multiPatchOption orderByFields
17
- outStatistics returnGeometry returnM returnZ).freeze
18
- PARAMS_10_3 = %w(returnExtentOnly resultOffset resultRecordCount).freeze
21
+ outStatistics returnGeometry returnM returnZ].freeze
22
+ PARAMS_10_3 = %w[returnExtentOnly resultOffset resultRecordCount].freeze
19
23
 
20
24
  attr_reader :valid_params # other accessors set in constructor
21
25
 
22
- def initialize(url)
26
+ def initialize(url, headers = {})
23
27
  super
24
28
  generate_attributes # dynamically create & assign values to attributes :)
29
+ @fields = fields
25
30
  end
26
31
 
27
32
  def count
28
33
  @version > 10 ? count_only_true : object_ids.count # v10.1 onwards
29
34
  end
30
35
 
31
- def object_ids # care - must specify outFields to overide default '*'
32
- query(outFields: nil, returnIdsOnly: true)['objectIds']
36
+ def object_ids
37
+ query(outFields: nil, returnIdsOnly: true)['objectIds'] # care - must specify outFields to overide default '*'
38
+ end
39
+
40
+ def query(options = {})
41
+ validate(options.keys.map(&:to_s).sort)
42
+ valid_resp(DEFAULT_PARAMS.merge(options))
33
43
  end
34
44
 
35
45
  def features(options = {})
@@ -37,9 +47,10 @@ module ArcREST
37
47
  end
38
48
 
39
49
  def valid_opts
40
- return PARAMS if @version < 10 || @version == 10.0
50
+ return PARAMS if @version < 10 || @version.to_s == '10.0'
41
51
  return (PARAMS + PARAMS_SP1).sort if @version < 10.1
42
52
  return (PARAMS + PARAMS_SP1 + PARAMS_10_1).sort if @version < 10.2
53
+
43
54
  (PARAMS + PARAMS_SP1 + PARAMS_10_1 + PARAMS_10_3).sort
44
55
  end
45
56
 
@@ -58,13 +69,9 @@ module ArcREST
58
69
  words[1..-1].map(&:capitalize).unshift(words.first).join
59
70
  end
60
71
 
61
- def query(options)
62
- validate(options.keys.map(&:to_s).sort)
63
- valid_resp(build_uri, DEFAULT_PARAMS.merge(options))
64
- end
72
+ def valid_resp(opts)
73
+ raise BadQuery, m(opts) if (resp = parse_json(query_url, opts)).keys.include? 'error'
65
74
 
66
- def valid_resp(uri, opts)
67
- raise InvalidQuery, m(opts) if (resp = json(uri, opts)).keys.include? ERR
68
75
  resp
69
76
  end
70
77
 
@@ -84,8 +91,8 @@ module ArcREST
84
91
  query(returnCountOnly: true)['count']
85
92
  end
86
93
 
87
- def build_uri
88
- URI::HTTP.build(host: @uri.host, path: "#{@uri.path}/query")
94
+ def query_url
95
+ "#{@server_url}/query"
89
96
  end
90
97
  end
91
98
  end
@@ -1,48 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
4
+ require 'open-uri'
2
5
  require 'json'
3
6
 
7
+ require_relative 'curlable'
8
+
4
9
  module ArcREST
5
- # adds metadata method
10
+ # superclass
6
11
  class Server
7
- REGEX = %r{^\/arcgis\/rest\/services}i
8
- BAD_ENDPOINT = 'Invalid ArcGIS endpoint'.freeze
12
+ include Curlable # for #curl_get
13
+
14
+ ENDPOINT_REGEX = %r{/arcgis/rest/services/?}i.freeze
15
+ BAD_ENDPOINT = 'Invalid ArcGIS endpoint'
9
16
 
10
17
  attr_reader :url, :json, :version
11
18
 
12
- def initialize(url)
19
+ def initialize(url, headers = {})
13
20
  @url = url
14
- @uri = uri
15
- @server_uri = server_uri
16
- @json = json(@uri)
17
- @version = version
21
+ @headers = headers
22
+ validate_endpoint_url
23
+ @server_url = server_url
24
+ @json = json_
25
+ @version = version_
18
26
  end
19
27
 
20
- def json(uri, options = {})
21
- JSON.parse get(uri, options)
28
+ protected
29
+
30
+ def server_url
31
+ @url[-1] == '/' ? @url[0..-2] : @url
22
32
  end
23
33
 
24
- def version
25
- json(server_uri)['currentVersion'] # subclasses use server uri
34
+ def json_
35
+ parse_json
26
36
  end
27
37
 
28
- protected
38
+ def version_
39
+ parse_json['currentVersion'] # subclasses use server uri
40
+ end
29
41
 
30
- def uri
31
- raise ArgumentError, BAD_ENDPOINT if (URI(@url).path =~ REGEX) != 0
32
- URI @url
42
+ def parse_json(url = @server_url, options = {})
43
+ JSON.parse get(url, options)
33
44
  end
34
45
 
35
- def server_uri
36
- URI::HTTP.build(host: @uri.host, path: '/arcgis/rest/services')
46
+ def validate_endpoint_url
47
+ raise ArgumentError, BAD_ENDPOINT unless @url =~ ENDPOINT_REGEX
37
48
  end
38
49
 
39
50
  def add_json_param_to(hash)
40
- { f: 'pjson' }.merge(hash) # 'pjson' guarantees id's unique
51
+ { f: 'json' }.merge(hash)
52
+ end
53
+
54
+ def get(url, options = {})
55
+ curl_get(query_string(url, options), @headers)
41
56
  end
42
57
 
43
- def get(uri, options = {})
44
- uri.query = URI.encode_www_form(add_json_param_to(options))
45
- Net::HTTP.get uri
58
+ def query_string(url, options)
59
+ "#{url}?#{URI.encode_www_form(add_json_param_to(options))}"
46
60
  end
47
61
  end
48
62
  end
@@ -1,24 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
4
  # a FeatureService or a MapService
3
5
  class Service < Server
4
6
  attr_reader :max_record_count, :capabilities, :layers
5
7
 
6
- def initialize(url)
8
+ def initialize(url, headers = {})
7
9
  super
8
- @max_record_count = max_record_count # may be nil
9
- @capabilities = capabilities # may be empty
10
- @layers = layers # may be empty
10
+ @max_record_count = max_record_count_
11
+ @capabilities = capabilities_
12
+ @layers = layers_
11
13
  end
12
14
 
13
- def max_record_count
15
+ private
16
+
17
+ def max_record_count_
14
18
  @json['maxRecordCount']
15
19
  end
16
20
 
17
- def capabilities
21
+ def capabilities_
18
22
  @json['capabilities'] ? @json['capabilities'].split(',') : nil
19
23
  end
20
24
 
21
- def layers
25
+ def layers_
22
26
  @json['layers']
23
27
  end
24
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
- VERSION = '0.0.1'.freeze
4
+ VERSION = '0.0.6'
3
5
  end
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.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
- - Bruce Steedman
7
+ - matzfan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-08 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,94 +16,123 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: guard
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '2.14'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '2.14'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: guard-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '4.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '4.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: guard
56
+ name: libnotify
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.14'
61
+ version: '0.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.14'
68
+ version: '0.9'
69
69
  - !ruby/object:Gem::Dependency
70
- name: guard-rspec
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4.7'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '4.7'
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.10'
83
97
  - !ruby/object:Gem::Dependency
84
- name: ruby_gntp
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.3'
103
+ version: '1.3'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.3'
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: curb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.11
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.11
97
125
  description: Wrapper for ArcGIS REST API
98
126
  email:
99
- - bruce.steedman@gmail.com
127
+ - matzfan@yandex.com
100
128
  executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
104
132
  - ".gitignore"
133
+ - ".gitlab-ci.yml"
105
134
  - ".rspec"
106
- - ".travis.yml"
135
+ - ".rubocop.yml"
107
136
  - Gemfile
108
137
  - Guardfile
109
138
  - LICENSE.txt
@@ -115,11 +144,12 @@ files:
115
144
  - lib/arcrest.rb
116
145
  - lib/arcrest/attributable.rb
117
146
  - lib/arcrest/catalog.rb
147
+ - lib/arcrest/curlable.rb
118
148
  - lib/arcrest/layer.rb
119
149
  - lib/arcrest/server.rb
120
150
  - lib/arcrest/service.rb
121
151
  - lib/arcrest/version.rb
122
- homepage: https://github.com/MatzFan/arcrest
152
+ homepage: https://gitlab.com/matzfan/arcrest
123
153
  licenses:
124
154
  - MIT
125
155
  metadata: {}
@@ -131,15 +161,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
161
  requirements:
132
162
  - - ">="
133
163
  - !ruby/object:Gem::Version
134
- version: '0'
164
+ version: '2.4'
135
165
  required_rubygems_version: !ruby/object:Gem::Requirement
136
166
  requirements:
137
167
  - - ">="
138
168
  - !ruby/object:Gem::Version
139
169
  version: '0'
140
170
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.5.1
171
+ rubygems_version: 3.1.4
143
172
  signing_key:
144
173
  specification_version: 4
145
174
  summary: Wrapper for ArcGIS REST API
@@ -1,10 +0,0 @@
1
- sudo: false
2
- language: ruby
3
-
4
- rvm:
5
- - 2.3.1
6
- - 2.2.5
7
-
8
- before_install: gem install bundler -v 1.12.5
9
-
10
- script: bundle exec rspec spec