Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit for web2project api. Including a GET for project

  • Loading branch information...
commit df95e9537b944a57a21a0a5e9a47df47538b0a6a 0 parents
Trevor Morse authored
1  .gitignore
@@ -0,0 +1 @@
+.idea
0  Action/.gitignore
No changes.
186 Action/Project.php
@@ -0,0 +1,186 @@
+<?php
+
+/**
+ * Action Project
+ *
+ * Handles request for projects.
+ *
+ * @link http://getfrapi.com
+ * @author Frapi <frapi@getfrapi.com>
+ * @link /project/:project_id
+ */
+class Action_Project extends Frapi_Action implements Frapi_Action_Interface
+{
+
+ /**
+ * Required parameters
+ *
+ * @var An array of required parameters.
+ */
+ protected $requiredParams = array(
+ 'username',
+ 'password'
+ );
+
+ /**
+ * The data container to use in toArray()
+ *
+ * @var A container of data to fill and return in toArray()
+ */
+ private $data = array();
+
+ /**
+ * To Array
+ *
+ * This method returns the value found in the database
+ * into an associative array.
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Default Call Method
+ *
+ * This method is called when no specific request handler has been found
+ *
+ * @return array
+ */
+ public function executeAction()
+ {
+ return $this->toArray();
+ }
+
+ /**
+ * Get Request Handler
+ *
+ * This method is called when a request is a GET
+ *
+ * @return array
+ */
+ public function executeGet()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ $username = $this->getParam('username', self::TYPE_STRING);
+ $password = $this->getParam('password', self::TYPE_STRING);
+ $project_id = $this->getParam('project_id', self::TYPE_INT);
+
+ if (!$project_id) {
+ throw new Frapi_Error('PARAM_ERROR', 'Missing Project ID', 500);
+ }
+
+ // Attempt to login as user, a little bit of a hack as we currently
+ // require the $_POST['login'] var to be set as well as a global AppUI
+ $AppUI = new CAppUI;
+ $GLOBALS['AppUI'] = $AppUI;
+ $_POST['login'] = 'login';
+
+ if (!$AppUI->login($username, $password)) {
+ throw new Frapi_Error('AUTH_ERROR', 'Invalid Username or Password', 401);
+ }
+
+ $project = new CProject();
+ $allowed_projects = $project->getAllowedProjects($AppUI->user_id);
+
+ // Project ID is the key, so lets get them in to an array so we can
+ // easily check
+ $allowed_projects = array_keys($allowed_projects);
+
+ if (!in_array($project_id, $allowed_projects)) {
+ throw new Frapi_Error('AUTH_ERROR', 'You do not have permission to view this project', 401);
+ }
+
+ // User has permission so load the project for display
+ $project->load($project_id);
+
+ $this->data['project_id'] = $project->project_id;
+ $this->data['project_company'] = $project->project_company;
+ $this->data['project_department'] = $project->project_department;
+ $this->data['project_name'] = $project->project_name;
+ $this->data['project_short_name'] = $project->project_short_name;
+ $this->data['project_owner'] = $project->project_owner;
+ $this->data['project_url'] = $project->project_url;
+ $this->data['project_demo_url'] = $project->project_demo_url;
+ $this->data['project_start_date'] = $project->project_start_date;
+ $this->data['project_end_date'] = $project->project_end_date;
+ $this->data['project_actual_end_date'] = $project->project_actual_end_date;
+ $this->data['project_status'] = $project->project_status;
+ $this->data['project_percent_complete'] = $project->project_percent_complete;
+ $this->data['project_color_identifier'] = $project->project_color_identifier;
+ $this->data['project_description'] = $project->project_description;
+ $this->data['project_target_budget'] = $project->project_target_budget;
+ $this->data['project_scheduled_hours'] = $project->project_scheduled_hours;
+ $this->data['project_worked_hours'] = $project->project_worked_hours;
+ $this->data['project_task_count'] = $project->project_task_count;
+ $this->data['project_creator'] = $project->project_creator;
+ $this->data['project_active'] = $project->project_active;
+ $this->data['project_private'] = $project->project_private;
+ $this->data['project_departments'] = $project->project_departments;
+ $this->data['project_contacts'] = $project->project_contacts;
+ $this->data['project_priority'] = $project->project_priority;
+ $this->data['project_type'] = $project->project_type;
+ $this->data['project_parent'] = $project->project_parent;
+ $this->data['project_original_parent'] = $project->project_original_parent;
+ $this->data['project_location'] = $project->project_location;
+
+ return $this->toArray();
+ }
+
+ /**
+ * Post Request Handler
+ *
+ * This method is called when a request is a POST
+ *
+ * @return array
+ */
+ public function executePost()
+ {
+ return $this->toArray();
+ }
+
+ /**
+ * Put Request Handler
+ *
+ * This method is called when a request is a PUT
+ *
+ * @return array
+ */
+ public function executePut()
+ {
+ return $this->toArray();
+ }
+
+ /**
+ * Delete Request Handler
+ *
+ * This method is called when a request is a DELETE
+ *
+ * @return array
+ */
+ public function executeDelete()
+ {
+ return $this->toArray();
+ }
+
+ /**
+ * Head Request Handler
+ *
+ * This method is called when a request is a HEAD
+ *
+ * @return array
+ */
+ public function executeHead()
+ {
+ return $this->toArray();
+ }
+
+
+}
+
160 Action/Testing1.php
@@ -0,0 +1,160 @@
+<?php
+
+/**
+ * Action Testing1
+ *
+ * Testing 1 edit2
+ *
+ * @link http://getfrapi.com
+ * @author Frapi <frapi@getfrapi.com>
+ * @link /testing/1
+ */
+class Action_Testing1 extends Frapi_Action implements Frapi_Action_Interface
+{
+
+ /**
+ * Required parameters
+ *
+ * @var An array of required parameters.
+ */
+ protected $requiredParams = array('bazinga');
+
+ /**
+ * The data container to use in toArray()
+ *
+ * @var A container of data to fill and return in toArray()
+ */
+ private $data = array();
+
+ /**
+ * To Array
+ *
+ * This method returns the value found in the database
+ * into an associative array.
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Default Call Method
+ *
+ * This method is called when no specific request handler has been found
+ *
+ * @return array
+ */
+ public function executeAction()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Get Request Handler
+ *
+ * This method is called when a request is a GET
+ *
+ * @return array
+ */
+ public function executeGet()
+ {
+ throw new Frapi_Error('ERROR_CODE', 'The error message to display', 405);
+ throw new Frapi_Error('Testing', 'Testing');
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ // Access your API like: http://api.frapi/testing/1.printr?bazinga=2.3david"><script>2
+ $this->data['bazinga-escaped'] = $this->getParam('bazinga', self::TYPE_OUTPUT);
+ $this->data['bazinga-plain'] = $this->getParam('bazinga', self::TYPE_STRING);
+ $this->data['bazinga-int'] = $this->getParam('bazinga', self::TYPE_INT);
+ $this->data['bazinga-float'] = $this->getParam('bazinga', self::TYPE_FLOAT);
+
+
+ return $this->toArray();
+ }
+
+ /**
+ * Post Request Handler
+ *
+ * This method is called when a request is a POST
+ *
+ * @return array
+ */
+ public function executePost()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ throw new Frapi_Error('TestingPost', 'POST Error');
+ // This instantiates an ArmChair object to access CouchDB. If you need
+ // something more advanced well... use something else, it's not forbidden.
+ // $chair = new ArmChair('http://localhost:5984/databasenamehere');
+
+ return $this->toArray();
+ }
+
+ /**
+ * Put Request Handler
+ *
+ * This method is called when a request is a PUT
+ *
+ * @return array
+ */
+ public function executePut()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Delete Request Handler
+ *
+ * This method is called when a request is a DELETE
+ *
+ * @return array
+ */
+ public function executeDelete()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Head Request Handler
+ *
+ * This method is called when a request is a HEAD
+ *
+ * @return array
+ */
+ public function executeHead()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+
+}
+
145 Action/Testing2.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * Action Testing2
+ *
+ * Testing 2
+ *
+ * @link http://getfrapi.com
+ * @author Frapi <frapi@getfrapi.com>
+ * @link /testing/2
+ */
+class Action_Testing2 extends Frapi_Action implements Frapi_Action_Interface
+{
+
+ /**
+ * Required parameters
+ *
+ * @var An array of required parameters.
+ */
+ protected $requiredParams = array('name');
+
+ /**
+ * The data container to use in toArray()
+ *
+ * @var A container of data to fill and return in toArray()
+ */
+ private $data = array();
+
+ /**
+ * To Array
+ *
+ * This method returns the value found in the database
+ * into an associative array.
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ $this->data['name'] = $this->getParam('name', self::TYPE_OUTPUT);
+ return $this->data;
+ }
+
+ /**
+ * Default Call Method
+ *
+ * This method is called when no specific request handler has been found
+ *
+ * @return array
+ */
+ public function executeAction()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Get Request Handler
+ *
+ * This method is called when a request is a GET
+ *
+ * @return array
+ */
+ public function executeGet()
+ {
+ $this->data['name'] = 'david';
+
+ $this->setTemplateFileName('CustomTesting2');
+ return $this->toArray();
+ }
+
+ /**
+ * Post Request Handler
+ *
+ * This method is called when a request is a POST
+ *
+ * @return array
+ */
+ public function executePost()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Put Request Handler
+ *
+ * This method is called when a request is a PUT
+ *
+ * @return array
+ */
+ public function executePut()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Delete Request Handler
+ *
+ * This method is called when a request is a DELETE
+ *
+ * @return array
+ */
+ public function executeDelete()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+ /**
+ * Head Request Handler
+ *
+ * This method is called when a request is a HEAD
+ *
+ * @return array
+ */
+ public function executeHead()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ return $this->toArray();
+ }
+
+
+}
+
18 AllFiles.php
@@ -0,0 +1,18 @@
+<?php
+
+// Use the constant CUSTOM_MODEL to access the custom model directory
+// IE: require CUSTOM_MODEL . DIRECTORY_SEPARATOR . 'ModelName.php';
+// Or add an autolaoder if you are brave.
+
+// Frapi comes with Armchair by default. You can use it or decide to remove it.
+// You can find armchair at: git://github.com/till/armchair.git
+require CUSTOM_MODEL . DIRECTORY_SEPARATOR . 'ArmChair' . DIRECTORY_SEPARATOR . 'ArmChair.php';
+
+// Change this to define where you have web2project installed
+define('W2P_INSTALL_DIR', '/var/www/html/web2project');
+
+// Bootstrap w2p
+require W2P_INSTALL_DIR . DIRECTORY_SEPARATOR . 'base.php';
+require_once W2P_BASE_DIR . '/includes/config.php';
+require_once W2P_BASE_DIR . '/includes/main_functions.php';
+require_once W2P_BASE_DIR . '/includes/db_adodb.php';
50 Config/actions.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <actions>
+ <action>
+ <name>Testing1</name>
+ <enabled>1</enabled>
+ <public>1</public>
+ <description>Testing 1 and editing from the new configuration location.</description>
+ <route>/testing/1</route>
+ <hash>6f1e8805cc0451de243b0432b15feb48f33383f9</hash>
+ <parameters>
+ <parameter>
+ <name>bazinga</name>
+ <required>1</required>
+ </parameter>
+ </parameters>
+ </action>
+ <action>
+ <name>Testing2</name>
+ <enabled>1</enabled>
+ <public>1</public>
+ <route>/testing/2</route>
+ <hash>500286218fe54ed4b7e8a8ce58ea4d947fb4f658</hash>
+ <parameters>
+ <parameter>
+ <name>name</name>
+ <required>1</required>
+ </parameter>
+ </parameters>
+ </action>
+ <action>
+ <name>Project</name>
+ <enabled>1</enabled>
+ <public>1</public>
+ <description>Handles request for projects.</description>
+ <route>/project/:project_id</route>
+ <hash>2a0129dd954d604c7036faf5302f5b05ee0615c4</hash>
+ <parameters>
+ <parameter>
+ <name>username</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>password</name>
+ <required>1</required>
+ </parameter>
+ </parameters>
+ </action>
+ </actions>
+</frapi-config>
29 Config/configurations.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <configurations>
+ <configuration>
+ <key>db_hostname</key>
+ <value>localhost</value>
+ </configuration>
+ <configuration>
+ <key>db_username</key>
+ <value>root</value>
+ </configuration>
+ <configuration>
+ <key>db_password</key>
+ <value>password</value>
+ </configuration>
+ <configuration>
+ <key>db_database</key>
+ <value>test</value>
+ </configuration>
+ <configuration>
+ <key>api_url</key>
+ <value>api.frapi</value>
+ </configuration>
+ <configuration>
+ <key>cache</key>
+ <value>apc</value>
+ </configuration>
+ </configurations>
+</frapi-config>
19 Config/errors.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <errors>
+ <error>
+ <name>ERROR_EXAMPLE</name>
+ <message>This is an example error.</message>
+ <http_code>405</http_code>
+ <description>This error is used as an example for both the API and the automatically generated documentation which can be found at admin.frapi/docs/generate/format/md</description>
+ <hash>e06f885297d44a9faf5703252c638b3dcdec6986</hash>
+ </error>
+ <error>
+ <name>TEST</name>
+ <message>The error</message>
+ <http_code>404</http_code>
+ <description>Used in documentation</description>
+ <hash>137595984a31492d0637fe873922537b13094e53</hash>
+ </error>
+ </errors>
+</frapi-config>
36 Config/outputs.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <outputs>
+ <output>
+ <name>CLI</name>
+ <enabled>1</enabled>
+ <default>0</default>
+ </output>
+ <output>
+ <name>PHP</name>
+ <enabled>1</enabled>
+ <default>0</default>
+ </output>
+ <output>
+ <name>XML</name>
+ <enabled>1</enabled>
+ <default>1</default>
+ </output>
+ <output>
+ <name>JSON</name>
+ <enabled>1</enabled>
+ <default>0</default>
+ </output>
+ <output>
+ <name>PRINTR</name>
+ <enabled>1</enabled>
+ <default>0</default>
+ </output>
+ <output>
+ <name>HTML</name>
+ <enabled>1</enabled>
+ <default>0</default>
+ <hash>798fd060fbd17739b4ce7c8f7ba3900d177a455e</hash>
+ </output>
+ </outputs>
+</frapi-config>
4 Config/partners.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <partners/>
+</frapi-config>
11 Config/users.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<frapi-config>
+ <users>
+ <user>
+ <handle>admin</handle>
+ <password>5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</password>
+ <role>admin</role>
+ <active>1</active>
+ </user>
+ </users>
+</frapi-config>
0  Model/.gitignore
No changes.
1  Model/ArmChair
@@ -0,0 +1 @@
+Subproject commit e8dc56488cdf5a1547c357fb15484ec0e5f5937f
0  Output/.gitignore
No changes.
2  Output/html/Testing2.html.tpl
@@ -0,0 +1,2 @@
+<h3>Hello</h3>
+<p>This is an example of how to generate HTML pages with FRAPI. It is however not recommended as FRAPI is made for webservices and APIs. If you want to build a web application that has a frontend and images and everything, I recommend looking at Lithium, Zend Framework, Symfony, Agavi, Cake or any other web-application frameworks for that matter. FRAPI is built for APIs and exposing your data to the world (machines) and to broaden your market.</p>
0  Output/html/custom/.gitignore
No changes.
1  Output/xml/Testing2.xml.tpl
@@ -0,0 +1 @@
+<hello><?php echo $data['name']; ?></hello>
0  Output/xml/custom/.gitignore
No changes.
1  Output/xml/custom/CustomTesting2.xml.tpl
@@ -0,0 +1 @@
+<response><custom/></response>
Please sign in to comment.
Something went wrong with that request. Please try again.