arcgis-ruby 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f39e8d5b9488d381e91dd22c73959b49ee2c720d
4
+ data.tar.gz: 3057e9fbc612c01d768f2451d19179a67fbd71b2
5
+ SHA512:
6
+ metadata.gz: 367eda7819093deff8ee80653262efee20304b133ed69b4376c3587c263e33da3288055598646e93e68fccff3636094a140b41a2d282c78fa54591161f361dfe
7
+ data.tar.gz: 05c380fedf779562e862059cc38999561461ce3b7c2507450882dd3b9a36e37de355409622665e1f0f0c19f8f91e914ea9506afaf741333b143ead76540268c3
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ config.yml
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,48 @@
1
+ Apache License – 2.0
2
+
3
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4
+
5
+ 1. Definitions.
6
+
7
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
8
+
9
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
10
+
11
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
12
+
13
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
14
+
15
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
16
+
17
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
18
+
19
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
20
+
21
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
22
+
23
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
24
+
25
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
26
+
27
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
28
+
29
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
30
+
31
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
32
+
33
+ 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
34
+ 2. You must cause any modified files to carry prominent notices stating that You changed the files; and
35
+ 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
36
+ 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
37
+
38
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
39
+
40
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
41
+
42
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
43
+
44
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
45
+
46
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
47
+
48
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,85 @@
1
+ # ArcGIS Online Ruby Library
2
+
3
+ This library is a simple wrapper around the ArcGIS Online sharing API for Users, Groups, Items, and Search.
4
+
5
+ The library currently just exposes the API endpoints and accepts unverified hashes of input parameters as specified in the [ArcGIS API](http://www.arcgis.com/apidocs/rest/). As it evolves more endpoints will be added as well as more Ruby-like objects for the various API capabilities.
6
+
7
+ It is intended to be a replacement for the [ArcGIS Gem](https://github.com/ajturner/arcgis-ruby)
8
+
9
+ ## Install
10
+
11
+ Just install using Rubygems:
12
+
13
+ `gem install arcgis-ruby`
14
+
15
+ ## Instructions
16
+
17
+ ```ruby
18
+ # Create a client
19
+ connection = Arcgis::Connection.new(host: "http://www.arcgis.com/sharing/rest/")
20
+
21
+ # Do an unauthenticated search
22
+ results = connection.search(q: "weather", itemtype: "Web Map")
23
+
24
+ # For features with permissions, first log in
25
+ connection = Arcgis::Connection.new(
26
+ host: "http://www.arcgis.com/sharing/rest/",
27
+ username: @username,
28
+ password: @password)
29
+
30
+ # Create an item
31
+ response = connection.item.create(:title => "Weather Station Temperatures",
32
+ :type => "CSV",
33
+ :file => File.open("my_data.csv"),
34
+ :tags => %w{temperature stations}.join(","))
35
+
36
+ @id = response["id"]
37
+ puts "This item has #{response['numComments']} comments."
38
+
39
+ # Publish as a feature service
40
+ item = connection.item(@id)
41
+ analysis = item.analyze(type: => "CSV")
42
+ publish = item.publish(filetype: "Feature Service",
43
+ publishParameters: analysis["publishParameters"].to_json)
44
+
45
+ puts "Feature Service URL: " + publish["services"].first["serviceurl"]
46
+
47
+ # Clean up
48
+ item.delete
49
+ connection.item(publish["services"].first["serviceItemId"]).delete
50
+ ```
51
+
52
+ ### Testing
53
+
54
+ arcgis-ruby uses RSpec for tests. First copy @config.yml.example@ to @config.yml@ and modify the username and password. Then from the command line run:
55
+
56
+ $ rspec
57
+
58
+
59
+ ## Requirements
60
+
61
+ * Ruby
62
+ * Typhoeus
63
+ * JSON
64
+
65
+ ## Resources
66
+
67
+ * [ArcGIS Portal API](http://www.arcgis.com/apidocs/rest/)
68
+
69
+ ## Licensing
70
+ Licensed under the Apache License, Version 2.0 (the "License");
71
+ you may not use this file except in compliance with the License.
72
+ You may obtain a copy of the License at
73
+
74
+ http://www.apache.org/licenses/LICENSE-2.0
75
+
76
+ Unless required by applicable law or agreed to in writing, software
77
+ distributed under the License is distributed on an "AS IS" BASIS,
78
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
79
+ See the License for the specific language governing permissions and
80
+ limitations under the License.
81
+
82
+ A copy of the license is available in the repository's [license.txt](./license.txt) file.
83
+
84
+ [](Esri Tags: ArcGIS Ruby API AGOL Public)
85
+ [](Esri Language: Ruby)
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: arcgis-ruby 0.0.1 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "arcgis-ruby"
6
+ s.version = "0.0.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Jake Sower"]
11
+ s.date = "2015-10-15"
12
+ s.email = "jsower@esri.com"
13
+ s.summary = "A simple wrapper for ArcGIS Online sharing API"
14
+ s.license = 'apache'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+
22
+ s.add_dependency 'typhoeus', ">= 0.8.0"
23
+ s.add_dependency 'json'
24
+
25
+ s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'rake'
27
+
28
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/rdf ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rdf' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rdf', 'rdf')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,6 @@
1
+ require 'typhoeus'
2
+ require 'json'
3
+
4
+ require File.dirname(__FILE__) + '/routes.rb'
5
+ require File.dirname(__FILE__) + '/arcgis/connection.rb'
6
+ require File.dirname(__FILE__) + '/arcgis/model.rb'
@@ -0,0 +1,102 @@
1
+ class Arcgis::Connection
2
+ @@object_registry = {}
3
+
4
+ attr_reader :username
5
+
6
+ #
7
+ # Take in username/password upon initialization
8
+ #
9
+ def initialize(host:, username: nil, password: nil)
10
+ @host = host.sub(/\/$/,'')
11
+ @token, @token_expires = nil, nil
12
+ @username, @password = username, password
13
+
14
+ if username && password
15
+ login(username, password)
16
+ end
17
+ end
18
+
19
+
20
+ def login(username, password)
21
+ response = run(
22
+ path: "/generateToken",
23
+ method: "POST",
24
+ body: {username: username, password: password, referer: "http://arcgis.com"}
25
+ )
26
+
27
+ @token = response["token"]
28
+ @token_expires = Time.at(response["expires"]/1000)
29
+ end
30
+
31
+
32
+ def search(params={})
33
+ run(
34
+ path: "/search",
35
+ params: params
36
+ )
37
+ end
38
+
39
+
40
+ def run(path:, method: "GET", params: {}, headers: {}, body: {})
41
+ full_params = default_params.merge(params)
42
+
43
+ # JSON encode array and hash fields
44
+ params, body = sanitize_params(params), sanitize_params(body)
45
+
46
+ request = Typhoeus::Request.new(
47
+ @host + path,
48
+ {method: method, params: full_params, headers: headers, body: body}
49
+ )
50
+
51
+ handle_response(request.run)
52
+ end
53
+
54
+
55
+ def default_params
56
+ @token.nil? ? {f: :json} : {f: :json, token: @token}
57
+ end
58
+
59
+
60
+ # also used on body
61
+ def sanitize_params(params)
62
+ params.reduce({}) do |agg,(k,v)|
63
+ agg[k] = (v.is_a?(Hash) || v.is_a?(Array)) ? v.to_json : v
64
+ agg
65
+ end
66
+ end
67
+
68
+
69
+ def handle_response(response)
70
+ if response.success?
71
+ r = JSON.parse(response.body)
72
+ raise ErrorResponse.new(r["error"]) if r["error"]
73
+ r
74
+ else
75
+ raise response.inspect
76
+ end
77
+ end
78
+
79
+
80
+ #
81
+ # Connection acts as something of a container for different AGOL models,
82
+ # passing its own information along to them.
83
+ #
84
+ (Arcgis::Routes::ROUTES.keys - [:root]).each do |object|
85
+ define_method object do |id = nil|
86
+ Arcgis::Model.build(connection: self, type: object, id: id)
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+
93
+
94
+ class ErrorResponse < RuntimeError
95
+ attr_accessor :response
96
+ def initialize(response={})
97
+ message = response["message"] || response[:message] || response[:code] || response.inspect
98
+ message += response["details"].join("\n") if response["details"]
99
+ super(message)
100
+ @response = response
101
+ end
102
+ end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Acts as a builder for classes based on routes.rb. This should be considered
3
+ # private. All entry points to models should come through connection.
4
+ #
5
+ module Arcgis::Model
6
+ class << self
7
+ @@classes = {}
8
+
9
+
10
+ #
11
+ # Sole entry point into the module--looks up the appropriate class by
12
+ # type (e.g. item, group, etc.) and initializes an instance of it
13
+ #
14
+ def build(connection:, type:, id: nil)
15
+ class_for_type(type).new(connection, id)
16
+ end
17
+
18
+
19
+ #
20
+ # Returns a copy of a class to handle the appropriate object type, creating
21
+ # the class if needed
22
+ #
23
+ def class_for_type(type)
24
+ @@classes[type] ||= Class.new do
25
+ def initialize(connection, id)
26
+ @connection, @id = connection, id
27
+ end
28
+
29
+
30
+ #
31
+ # Helper method to extract HTTP method, argument names, the the path.
32
+ # e.g. "POST /content/users/:username/items/:id/delete" becomes
33
+ # {method: "POST", args: ["username", "id"],
34
+ # path: "/content/users/:username/items/:id/delete"}
35
+ #
36
+ def extract_config(path_config)
37
+ method, path_pattern = path_config.split(' ')
38
+ args = path_pattern.scan(/\/:[^\/]+/)
39
+ arg_names = args.map{|a| a[2..-1]}
40
+ return { method: method, args: arg_names, path: path_pattern }
41
+ end
42
+
43
+
44
+ #
45
+ # Args to be merged into every path
46
+ #
47
+ def default_args
48
+ {id: @id, username: @connection.username}
49
+ end
50
+
51
+
52
+ # Helper procs
53
+ stringify_keys = ->(x) { x.reduce({}){|h, (k,v)| h[k.to_s] = v; h} }
54
+ symbolize_keys = ->(x) { x.reduce({}){|h, (k,v)| h[k.to_s.to_sym] = v; h} }
55
+
56
+ Arcgis::Routes::ROUTES[type].each_pair do |meth, path_config|
57
+ #
58
+ # Creates the specific path for a request, merging default_args with
59
+ # user-provided arguments, to create a final path.
60
+ # e.g. for item: delete: "POST /content/users/:username/items/:id/delete"
61
+ # substitutes in :username and :id to get something like
62
+ # {method: "POST",
63
+ # path: "/content/users/someuser/items/4e770315ad9049e7950b552aa1e40869/delete"}
64
+ #
65
+ self.send(:define_method, "#{meth}_path") do |local_args = {}|
66
+ # stringify keys
67
+ local_args = stringify_keys[local_args]
68
+
69
+ config = self.extract_config(path_config)
70
+ args = stringify_keys[self.default_args.merge(local_args)]
71
+
72
+ path = config[:args].reduce(config[:path]) do |u,arg|
73
+ u.sub("/:#{arg}", "/#{args[arg]}")
74
+ end
75
+
76
+ {method: config[:method], path: path}
77
+ end
78
+
79
+
80
+ #
81
+ # Creates a method for each route in the routes file that merges in
82
+ # variables (see #{meth}_path) and then runs the request via the
83
+ # connection
84
+ #
85
+ self.send(:define_method, "#{meth}") do |local_args = {}|
86
+ local_args = symbolize_keys[local_args]
87
+ path_args = send("#{meth}_path")
88
+ args = (path_args[:method] == "GET") ?
89
+ path_args.merge(params: stringify_keys[local_args]) :
90
+ path_args.merge(body: stringify_keys[local_args])
91
+
92
+ @connection.run(args)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,82 @@
1
+ # Provides pseudo-routes from local methods to AGOL URLs. These get loaded into
2
+ # AGOL model objects via Agol::Model::load_routes.
3
+
4
+ module Arcgis
5
+ module Routes
6
+ ROUTES = {
7
+ root: {
8
+ search: "GET /search",
9
+ generate_token: "POST /generateToken"
10
+ },
11
+
12
+ group: {
13
+ fetch: "GET /community/groups/:id",
14
+ items: "GET /content/groups/:id/items",
15
+ users: "GET /community/groups/:id/users",
16
+ applications: "GET /community/groups/:id/applications",
17
+ add_item: "POST /content/groups/:id/addItem",
18
+ update: "POST /community/groups/:id/update",
19
+ reassign: "POST /community/groups/:id/reassign",
20
+ delete: "POST /community/groups/:id/delete",
21
+ join: "POST /community/groups/:id/join",
22
+ invite: "POST /community/groups/:id/invite",
23
+ leave: "POST /community/groups/:id/leave",
24
+ remove_users: "POST /community/groups/:id/removeUsers",
25
+ create: "POST /community/createGroup"
26
+ },
27
+
28
+ item: {
29
+ fetch: "GET /content/items/:id",
30
+ comments: "GET /content/items/:id/comments",
31
+ rating: "GET /content/items/:id/rating",
32
+ related_items: "GET /content/items/:id/relatedItems",
33
+ data: "GET /content/items/:id/data",
34
+ groups: "GET /content/items/:id/groups",
35
+ add_relationship: "POST /content/items/:id/addRelationship",
36
+ delete_relationship: "POST /content/items/:id/deleteRelationship",
37
+ add_comment: "POST /content/items/:id/addComment",
38
+ add_rating: "POST /content/items/:id/addRating",
39
+ delete_rating: "POST /content/items/:id/deleteRating",
40
+ share: "POST /content/items/:id/share",
41
+ unshare: "POST /content/items/:id/unshare",
42
+ delete: "POST /content/users/:username/items/:id/delete",
43
+ create: "POST /content/users/:username/addItem"
44
+ },
45
+
46
+ comment: {
47
+ fetch: "GET /content/items/:item_id/comments/:id",
48
+ update: "POST /content/items/:item_id/comments/:id/update",
49
+ delete: "POST /content/items/:item_id/comments/:id/delete"
50
+ },
51
+
52
+ feature: {
53
+ analyze: "POST /content/features/analyze",
54
+ generate: "GET /content/features/generate"
55
+ },
56
+
57
+ user: {
58
+ fetch: "GET /community/users/:username",
59
+ items: "GET /content/users/:username/items",
60
+ add_relationship: "POST /content/users/:username/addRelationship",
61
+ delete_relationship: "POST /content/users/:username/deleteRelationship",
62
+ publish_item: "POST /content/users/:username/publish",
63
+ export_item: "POST /content/users/:username/exportItem",
64
+ share_items: "POST /content/users/:username/shareItems",
65
+ unshare_items: "POST /content/users/:username/unshareItems",
66
+ move_items: "POST /content/users/:username/moveItems",
67
+ notifications: "GET /community/users/:username/notifications",
68
+ tags: "GET /community/users/:username/tags",
69
+ invitations: "GET /community/users/:username/invitations",
70
+ update: "POST /community/users/:username/update",
71
+ delete: "POST /community/users/:username/delete",
72
+ create_folder: "POST /content/users/:username/createFolder",
73
+ delete_folder: "POST /content/users/:username/deleteFolder",
74
+ add_items: "POST /content/users/:username/addItems",
75
+ add_item: "POST /content/users/:username/addItem",
76
+ update_items: "POST /content/users/:username/updateItems",
77
+ delete_items: "POST /content/users/:username/deleteItems",
78
+ create_service: "POST /content/users/:username/createService"
79
+ }
80
+ }
81
+ end
82
+ end
@@ -0,0 +1,119 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ RSpec.describe Arcgis::Model do
4
+ context "adding an item" do
5
+ before :all do
6
+ @username = ArcConfig.config["online"]["username"]
7
+ @online = Arcgis::Connection.new(
8
+ host: ArcConfig.config["online"]["host"],
9
+ username: ArcConfig.config["online"]["username"],
10
+ password: ArcConfig.config["online"]["password"])
11
+ end
12
+
13
+
14
+ describe "of a CSV" do
15
+ before :all do
16
+ existing = @online.search(q: "arcgis-rb")
17
+ existing["results"].map{|e| e["id"]}.each{|id| @online.item(id).delete}
18
+
19
+ @response = @online.item.create(
20
+ :title => "arcgis-rb gem test",
21
+ :type => "CSV",
22
+ :file => File.open(File.dirname(__FILE__) + "/../data/gas_data.csv"),
23
+ :tags => %w{test gas}.join(","))
24
+ @id = @response["id"]
25
+ i = @online.item(@id)
26
+ @analyze_response = @online.feature.analyze(itemid: @id, type: "CSV")
27
+ @item = i.fetch
28
+ end
29
+
30
+ context "with analysis" do
31
+ it "should have publishParameters" do
32
+ expect(@analyze_response["publishParameters"]["type"]).to eq("csv")
33
+ end
34
+
35
+ it "should have fields" do
36
+ expect(@analyze_response["publishParameters"]["layerInfo"]["fields"].length).to eq(6)
37
+ end
38
+
39
+ describe "publishing" do
40
+ before :all do
41
+ pub_params = @analyze_response["publishParameters"].merge("name" => "feature#{@id}")
42
+ @publish_response = @online.user.publish_item(
43
+ itemId: @id,
44
+ title: "arcgisrbtest2",
45
+ filetype: "Feature Service",
46
+ tags: "arcgisrbtest",
47
+ publishParameters: pub_params.to_json)
48
+ end
49
+
50
+ it "should be successful" do
51
+ expect(@publish_response.include?("services")).to eq(true)
52
+ end
53
+
54
+ it "should have a serviceUrl" do
55
+ expect(@publish_response["services"].first["serviceurl"].nil?).to eq(false)
56
+ end
57
+
58
+ it "should have a size" do
59
+ expect(@publish_response["services"].first["size"]).to eq(3116)
60
+ end
61
+
62
+ it "should have a jobId" do
63
+ expect(@publish_response["services"].first["jobId"].nil?).to eq(false)
64
+ end
65
+
66
+ it "should have a serviceItemId" do
67
+ expect(@publish_response["services"].first["serviceItemId"].nil?).to eq(false)
68
+ end
69
+
70
+ after :all do
71
+ response = @online.item(@publish_response["services"].first["serviceItemId"]).delete
72
+ expect(response["success"]).to eq(true)
73
+ end
74
+ end
75
+ end
76
+
77
+ it "should be an item" do
78
+ expect(@item["id"]).to eq(@id)
79
+ end
80
+
81
+ it "should have tags" do
82
+ expect(@item["tags"]).to eq(%w{test gas})
83
+ end
84
+
85
+ it "should have title" do
86
+ expect(@item["title"]).to eq("arcgis-rb gem test")
87
+ end
88
+
89
+ it "should have type" do
90
+ expect(@item["type"]).to eq("CSV")
91
+ end
92
+
93
+ it "should have description" do
94
+ expect(@item["description"]).to eq(nil)
95
+ end
96
+
97
+ it "should have blank rating" do
98
+ expect(@item["avgRating"]).to eq(0)
99
+ end
100
+
101
+ it "should have no ratings" do
102
+ expect(@item["numRatings"]).to eq(0)
103
+ end
104
+
105
+ it "should have no comments" do
106
+ expect(@item["numComments"]).to eq(0)
107
+ end
108
+
109
+ it "should have owner" do
110
+ expect(@item["owner"]).to eq(@username)
111
+ end
112
+
113
+ after :all do
114
+ response = @online.item(@item["id"]).delete
115
+ expect(response["success"]).to eq(true)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ online:
2
+ host: http://www.arcgis.com/sharing/rest/
3
+ username: USER
4
+ password: PASS
5
+
@@ -0,0 +1,35 @@
1
+ Lat,Lon,Description,Street,City,State
2
+ 40.357086,-74.494077,"Gas in Dayton on route 130 @ QuickChek, no wait!",Stults Rd,South Brunswick, NJ
3
+ 40.529749,-74.378683,Costco gas line not bad either and prices lower than lukoil. ,,, NJ
4
+ 40.569997,-74.611229,Hi. Is the gas station on your way open?,,,
5
+ 40.608005,-73.920289,Hi. You are waiting for gas over there? ,,,
6
+ 40.615567,-73.999589,any gas in Brooklyn????,Bay Ridge Pkwy,Brooklyn, NY
7
+ 40.618205,-73.979368,anyone knows where I can buy gas no line in bp ? ,59th St,Brooklyn, NY
8
+ 40.638776,-74.021618,Is there any gas on 711 on 65th & 3ave,,,
9
+ 40.640437,-74.913106,Amy stations open in Clinton areA?,Rachel Ct,Clinton, NJ
10
+ 40.693435,-73.852774,any gas pumps open,Jamaica Ave,Queens, NY
11
+ 40.704073,-73.816531,No gas over here,Hillside Ave,Queens, NY
12
+ 40.710468,-73.906357,Does anyone know where I can get gas in the Ridgewood Queens area?,Butler Ave,Queens, NY
13
+ 40.711576,-73.857894,gas at Sunoco on 10016 metropolitan ave in forest hills!! ,Metropolitan Ave,Queens, NY
14
+ 40.725916,-73.895372,no gas,Grand Ave,Queens, NY
15
+ 40.729355,-73.540845,gas In Levittown across from Walmart on Hempstead tmpike,Wantagh State Pkwy N,East Meadow,
16
+ 40.731942,-74.039401,Gas at the Exxon near the Holland Tunnel!!,Marin Blvd,Jersey City, NJ
17
+ 40.740488,-73.787014,was gas here when I went to work ,Horace Harding Blvd,Queens, NY
18
+ 40.785232,-73.841245,gas on 14th ave 131st delta gas station open and pumping ,127th St,Queens, NY
19
+ 40.786648,-73.826511,178 people on line for delta station,14th Ave,Queens, NY
20
+ 40.788644,-74.272665,word is they aren't pumping gas at the arsenal waiting for the ok from FEMA,Pleasant Valley Way,West Orange, NJ
21
+ 40.824485,-73.95374,any short lines for gas? yet,W 141 St,Manhattan, NY
22
+ 40.841327,-73.996875,46e sunocco in palisade park open. line not bad but getting longer. ,Abbott Ave,Palisades Park, NJ
23
+ 40.844108,-73.85317,Bronx armory gas see News 12,Colden Ave,Bronx, NY
24
+ 40.849247,-73.037099,looking for available gas in Suffolk county,Orchard Dr,Farmingville, NY
25
+ 40.852228,-73.864878,any idea where to get gas,,,
26
+ 40.852335,-74.34811,line at wawa is half of yesterday's should be less than 45 minutes. line started half way down New Rd. ,New Rd,Parsippany-Troy Hills, NJ
27
+ 40.858352,-73.352762,any gas stations in the Huntington ny open?,Manor Rd,Greenlawn, NY
28
+ 40.863279,-73.974963,lukoil is open short line @ 8 23PM,State Rte 4 E,Fort Lee, NJ
29
+ 40.864818,-74.181681,any one know what the holder up is on rte 3?,State Rte 3,Clifton, NJ
30
+ 40.870323,-73.891246,gas on Bedford and Jerome,,,
31
+ 40.92969,-73.888872,donde hay gasoline ,Van Cortlandt Park Ave,Yonkers, NY
32
+ 40.954824,-73.825425,anyone know where to get gas without long lines in eastchester?,Consulate Dr,Tuckahoe, NY
33
+ 40.98779,-74.324249,Loulou coil on route 23 S. is currently open they Gotthe lukoil on 23 south is open they got a shipment in from Philly.,State Rte 23,Riverdale, NJ
34
+ 40.993218,-73.820704,gas at 233rd by Woodlawn metro north ,Central Park Ave,Edgemont, NY
35
+ 41.183929,-74.046066,gulf gas station on 202 doesnt have long lines get ur arse there ,US Hwy 202,Ramapo, NY
@@ -0,0 +1,38 @@
1
+ require 'rspec'
2
+ require 'rspec/expectations'
3
+ require 'yaml'
4
+ require 'arcgis-ruby'
5
+
6
+ module TestHelper
7
+ def create_testing_group(options={})
8
+ connection = Arcgis::Connection.new(ArcConfig.config["online"])
9
+ connection.group.create(
10
+ :title => "Ruby Testing Group",
11
+ :description => "Group for Testing",
12
+ :access => "org",
13
+ :tags => "test,ruby")
14
+ end
15
+
16
+ def delete_testing_group
17
+ unless @group.nil? || @group["group"].nil?
18
+ @connection.group(@group["group"]["id"]).delete
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ RSpec.configure do |config|
25
+ config.expect_with :rspec do |c|
26
+ c.syntax = :expect
27
+ end
28
+ config.include TestHelper
29
+ end
30
+
31
+
32
+ module ArcConfig
33
+ class << self
34
+ def config
35
+ @config ||= YAML.load_file(File.dirname(__FILE__) + '/agol_config.yml')
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arcgis-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jake Sower
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: jsower@esri.com
71
+ executables:
72
+ - bundler
73
+ - htmldiff
74
+ - ldiff
75
+ - rdf
76
+ - rspec
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - arcgis-ruby.gemspec
86
+ - bin/bundler
87
+ - bin/htmldiff
88
+ - bin/ldiff
89
+ - bin/rdf
90
+ - bin/rspec
91
+ - lib/arcgis-ruby.rb
92
+ - lib/arcgis/connection.rb
93
+ - lib/arcgis/model.rb
94
+ - lib/routes.rb
95
+ - spec/arcgis/model_spec.rb
96
+ - spec/config.yml.example
97
+ - spec/data/gas_data.csv
98
+ - spec/spec_helper.rb
99
+ homepage:
100
+ licenses:
101
+ - apache
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.4.8
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: A simple wrapper for ArcGIS Online sharing API
123
+ test_files: []