GithubHelp home page GithubHelp logo

isabella232 / geotrigger-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esri/geotrigger-ruby

0.0 0.0 0.0 416 KB

A small Ruby client library for interacting with the Esri Geotrigger API.

License: Apache License 2.0

Ruby 100.00%

geotrigger-ruby's Introduction

geotrigger-ruby

a small ruby client for https://developers.arcgis.com/en/geotrigger-service/.

Install

gem install geotrigger

Usage

Session

Geotrigger::Session is the main interface to the Geotrigger API. Once created, it serves as the underlying support to all the Model subclasses. Its main features are:

  • wrapping communication with the Geotrigger API
  • handling all access_token negotiation with ArcGIS Online

See also API Doc

To create a Session, call #new with a optional Hash:

# specify client_id and client_secret
#
session = Geotrigger::Session.new client_id: 'abcde', client_secret: '12345'
#=> <Geotrigger::Session ... >

# specify client_id and :device type
# (registers as a new device)
#
session = Geotrigger::Session.new client_id: 'abcde', type: :device
#=> <Geotrigger::Session ... >

# specify client_id, refresh_token, and :device type
# (gets access_tokens for an existing device)
#
session = Geotrigger::Session.new client_id: 'abcde', refresh_token: 'qwert', type: :device
#=> <Geotrigger::Session ... >

# reads config from ~/.geotrigger YAML
#
session = Geotrigger::Session.new
#=> <Geotrigger::Session ... >

# reads config from ~/.geotrigger YAML :dev key
#
session = Geotrigger::Session.new config: :dev
#=> <Geotrigger::Session ... >

You can then POST to any route in the API, without worring about managing access_token lifecycles, with a normal Ruby Hash for both request parameters and additional headers. The return value will be a normal Ruby Hash parsed from the JSON response of the API. A GeotriggerError may be raised if there was a problem with your request parameters or soemthing else.

session.post 'trigger/list'
#=> { "triggers" => [] }

session.post 'device/update', deviceIds: ['abcd1234'], addTags: ['foo']
#=> { "devices" => [ { "deviceId" => "abcd1234", tags: ["foo", "device:abcd1234", ...] } ] }

begin
  session.post 'device/update', bad_param: false
rescue Geotrigger::GeotriggerError => ge

  ge.parameters
  #=> {"bad_param"=>[{"type"=>"invalid", "message"=>"Not a valid parameter for this request."}]}

end

You can do all of what you need to through this interface, but there are some more lightweight utility classes for those that prefer a more OO approach.

Models

These classes provide a ORM-ish interface to the Geotrigger API objects Application, Trigger, Tag, and Device.

Application

Application objects offer top-level access to various other model objects, as well as updating of Application specific settings.

See also API Doc

a = Geotrigger::Application.new client_id: 'abcde', client_secret: '12345'
#=> <Geotrigger::Application ... >

d = a.devices(tags: ['foo']).first
#=> <Geotrigger::Device ... >

geojson = JSON.parse File.load 'something.geojson'
t = a.triggers(geo: {geojson: geosjon}).first
#=> <Geotrigger::Trigger ... >

tag = a.tags.first
#=> <Geotrigger::Tag ... >

Trigger

Trigger objects offer access to all attributes of a Trigger.

See also API Doc

trigger.add_tags 'foo'
trigger.save

trigger.remove_tags 'bar'
trigger.properties = { foo: 'bar', baz: true, bat: 123 }
trigger.save

Device

Device objects offer access to all attributes of a Device.

See also API Doc

device.add_tags 'foo'
device.save

device.remove_tags 'bar'
device.properties = { foo: 'bar', baz: true, bat: 123 }
device.save

device.session.post 'location/update', locations: [{
  longitude: -122,
  latitude: 45,
  accuracy: 10,
  timestamp: DateTime.now.iso8601,
  trackingProfile: 'adaptive'
}]

Tag

Tag objects offer access to all attributes of a Tag.

See also API Doc

# create a new tag without applying it to any other objects
#
s = Geotrigger::Session.new
tag = Geotrigger::Tag.create s, name: 'foo', deviceTagging: false
#=> <Geotrigger::Tag ... >

Note that Tags are automatically created by the API, if needed, when added to a Trigger or Device. This offers a way to create the Tag before applying it to anything.

a = Geotrigger::Application.new client_id: 'abcde', client_secret: '12345'
#=> <Geotrigger::Application ... >

tag = a.tags(tags: 'foo').first
#=> <Geotrigger::Tag ... >

tag.device_tagging = false
tag.trigger_list = false
tag.save

[](Esri Language: Ruby)

geotrigger-ruby's People

Contributors

kenichi avatar ajturner avatar jyaganeh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.