arcrest 0.0.3 → 0.0.4

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
- SHA1:
3
- metadata.gz: c27f5abfa74c8a59790b373ace7d84486332d635
4
- data.tar.gz: 3f89ea3cfb848ef9dacc062fd76909a9c7592da4
2
+ SHA256:
3
+ metadata.gz: '094692ab842a296611709975fe686c760c663f0979a6ac610d4cb05c9cee8154'
4
+ data.tar.gz: 714b1484b6edbd395ca8b54735b267f46936afaea06d904c3ebdfeab1d7d7045
5
5
  SHA512:
6
- metadata.gz: ec93299a63e2c0b2e85d64f88bdddaa3a54a1254b71f74ad86d903313d30061b15786bf52d5dc9d6f376f892664322e7f7ffc1e5896ac51370509f06e075c6cd
7
- data.tar.gz: 159cfa5b8cf221d489537d6ce5f5ef93b3b0ee010d572bdba8e4c9e9fc81c385aa7030715ad20493b8d8051571819ccf58b36c967b3f9c7fd39c7e89eb54a16c
6
+ metadata.gz: 9ff644960db61b5fd69bccfb5a5dae58c475f157a48eb01cdedd0b7b348f4c4be71687b51ea7da4508a740b7d1a11f806f2363255ba0ac512ecd9ebcb6790415
7
+ data.tar.gz: 3c3f64142e4c687ffc3e03fe1e023ff323510eec51b047440547c9d725f4d5232176b890acf46125acc645f47b6d8369199429cf5f888bb9495b6067e1f331eb
@@ -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
+ # frozen_string_literal: true
2
+
1
3
  notification :libnotify, transient: true, append: false, urgency: :critical
2
4
 
3
5
  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
11
-
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,67 +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('https://www.geomac.gov/arcgis/rest/services')
36
+ catalog = ArcREST::Catalog.new 'https://sampleserver6.arcgisonline.com/arcgis/rest/services'
40
37
  puts catalog.services
41
- #=> {"name"=>"BIADigit", "type"=>"FeatureServer"}
42
- #=> {"name"=>"BIADigit", "type"=>"MapServer"}
43
- #=> {"name"=>"contAF", "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('https://www.geomac.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
- Catalog, Service and Layer have a ```json``` method which returns information from the relevant server as a Hash (derived from JSON). In addition to the example methods above this can be parsed in the usual way - e.g:
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:
69
85
  ```ruby
70
86
  puts layer.json.keys.inspect
71
- #=> ["currentVersion", "id", "name", "type", "description", "copyrightText"...
87
+ #=> ["currentVersion", "id", "name", "type", "parentLayer", "defaultVisibility", ...
72
88
  ```
73
89
 
74
- Once you have a Layer object, you can perform queries on it. The [documention](http://services.arcgisonline.com/arcgis/sdk/rest/index.html#/Query_Feature_Service_Layer/) shows the possibilities. Here is a very simple example:
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:
75
91
 
76
92
  The ```query``` method returns the whole server response as a Hash:
77
93
  ```ruby
78
94
  puts layer.query(where: '1=0').inspect
79
- #=> {"objectIdFieldName"=>"objectid", "globalIdFieldName"=>"", "features"=>[]}
95
+ #=> {"objectIdFieldName"=>"objectid", "globalIdFieldName"=>"globalid", "geometryType"=>"esriGeometryPoint", "spatialReference"=>{"wkid"=>4326, "latestWkid"=>4326}, "features"=>[]}
80
96
  ```
81
97
 
82
98
  If you just want the features, use the ```features``` method:
83
99
  ```ruby
84
- features = layer.features(where: "agency='BLM'", returnGeometry: false)
85
100
  puts features.count
86
- #=> 2
87
- puts features.first
88
- #=> {"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", ...
89
112
  ```
90
113
 
91
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:
92
115
  ```ruby
93
116
  puts layer.valid_opts.inspect
94
- #=> ["dbVersion", "distance", "geometry", "geometryPrecision"...
117
+ #=> ["dbVersion", "distance", "geometry", "geometryPrecision", ... , "where"]
95
118
  ```
96
- 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.
97
120
 
98
121
 
99
- 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 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:
100
123
  ```json
101
124
  {
102
125
  "error": {
@@ -113,14 +136,14 @@ The ```:where``` key is used with any valid SQL to query the layer fields. The d
113
136
 
114
137
  ## Specification & Tests
115
138
 
116
- 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:
117
140
 
118
- $ rake spec
141
+ $ bundle exec rake spec
119
142
 
120
143
 
121
144
  ## Contributing
122
145
 
123
- 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
124
147
 
125
148
 
126
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,17 +1,20 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'arcrest/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
8
  spec.name = 'arcrest'
7
9
  spec.version = ArcREST::VERSION
8
- spec.authors = ['Bruce Steedman']
9
- spec.email = ['bruce.steedman@gmail.com']
10
+ spec.authors = ['matzfan']
11
+ spec.email = ['matzfan@yandex.com']
10
12
 
11
13
  spec.summary = 'Wrapper for ArcGIS REST API'
12
14
  spec.description = 'Wrapper for ArcGIS REST API'
13
- spec.homepage = 'https://github.com/MatzFan/arcrest'
14
- spec.license = 'MIT'
15
+ spec.homepage = 'https://gitlab.com/matzfan/ArcREST'
16
+ spec.required_ruby_version = '>= 2.4'
17
+ spec.license = 'MIT'
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
20
  f.match(%r{^(test|spec|features)/})
@@ -20,10 +23,13 @@ Gem::Specification.new do |spec|
20
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
24
  spec.require_paths = ['lib']
22
25
 
23
- spec.add_development_dependency 'bundler', '~> 1.15'
24
- spec.add_development_dependency 'rake', '~> 12.1'
25
- spec.add_development_dependency 'rspec', '~> 3.6'
26
+ spec.add_development_dependency 'bundler', '~> 2.1'
26
27
  spec.add_development_dependency 'guard', '~> 2.14'
27
28
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
28
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'
29
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,9 +1,11 @@
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
10
  @folders = folders_
9
11
  @services = services_
@@ -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.headers['Upgrade-Insecure-Requests'] = 1
31
+ headers.each { |k, v| curl.headers[k.capitalize] = v }
32
+ end
33
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
4
  class InvalidOption < StandardError; end
3
5
  class BadQuery < StandardError; end
@@ -5,8 +7,7 @@ module ArcREST
5
7
  class Layer < Server
6
8
  include Attributable
7
9
 
8
- E = 'error'.freeze
9
- DATE = 'esriFieldTypeDate'.freeze
10
+ DATE = 'esriFieldTypeDate'
10
11
  ATTRIBUTES = %w[id name type drawing_info fields max_record_count].freeze
11
12
  DEFAULT_PARAMS = { where: '1=1', outFields: '*' }.freeze
12
13
  PARAMS = %w[distance geometry geometryType inSR objectIds
@@ -20,7 +21,7 @@ module ArcREST
20
21
 
21
22
  attr_reader :valid_params # other accessors set in constructor
22
23
 
23
- def initialize(url)
24
+ def initialize(url, headers = {})
24
25
  super
25
26
  generate_attributes # dynamically create & assign values to attributes :)
26
27
  @fields = fields
@@ -30,13 +31,13 @@ module ArcREST
30
31
  @version > 10 ? count_only_true : object_ids.count # v10.1 onwards
31
32
  end
32
33
 
33
- def object_ids # care - must specify outFields to overide default '*'
34
- query(outFields: nil, returnIdsOnly: true)['objectIds']
34
+ def object_ids
35
+ query(outFields: nil, returnIdsOnly: true)['objectIds'] # care - must specify outFields to overide default '*'
35
36
  end
36
37
 
37
38
  def query(options = {})
38
39
  validate(options.keys.map(&:to_s).sort)
39
- valid_resp(build_uri, DEFAULT_PARAMS.merge(options))
40
+ valid_resp(DEFAULT_PARAMS.merge(options))
40
41
  end
41
42
 
42
43
  def features(options = {})
@@ -44,9 +45,10 @@ module ArcREST
44
45
  end
45
46
 
46
47
  def valid_opts
47
- return PARAMS if @version < 10 || @version == 10.0
48
+ return PARAMS if @version < 10 || @version.to_s == '10.0'
48
49
  return (PARAMS + PARAMS_SP1).sort if @version < 10.1
49
50
  return (PARAMS + PARAMS_SP1 + PARAMS_10_1).sort if @version < 10.2
51
+
50
52
  (PARAMS + PARAMS_SP1 + PARAMS_10_1 + PARAMS_10_3).sort
51
53
  end
52
54
 
@@ -65,8 +67,9 @@ module ArcREST
65
67
  words[1..-1].map(&:capitalize).unshift(words.first).join
66
68
  end
67
69
 
68
- def valid_resp(uri, opts)
69
- raise BadQuery, m(opts) if (resp = parse_json(uri, opts)).keys.include? E
70
+ def valid_resp(opts)
71
+ raise BadQuery, m(opts) if (resp = parse_json(query_url, opts)).keys.include? 'error'
72
+
70
73
  resp
71
74
  end
72
75
 
@@ -86,8 +89,8 @@ module ArcREST
86
89
  query(returnCountOnly: true)['count']
87
90
  end
88
91
 
89
- def build_uri
90
- URI::HTTP.build(host: @uri.host, path: "#{@uri.path}/query")
92
+ def query_url
93
+ "#{@server_url}/query"
91
94
  end
92
95
  end
93
96
  end
@@ -1,53 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
  require 'open-uri'
3
5
  require 'json'
4
6
 
7
+ require_relative 'curlable'
8
+
5
9
  module ArcREST
6
- # adds metadata method
10
+ # superclass
7
11
  class Server
8
- REGEX = %r{^\/arcgis\/rest\/services}i
9
- 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'
10
16
 
11
17
  attr_reader :url, :json, :version
12
18
 
13
- def initialize(url)
19
+ def initialize(url, headers = {})
14
20
  @url = url
15
- @uri = uri
16
- @server_uri = server_uri
21
+ @headers = headers
22
+ validate_endpoint_url
23
+ @server_url = server_url
17
24
  @json = json_
18
25
  @version = version_
19
26
  end
20
27
 
21
28
  protected
22
29
 
30
+ def server_url
31
+ @url[-1] == '/' ? @url[0..-2] : @url
32
+ end
33
+
23
34
  def json_
24
- parse_json @uri
35
+ parse_json
25
36
  end
26
37
 
27
38
  def version_
28
- parse_json(server_uri)['currentVersion'] # subclasses use server uri
39
+ parse_json['currentVersion'] # subclasses use server uri
29
40
  end
30
41
 
31
- def parse_json(uri, options = {})
32
- JSON.parse get(uri, options)
42
+ def parse_json(url = @server_url, options = {})
43
+ JSON.parse get(url, options)
33
44
  end
34
45
 
35
- def uri
36
- raise ArgumentError, BAD_ENDPOINT if (URI(@url).path =~ REGEX) != 0
37
- URI @url
46
+ def validate_endpoint_url
47
+ raise ArgumentError, BAD_ENDPOINT unless @url =~ ENDPOINT_REGEX
38
48
  end
39
49
 
40
- def server_uri
41
- URI::HTTP.build(host: @uri.host, path: '/arcgis/rest/services')
50
+ def add_json_param_to(hash)
51
+ { f: 'json' }.merge(hash)
42
52
  end
43
53
 
44
- def add_json_param_to(hash)
45
- { f: 'pjson' }.merge(hash) # 'pjson' guarantees id's unique
54
+ def get(url, options = {})
55
+ curl_get(query_string(url, options), @headers)
46
56
  end
47
57
 
48
- def get(uri, options = {})
49
- uri.query = URI.encode_www_form(add_json_param_to(options))
50
- open(uri).read # net/http doesn't follow redirects..
58
+ def query_string(url, options)
59
+ "#{url}?#{URI.encode_www_form(add_json_param_to(options))}"
51
60
  end
52
61
  end
53
62
  end
@@ -1,9 +1,11 @@
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
10
  @max_record_count = max_record_count_
9
11
  @capabilities = capabilities_
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArcREST
2
- VERSION = '0.0.3'.freeze
4
+ VERSION = '0.0.4'
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.3
4
+ version: 0.0.4
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: 2017-09-26 00:00:00.000000000 Z
11
+ date: 2020-11-20 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.15'
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.15'
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: '12.1'
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: '12.1'
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.6'
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.6'
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
83
  - !ruby/object:Gem::Dependency
84
- name: libnotify
84
+ name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.9'
89
+ version: '3.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.9'
96
+ version: '3.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
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.6.13
171
+ rubygems_version: 3.1.4
143
172
  signing_key:
144
173
  specification_version: 4
145
174
  summary: Wrapper for ArcGIS REST API
@@ -1,9 +0,0 @@
1
- sudo: false
2
- language: ruby
3
-
4
- rvm:
5
- - 2.4.2
6
-
7
- before_install: gem install bundler -v 1.15.4
8
-
9
- script: bundle exec rspec spec