Class: Esriveter
- Inherits:
-
Object
- Object
- Esriveter
- Defined in:
- lib/esriveter.rb
Constant Summary collapse
- ACCESS_TOKEN_KEY =
'access_token'- EXPIRES_KEY =
'expires_in'- DEVICE_KEY =
'device'- DEVICE_TOKEN_KEY =
'deviceToken'- DEVICE_ID_KEY =
'deviceId'- REFRESH_TOKEN_KEY =
'refresh_token'
Instance Attribute Summary collapse
-
#app_token ⇒ Object
Returns the value of attribute app_token.
-
#app_token_expiry ⇒ Object
Returns the value of attribute app_token_expiry.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#device_id ⇒ Object
Returns the value of attribute device_id.
-
#device_token ⇒ Object
Returns the value of attribute device_token.
-
#device_token_expiry ⇒ Object
Returns the value of attribute device_token_expiry.
-
#force ⇒ Object
Returns the value of attribute force.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #create_app(username, password, title = "Random Name #{Random.rand(11)}") ⇒ Object
- #get_app_token ⇒ Object
- #get_device_token ⇒ Object
-
#initialize(opts = {}) ⇒ Esriveter
constructor
A new instance of Esriveter.
Constructor Details
#initialize(opts = {}) ⇒ Esriveter
Returns a new instance of Esriveter.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/esriveter.rb', line 15 def initialize(opts={}) set_variables opts @server = self.default_server if not @server @client = Faraday.new do |faraday| faraday.use Faraday::Request::UrlEncoded faraday.use Faraday::Response::Logger if @debug faraday.adapter :net_http end self end |
Instance Attribute Details
#app_token ⇒ Object
Returns the value of attribute app_token.
4 5 6 |
# File 'lib/esriveter.rb', line 4 def app_token @app_token end |
#app_token_expiry ⇒ Object
Returns the value of attribute app_token_expiry.
4 5 6 |
# File 'lib/esriveter.rb', line 4 def app_token_expiry @app_token_expiry end |
#client_id ⇒ Object
Returns the value of attribute client_id.
5 6 7 |
# File 'lib/esriveter.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
5 6 7 |
# File 'lib/esriveter.rb', line 5 def client_secret @client_secret end |
#debug ⇒ Object
Returns the value of attribute debug.
6 7 8 |
# File 'lib/esriveter.rb', line 6 def debug @debug end |
#device_id ⇒ Object
Returns the value of attribute device_id.
3 4 5 |
# File 'lib/esriveter.rb', line 3 def device_id @device_id end |
#device_token ⇒ Object
Returns the value of attribute device_token.
3 4 5 |
# File 'lib/esriveter.rb', line 3 def device_token @device_token end |
#device_token_expiry ⇒ Object
Returns the value of attribute device_token_expiry.
3 4 5 |
# File 'lib/esriveter.rb', line 3 def device_token_expiry @device_token_expiry end |
#force ⇒ Object
Returns the value of attribute force.
6 7 8 |
# File 'lib/esriveter.rb', line 6 def force @force end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
3 4 5 |
# File 'lib/esriveter.rb', line 3 def refresh_token @refresh_token end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/esriveter.rb', line 6 def server @server end |
Instance Method Details
#create_app(username, password, title = "Random Name #{Random.rand(11)}") ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/esriveter.rb', line 48 def create_app username, password, title="Random Name #{Random.rand(11)}" action = Proc.new { |uri, params| puts params.inspect if @debug self.generic_request uri, params } # Generate Token params = { 'username' => username, 'password' => password, 'expiration' => self.desired_expiration, 'referer' => 'arcgis.com' } uri = "/rest/generateToken" tresponse = action.call(uri, params) # Add Item params = { 'token' => tresponse['token'], 'type' => 'Application', 'title' => title } uri = "/rest/content/users/#{username}/addItem" iresponse = action.call(uri, params) # Create Application params = { 'itemId' => iresponse['id'], 'appType' => 'multiple', 'redirect_uris' => '[]', 'token' => tresponse['token'] } uri = "/oauth2/registerApp" aresponse = action.call(uri, params) aresponse end |
#get_app_token ⇒ Object
27 28 29 30 31 32 |
# File 'lib/esriveter.rb', line 27 def get_app_token if not @app_token_expiry or (not @app_token or @force or @app_token_expiry < Time.now) self.create_app_token end {app_token: @app_token, app_token_expiry: @app_token_expiry} end |
#get_device_token ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/esriveter.rb', line 34 def get_device_token if not @device_token_expiry or (not @device_token or @force or @device_token_expiry < Time.now) dresponse = self.create_device_token if dresponse.size == 2 {device_token: @device_token, device_token_expiry: @device_token_expiry} else {device_token: @device_token, device_token_expiry: @device_token_expiry, refresh_token: @refresh_token, device_id: @device_id} end else {device_token: @device_token, device_token_expiry: @device_token_expiry} end end |