Skip to content

Commit

Permalink
Merge pull request #158 from cjsaylor/2.3
Browse files Browse the repository at this point in the history
WIP: 2.3
  • Loading branch information
cjsaylor committed Sep 13, 2013
2 parents a09040a + a78916f commit 716fd71
Show file tree
Hide file tree
Showing 53 changed files with 1,942 additions and 525 deletions.
2 changes: 2 additions & 0 deletions app/.htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
php_value newrelic.appname "Boxmeup"

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
Expand Down
18 changes: 16 additions & 2 deletions app/Config/routes.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

Router::parseExtensions();
Router::parseExtensions('json');
/**
* Static pages:
* /slug => template name
*/
$static_pages = array(
'' => 'home',
'terms' => 'terms',
'privacy' => 'privacy'
'privacy' => 'privacy',
'developer' => 'developer'
);
foreach($static_pages as $slug => $page) {
Router::connect('/'.$slug, array('controller' => 'pages', 'action' => 'display', $page));
Expand All @@ -23,6 +24,19 @@
// Application
Router::connect('/dashboard', array('controller' => 'containers', 'action' => 'dashboard'));

// API
Router::connect('/api/containers/search/*', array('plugin' => 'api', 'controller' => 'containers', 'action' => 'search'));
Router::connect('/api/users/login', array('plugin' => 'api', 'controller' => 'users', 'action' => 'login', '[method]' => 'POST'));
// API Mapped resources
Router::mapResources(array(
'Api.containers',
'Api.container_items'
), array(
'id' => '[a-z0-9-]+'
));
// API Catchall
Router::connect('/api/*', array('plugin' => 'api'));

// Fallback
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

Expand Down
20 changes: 18 additions & 2 deletions app/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public function logout() {
}

public function account() {
Configure::write('Feature.adsense', false);
$this->layout = 'app';
if(!empty($this->request->data)) {
$this->request->data['User']['id'] = $this->Auth->user('id');
Expand All @@ -121,6 +120,23 @@ public function account() {
$secret_key = ClassRegistry::init('Api.ApiUser')->getSecretKey($api_key);
$this->set(compact('api_key', 'secret_key'));
}

public function auth() {
$this->layout = 'app';
$userApplication = ClassRegistry::init('Api.ApiUserApplication');
$this->set('applications', $userApplication->getAllAuthenticatedApps($this->Auth->user('id')));
}

public function revoke($id) {
$this->layout = 'app';
$userApplication = ClassRegistry::init('Api.ApiUserApplication');
if ($userApplication->revokeTokenById($id, $this->Auth->user('id'))) {
$this->Session->setFlash(__('Successfully revoked token.'), 'notification/success');
} else {
$this->Session->setFlash(__('Error revoking token.'), 'notification/error');
}
$this->redirect(array('action' => 'auth'));
}

public function forgot_password() {
if(!empty($this->request->data)) {
Expand Down Expand Up @@ -185,4 +201,4 @@ public function change_language($language = null) {
}
$this->redirect($this->referer());
}
}
}
6 changes: 3 additions & 3 deletions app/Model/Behavior/SphinxBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SphinxBehavior extends ModelBehavior
*/
var $sphinx = null;

function setup(&$model, $config = array())
function setup(Model $model, $config = array())
{
$settings = array_merge($this->_defaults, (array) $config);

Expand All @@ -43,7 +43,7 @@ function setup(&$model, $config = array())
* @return array Modified query
* @access public
*/
function beforeFind(&$model, $query)
function beforeFind(Model $model, $query)
{
if (empty($query['sphinx']) || empty($query['search']))
return true;
Expand Down Expand Up @@ -135,4 +135,4 @@ function beforeFind(&$model, $query)
return $query;
}
}
?>
?>
8 changes: 6 additions & 2 deletions app/Model/ContainerItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ public function searchContainers(&$controller, $user_id, $query) {
// API Methods
public function getApiContainerItems($user_id, $conditions = array()) {
$conditions = array_merge(array('user_id' => $user_id), $conditions);
return $this->find('all', array(
$data = $this->find('all', array(
'fields' => array('uuid', 'body', 'quantity', 'created', 'modified'),
'conditions' => $conditions,
'limit' => 150
));
foreach ($data as &$datum) {
$datum['ContainerItem']['quantity'] = (int)$datum['ContainerItem']['quantity'];
}
return $data;
}
}
}
24 changes: 0 additions & 24 deletions app/Plugin/Api/Config/Schema/schema.php

This file was deleted.

8 changes: 0 additions & 8 deletions app/Plugin/Api/Config/routes.php

This file was deleted.

230 changes: 230 additions & 0 deletions app/Plugin/Api/Config/service_description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
{
"name": "BoxmeupAPI",
"apiVersion": "2013-08-11",
"baseUrl": "https://boxmeupapp.com/api",
"description": "BoxmeupAPI allows for programatic manipulation of containers, items, and locations",
"operations": {
"Login": {
"httpMethod": "POST",
"uri": "/users/login",
"summary": "Authenticate a user and retrieve an OAuth access token.",
"responseClass": "LoginOutput",
"parameters": {
"email": {
"location": "postField",
"description": "Email of the account.",
"type": "string",
"required": true
},
"password": {
"location": "postField",
"description": "Password of the account.",
"type": "string",
"required": true
},
"application": {
"location": "postField",
"description": "Application name to register this OAuth request.",
"type": "string",
"required": true
}
}
},
"GetContainers": {
"httpMethod": "GET",
"uri": "/containers",
"summary": "Get a list of containers.",
"responseClass": "ContainerListOutput",
"parameters": {
"slug": {
"location": "query",
"description": "Filter by container slug.",
"type": "string",
"required": false
}
}
},
"AddContainer": {
"httpMethod": "POST",
"uri": "/containers",
"summary": "Adds a new container.",
"responseClass": "ContainerShortOutput",
"parameters": {
"name": {
"location": "postField",
"description": "Name of the container",
"type": "string",
"required": true
}
}
},
"UpdateContainer": {
"httpMethod": "PUT",
"uri": "/containers/:slug",
"summary": "Updates an existing container.",
"responseClass": "ContainerLongOutput",
"parameters": {
"slug": {
"location": "uri",
"description": "Container slug.",
"type": "string",
"required": true
},
"name": {
"location": "postField",
"description": "Name of the container",
"type": "string",
"required": true
}
}
},
"RemoveContainer": {
"httpMethod": "DELETE",
"uri": "/containers/:slug",
"summary": "Adds a new container.",
"responseClass": "SuccessOutput",
"parameters": {
"slug": {
"location": "uri",
"description": "Container slug.",
"type": "string",
"required": true
}
}
}
},
"models": {
"LoginOutput": {
"type": "object",
"properties": {
"token": {
"location": "json",
"type": "string"
}
}
},
"ContainerListOutput": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Container": {
"location": "json",
"type": "object",
"properties": {
"name": {
"location": "json",
"type": "string"
},
"uuid": {
"location": "json",
"type": "string"
},
"slug": {
"location": "json",
"type": "string"
},
"container_item_count": {
"location": "json",
"type": "integer"
},
"created": {
"location": "json",
"type": "string"
},
"modified": {
"location": "json",
"type": "string"
}
}
},
"Location": {
"location": "json",
"type": "object",
"properties": {
"name": {
"location": "json",
"type": "string"
},
"uuid": {
"location": "json",
"type": "string"
}
}
}
}
}
},
"ContainerShortOutput": {
"type": "object",
"properties": {
"uuid": {
"location": "json",
"type": "string"
},
"slug": {
"location": "json",
"type": "string"
}
}
},
"ContainerLongOutput": {
"type": "object",
"properties": {
"Container": {
"location": "json",
"type": "object",
"properties": {
"name": {
"location": "json",
"type": "string"
},
"uuid": {
"location": "json",
"type": "string"
},
"slug": {
"location": "json",
"type": "string"
},
"container_item_count": {
"location": "json",
"type": "integer"
},
"created": {
"location": "json",
"type": "string"
},
"modified": {
"location": "json",
"type": "string"
}
}
},
"Location": {
"location": "json",
"type": "object",
"properties": {
"name": {
"location": "json",
"type": "string"
},
"uuid": {
"location": "json",
"type": "string"
}
}
}
}
},
"SuccessOutput": {
"type": "object",
"properties": {
"success": {
"location": "json",
"type": "boolean"
}
}
}
}
}
Loading

0 comments on commit 716fd71

Please sign in to comment.