Created
September 26, 2014 20:46
-
-
Save mdobson/d2e19027b2de36ccc08f to your computer and use it in GitHub Desktop.
Conect a user to a device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>App Services HTML5 Template</title> | |
| <script src="../apigee.min.js"></script> | |
| </head> | |
| <body> | |
| <script> | |
| /* | |
| 1. Set your account details in the app | |
| - Enter your orgName below — it’s the username you picked when you signed up at apigee.com | |
| - Keep the appName as “sandbox”: it’s a context we automatically created for you. It’s completely open by default, but don’t worry, other apps you create are not! */ | |
| var client = new Apigee.Client({ | |
| orgName:'mdobson', | |
| appName:'sandbox' | |
| }); | |
| client.login('mdobs', 'Apigee10@', function(err, resp, user){ | |
| var opts = { | |
| uuid:'83491728-cb42-4210-ad10-31c7d59ad84a', | |
| type:'devices' | |
| }; | |
| client.getEntity(opts, function(error, resp, device){ | |
| //Returns uuid <Not intended> | |
| //console.log('User:', user.getEntityId(user)); | |
| //Returns uuid <Intended> | |
| //console.log('Device:', user.getEntityId(device)); | |
| connectUserToDevice(user, device, function(err, response){ | |
| console.log(err, response); | |
| }); | |
| }); | |
| }); | |
| function connectUserToDevice(user, device, cb) { | |
| var endpoint = [user._data.type, user._data.username, 'devices', device._data.uuid].join('/'); | |
| console.log(endpoint); | |
| var opts = { | |
| method: 'POST', | |
| endpoint: endpoint | |
| } | |
| user._client.request(opts, function(err, response){ | |
| cb(err, response); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment