Activities API docs

James Peret 9 years ago
parent
commit
086f8db673

+ 3 - 2
Gruntfile.js

@@ -77,11 +77,12 @@ module.exports = function (grunt) {
77 77
         port: 9000,
78 78
         // Change this to '0.0.0.0' to access the server from outside.
79 79
         hostname: 'localhost',
80
-        livereload: 35729
80
+        livereload: 35729,
81
+        open: false
81 82
       },
82 83
       livereload: {
83 84
         options: {
84
-          open: true,
85
+          open: false,
85 86
           middleware: function (connect) {
86 87
             return [
87 88
               modRewrite(['^[^\\.]*$ /index.html [L]']),

+ 45 - 3
app/data/page-list.json

@@ -146,6 +146,48 @@
146 146
         }
147 147
       },
148 148
       {
149
+        "pageUrl" : "/rest-api-v1/get-mission-activities",
150
+        "slug"  : "get-mission-activities",
151
+        "title" : "Mission Activities",
152
+        "endpoint" : {
153
+          "type"    : "GET",
154
+          "base"    : "/missions/:slug/activities",
155
+          "object1" : "/missions/",
156
+          "id1"     : "slug",
157
+          "object2" : "/activities"
158
+        },
159
+        "implemented" : true,
160
+        "description" : "Returns a list of activities that happened on the mission. Activities include all messages sent, mission details edits, new agents and task related activities.",
161
+        "variables" : [
162
+          {
163
+            "name" : "slug",
164
+            "description" : "A shortname without spaces used as the mission identifier and url. This needs to be unique.",
165
+            "variable_type" : "string"
166
+          }
167
+        ]
168
+      },
169
+      {
170
+        "pageUrl" : "/rest-api-v1/get-activity",
171
+        "slug"  : "get-activity",
172
+        "title" : "Find Activity",
173
+        "endpoint" : {
174
+          "type"    : "GET",
175
+          "base"    : "/activities/:id",
176
+          "object1" : "/activities/",
177
+          "id1"     : "id",
178
+          "object2" : ""
179
+        },
180
+        "implemented" : true,
181
+        "description" : "Search for a specific activity by its ID.",
182
+        "variables" : [
183
+          {
184
+            "name" : "id",
185
+            "description" : "Unique ID number of the activity",
186
+            "variable_type" : "string"
187
+          }
188
+        ]
189
+      },
190
+      {
149 191
         "pageUrl" : "/rest-api-v1/get-mission-messages",
150 192
         "slug"  : "get-mission-messages",
151 193
         "title" : "Mission Messages",
@@ -167,12 +209,12 @@
167 209
         ]
168 210
       },
169 211
       {
170
-        "pageUrl" : "/rest-api-v1/post-mission-message",
171
-        "slug"  : "post-mission-message",
212
+        "pageUrl" : "/rest-api-v1/post-mission-messages",
213
+        "slug"  : "post-mission-messages",
172 214
         "title" : "Send Message",
173 215
         "endpoint" : {
174 216
           "type"    : "POST",
175
-          "base"    : "/missions/:slug/message/",
217
+          "base"    : "/missions/:slug/messages/",
176 218
           "object1" : "/missions/",
177 219
           "id1"     : "slug",
178 220
           "object2" : "/messages"

+ 1 - 1
app/scripts/controllers/getting-started-ctrl.js

@@ -10,7 +10,7 @@
10 10
 angular.module('avalancheDocsApp')
11 11
   .controller('GettingStartedCtrl', ['$scope', '$cookies', '$sanitize', 'OAuthService', '$location', function ($scope, $cookies, $sanitize, OAuthService, $location) {
12 12
 
13
-    OAuthService.lookForAuthCode();
13
+    OAuthService.lookForApplicationAuthCode();
14 14
 
15 15
     var before_login_page = $cookies.get('avalanche_docs_before_login_page');
16 16
     if(before_login_page != undefined) {

+ 11 - 8
app/scripts/controllers/realtime-api-v1-ctrl.js

@@ -32,13 +32,9 @@ angular.module('avalancheDocsApp')
32 32
         return viewLocation === $location.path();
33 33
     };
34 34
 
35
-    $scope.token = $cookies.get('avalanche-docs-token');
36
-    if($scope.token == undefined) {
37
-      $scope.token = "none";
38
-      $scope.hideToken = true;
39
-    }
40 35
 
41
-    $scope.authorizeUser = function(){
36
+
37
+    $scope.authorizeApplication = function(){
42 38
       console.log($location.url());
43 39
       $cookies.put('avalanche_docs_before_login_page', $location.url());
44 40
       $window.location.href = 'http://localhost:5000/oauth/authorize?client_id=d514f58c234d69ce1405f00dbef842bd785c09201b35a746d87306f5e69fd02b&redirect_uri=http://localhost:9000/&response_type=code';
@@ -53,8 +49,15 @@ angular.module('avalancheDocsApp')
53 49
     $scope.tokens.selectedToken = $scope.tokens.availableOptions[0];
54 50
     $scope.data = {}
55 51
     if(OAuthService.getToken() != "" && OAuthService.getToken() != undefined){
56
-      $scope.tokens.availableOptions[1] = OAuthService.getToken();
57
-      $scope.tokens.selectedToken = $scope.tokens.availableOptions[1];
52
+      if(!$scope.$$phase) {
53
+        $scope.$apply(function(){
54
+          $scope.tokens.availableOptions[1] = OAuthService.getToken();
55
+          $scope.tokens.selectedToken = $scope.tokens.availableOptions[1];
56
+        });
57
+      } else {
58
+        $scope.tokens.availableOptions[1] = OAuthService.getToken();
59
+        $scope.tokens.selectedToken = $scope.tokens.availableOptions[1];
60
+      }
58 61
     }
59 62
     DataService.getResponse()
60 63
 

+ 13 - 11
app/scripts/controllers/rest-api-v1-ctrl.js

@@ -32,23 +32,25 @@ angular.module('avalancheDocsApp')
32 32
         return viewLocation === $location.path();
33 33
     };
34 34
 
35
-    $scope.token = $cookies.get('avalanche-docs-token');
36
-    if($scope.token == undefined) {
37
-      $scope.token = "none";
38
-      $scope.hideToken = true;
39
-    }
40 35
 
41
-    $scope.authorizeUser = function(){
36
+
37
+    $scope.authorizeApplication = function(){
42 38
       console.log($location.url());
43 39
       $cookies.put('avalanche_docs_before_login_page', $location.url());
44 40
       $window.location.href = 'http://localhost:5000/oauth/authorize?client_id=d514f58c234d69ce1405f00dbef842bd785c09201b35a746d87306f5e69fd02b&redirect_uri=http://localhost:9000/&response_type=code';
45 41
     }
46 42
 
43
+    $scope.authorizeUser = function(){
44
+      console.log("Authorizing user...");
45
+      OAuthService.authorizeUser($scope.login.email, $scope.login.password);
46
+    }
47
+
47 48
 
48 49
     // Initialize
49 50
     $scope.response = {};
50 51
     $scope.hideResult = true;
51 52
     $scope.tokens = { availableOptions : [], selectedOption: []};
53
+    $scope.login = { email : "", password: ""};
52 54
     $scope.tokens.availableOptions[0] = 'none';
53 55
     $scope.tokens.selectedToken = $scope.tokens.availableOptions[0];
54 56
     $scope.data = {}
@@ -67,7 +69,7 @@ angular.module('avalancheDocsApp')
67 69
     $scope.postData = function(endpoint){
68 70
       var url = $scope.fullURL(endpoint);
69 71
       usSpinnerService.spin('spinner-1');
70
-      DataService.post(url, $scope.processInputs(), $scope.data, $scope.tokens.selectedToken);
72
+      DataService.post(url, $scope.processInputs(), $scope.tokens.selectedToken);
71 73
     }
72 74
 
73 75
     $scope.processInputs = function(){
@@ -101,12 +103,12 @@ angular.module('avalancheDocsApp')
101 103
     $rootScope.$on('auth:success', function() {
102 104
       if(!$scope.$$phase) {
103 105
         $scope.$apply(function(){
104
-          $scope.token[1] = OAuthService.getToken();
105
-          $scope.selectedToken = $scope.tokens.availableOptions[1];
106
+          $scope.tokens.availableOptions[1] = OAuthService.getToken();
107
+          $scope.tokens.selectedToken = $scope.tokens.availableOptions[1];
106 108
         });
107 109
       } else {
108
-          $scope.token[1] = OAuthService.getToken();
109
-          $scope.selectedToken = $scope.tokens.availableOptions[1];
110
+        $scope.tokens.availableOptions[1] = OAuthService.getToken();
111
+        $scope.tokens.selectedToken = $scope.tokens.availableOptions[1];
110 112
       }
111 113
     });
112 114
 

+ 2 - 0
app/scripts/services/data-service.js

@@ -6,6 +6,7 @@ angular.module('avalancheDocsApp')
6 6
   this.get = function(url, inputs, token){
7 7
     console.log("Requesting data from " + url);
8 8
     console.log(inputs);
9
+    console.log(token);
9 10
     $http({
10 11
       method: 'GET',
11 12
       url: url,
@@ -35,6 +36,7 @@ angular.module('avalancheDocsApp')
35 36
   this.post = function(url, inputs, token){
36 37
     console.log("Posting data to " + url);
37 38
     console.log(inputs);
39
+    console.log(token);
38 40
     $http({
39 41
       method: 'POST',
40 42
       url: url,

+ 31 - 7
app/scripts/services/oauth-service.js

@@ -1,31 +1,55 @@
1 1
 angular.module('avalancheDocsApp')
2 2
 .service('OAuthService', [ '$rootScope', '$http', '$location', '$routeParams', '$cookies',  function($rootScope, $http, $location, $routeParams, $cookies) {
3 3
   var code = {};
4
-  var token = $cookies.get('avalanche_docs_token');;
5
-  this.lookForAuthCode = function(){
4
+  var token = $cookies.get('avalanche_docs_token');
5
+
6
+  this.lookForApplicationAuthCode = function(){
6 7
     code = $location.search().code;
7 8
     if(code != undefined) {
8 9
       console.log(code);
9 10
       // Reset URL
10 11
       $location.search("code", null);
11 12
       $routeParams= null;
12
-      this.authorize(code);
13
+      this.authorizeApplication(code);
13 14
     }
14 15
   }
15 16
 
16
-  this.authorize = function(code){
17
+  this.authorizeApplication = function(code){
17 18
     $http({
18 19
       method: 'POST',
19 20
       url: 'http://localhost:5000/oauth/token?client_id=d514f58c234d69ce1405f00dbef842bd785c09201b35a746d87306f5e69fd02b&client_secret=de63eb190485179d713df3e15339eb618e78e94ab96185621112dd0e5215997c&grant_type=authorization_code&redirect_uri=http://localhost:9000/&code=' + code
20 21
     }).then(function(data) {
21 22
       token = data.data.access_token;
22
-      console.log("Token Authentication SUCCESSFULL")
23
-      console.log(token);
24 23
       $cookies.put('avalanche_docs_token', token);
24
+      console.log("Application Authorization Flow SUCCESSFULL")
25
+      console.log(data.data);
26
+      $rootScope.$broadcast('auth:success');
27
+    },
28
+    function(data) {
29
+      console.log("Application Authorization Flow FAILED")
30
+      console.log(data);
31
+      $rootScope.$broadcast('auth:failed');
32
+    });
33
+  }
34
+
35
+  this.authorizeUser = function(username, password){
36
+    $http({
37
+      method: 'POST',
38
+      url: 'http://localhost:5000/oauth/token',
39
+      params: {
40
+        "grant_type"    : "password",
41
+        "username"      : username,
42
+        "password"      : password
43
+      }
44
+    }).then(function(data) {
45
+      token = data.data.access_token;
46
+      $cookies.put('avalanche_docs_token', token);
47
+      console.log("Resource Owner Password Credentials flow SUCCESSFULL")
48
+      console.log(data.data);
25 49
       $rootScope.$broadcast('auth:success');
26 50
     },
27 51
     function(data) {
28
-      console.log("Token Authentication FAILED")
52
+      console.log("Resource Owner Password Credentials flow FAILED")
29 53
       console.log(data);
30 54
       $rootScope.$broadcast('auth:failed');
31 55
     });

+ 1 - 1
app/styles/avalanche_theme/docs.scss

@@ -122,7 +122,7 @@
122 122
 
123 123
 // Hacks
124 124
 
125
-.api-endpoint > .label { margin-right: 6px;}
125
+.api-endpoint .label { margin-right: 6px; padding-top: 3px; }
126 126
 
127 127
 ::-webkit-scrollbar {
128 128
     width: 4px;

+ 40 - 1
app/views/helpers/api-token-field.html

@@ -7,7 +7,46 @@
7 7
     </div>
8 8
     <div class="col-sm-3">
9 9
       <br>
10
-      <a ng-click="authorizeUser()" class="btn btn-secondary-outline btn-sm" role="button" style="margin-top:10px;">Get Token</a>
10
+      <div class="dropdown" style="margin-top:10px;">
11
+        <button class="btn btn-secondary dropdown-toggle btn btn-secondary-outline btn-sm" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
12
+          Get Token
13
+        </button>
14
+        <div class="dropdown-menu" aria-labelledby="dropdownMenu1" style="font-size: 0.9rem; ">
15
+          <button type="button" class="dropdown-item" data-toggle="modal" data-target="#myModal">User Auth</button>
16
+          <a ng-click="authorizeApplication()" class="dropdown-item" role="button" style="margin-top:10px;">Application Auth</a>
17
+        </div>
18
+      </div>
11 19
     </div>
12 20
   </div>
13 21
 </fieldset>
22
+
23
+<!-- Modal -->
24
+<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
25
+  <div class="modal-dialog modal-sm" role="document">
26
+    <div class="modal-content">
27
+      <div class="modal-header">
28
+        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
29
+          <span aria-hidden="true">&times;</span>
30
+          <span class="sr-only">Close</span>
31
+        </button>
32
+        <h4 class="modal-title" id="myModalLabel">Avalanche Login</h4>
33
+      </div>
34
+      <div class="modal-body">
35
+        <form>
36
+          <fieldset class="form-group">
37
+            <label for="email">Email</label>
38
+            <input type="text" class="form-control" id="email" placeholder="" ng-model="login.email" autofocus>
39
+          </fieldset>
40
+          <fieldset class="form-group">
41
+            <label for="password">Password</label>
42
+            <input type="password" class="form-control" id="password" placeholder="" ng-model="login.password">
43
+          </fieldset>
44
+        </form>
45
+      </div>
46
+      <div class="modal-footer">
47
+        <button type="button" class="btn btn-success btn-sm" data-dismiss="modal">Close</button>
48
+        <button type="submit" class="btn btn-primary btn-sm" data-dismiss="modal" ng-click="authorizeUser()">Authorize</button>
49
+      </div>
50
+    </div>
51
+  </div>
52
+</div>

+ 5 - 6
app/views/rest-api-v1.html

@@ -5,11 +5,10 @@
5 5
       <ul class="nav nav-sidebar">
6 6
         <li ng-repeat="page in pageList" ng-class="{ active: isActive(page.pageUrl)}">
7 7
           <a ui-sref="rest-api-v1({ id: page.slug })">
8
-            <small ng-hide="page.type == 'page'" class="api-endpoint">
9
-              <span ng-class="callTypeBadge(page.endpoint.type)">{{page.endpoint.type}}</span><samp>{{page.endpoint.base}}</samp>
10
-            </small>
11
-            <p  ng-hide="page.type == 'page'" class="endpoint-description"><i>{{page.title}}</i></p>
12
-            <h5 ng-show="page.type == 'page'">{{page.title}}</h5>
8
+            <b>{{page.title}}</b><br>
9
+            <p ng-hide="page.type == 'page'" class="api-endpoint">
10
+              <small><span ng-class="callTypeBadge(page.endpoint.type)" >{{page.endpoint.type}}</span><samp>{{page.endpoint.base}}</samp></small>
11
+            </p>
13 12
             <p  ng-show="page.type == 'page'" style="margin-bottom: 10px;"><i>{{page.tagline}}</i></p>
14 13
           </a>
15 14
         </li>
@@ -19,7 +18,7 @@
19 18
     <div class="col-sm-5 col-sm-offset-7 col-md-7 col-md-offset-5 main">
20 19
       <div class="api-endpoint" ng-hide="pageData.type == 'page'">
21 20
         <h2 style="margin-bottom: 0px;">{{pageData.title}}</h2>
22
-        <small class="api-endpoint"><span ng-class="callTypeBadge(pageData.endpoint.type)">{{pageData.endpoint.type}}</span> {{pageData.endpoint.base}}</small>
21
+        <small class="api-endpoint"><span ng-class="callTypeBadge(pageData.endpoint.type)">{{pageData.endpoint.type}}</span> <samp>{{pageData.endpoint.base}}</samp></small>
23 22
         <hr>
24 23
 
25 24
         <div ng-if="pageData.description != undefined">