ArcGIS Online Ruby Library

This library is a simple wrapper around the ArcGIS Online sharing API for Users, Groups, Items, and Search.

The library currently just exposes the API endpoints and accepts unverified hashes of input parameters as specified in the ArcGIS API. As it evolves more endpoints will be added as well as more Ruby-like objects for the various API capabilities.

It is intended to be a replacement for the ArcGIS Gem

Install

Just install using Rubygems:

gem install arcgis-ruby

Instructions

# Create a client
connection = Arcgis::Connection.new(host: "http://www.arcgis.com/sharing/rest/")

# Do an unauthenticated search
results = connection.search(q: "weather", itemtype: "Web Map")

# For features with permissions, first log in
connection = Arcgis::Connection.new(
  host: "http://www.arcgis.com/sharing/rest/",
  username: @username,
  password: @password)

# Create an item
response = connection.item.create(:title => "Weather Station Temperatures",
                  :type => "CSV",
                  :file => File.open("my_data.csv"),
                  :tags  => %w{temperature stations}.join(","))

@id = response["id"]
puts "This item has #{response['numComments']} comments."

# Publish as a feature service
item = connection.item(@id)
analysis = item.analyze(type: => "CSV")
publish = item.publish(filetype: "Feature Service",
                       publishParameters: analysis["publishParameters"].to_json)

puts "Feature Service URL: " + publish["services"].first["serviceurl"]

# Clean up
item.delete
connection.item(publish["services"].first["serviceItemId"]).delete

Testing

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:

$ rspec

Requirements

  • Ruby
  • Typhoeus
  • JSON

Resources

Licensing

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.