class Geotrigger::AGO::Session
AGO::Session
is responsible for talking to the ArcGIS Online API.
-
retrieves a valid OAuth
access_token
, handling expiration-
Application
, viaclient_credentials
-
Device
, via registration orrefresh_token
-
-
registers a new
Device
given aclient_id
Generally, one interacts with only the Session
, which retains an instance of this to deal with tokens.
Constants
- AGO_BASE_URL
Read the base URL for ArcGIS Online API from the environment, or use the default.
If you have a different OAuth portal, you can:
$ AGO_BASE_URL=http://example.com/path/ irb -rgeotrigger
to have the client use that base URL.
Public Class Methods
Determines underlying implementation type, and creates an HTTPClient
instance.
- opts
-
Hash
options for construction: - :client_id
-
String
OAuth client id - :client_secret
-
String
OAuth client secret - :refresh_token
-
String
OAuth refresh token - :type
-
Symbol
:application
(default) or:device
# File lib/geotrigger/ago/session.rb, line 44 def initialize opts = {} @hc = HTTPClient.new @impl = case opts[:type] || :application when :application Application.new self, opts when :device Device.new self, opts else raise ArgumentError 'unknown type' end self.access_token = opts[:access_token] if opts[:access_token] end
Public Instance Methods
HTTP the specified method to the specified path with the given params. JSON parse the response body or raise errors.
- meth
-
Symbol
of the method to HTTP (:get,:post…) - path
-
String
path of the request (‘/example/index.html’) - params
-
Hash
parameters for the request
# File lib/geotrigger/ago/session.rb, line 75 def hc meth, path, params r = @hc.__send__ meth, AGO_BASE_URL % path, params.merge(f: 'json') raise AGOError.new r.body unless r.status == 200 h = JSON.parse r.body raise AGOError.new r.body if h['error'] h end
Type of implementation as a symbol.
# File lib/geotrigger/ago/session.rb, line 59 def type case @impl when Application :application when Device :device end end