Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Ubuntu 14.04 beta in travis #8

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
19ca05c
Moved app authentication to listener
fpapadopou Nov 4, 2015
26f1b6a
Strict boolean check
fpapadopou Nov 4, 2015
f2e98d0
Used JsonResponse all over the DefaultController
fpapadopou Nov 4, 2015
ccc4ff2
Removed TestController (redundant)
fpapadopou Nov 4, 2015
83720b3
Used JsonResponse all over the ViewsController
fpapadopou Nov 4, 2015
e8564eb
Code style improvements in ViewsController
fpapadopou Nov 4, 2015
a1c1c90
Used JsonResponse in DefaultHandler
fpapadopou Nov 4, 2015
91ce90e
Code style fixes in DefaultHandler
fpapadopou Nov 4, 2015
c96e12d
Updated Github requests headers and their notes.
fpapadopou Nov 4, 2015
b05fe8d
Split inline functions
fpapadopou Nov 4, 2015
c8c64cf
Removed continue statement from foreach
fpapadopou Nov 4, 2015
3c279b0
Fixed an if statement
fpapadopou Nov 4, 2015
3d5c3b6
findSelectedNode method update
fpapadopou Nov 5, 2015
8a2a07c
Early-return in newLibraryAction
fpapadopou Nov 5, 2015
302ce34
Removed PHPStorm comment
fpapadopou Nov 5, 2015
2de86c0
Added comment
fpapadopou Nov 5, 2015
8903c0e
Removed continue statement
fpapadopou Nov 5, 2015
85c28ca
JS code improvement
fpapadopou Nov 5, 2015
817e49e
Handled JSON decoding failure in files fetching from Github
fpapadopou Nov 5, 2015
84a1ca1
Comments
fpapadopou Nov 5, 2015
9752b9c
Removed multi-line comment
fpapadopou Nov 5, 2015
cd7feac
Use default branch (instead of hardcoded master) if none is provided …
fpapadopou Nov 5, 2015
9a99fbc
Added missing if braces
fpapadopou Nov 5, 2015
014a960
Comment
fpapadopou Nov 5, 2015
744bff6
Replaced continue statement with an elseif
fpapadopou Nov 5, 2015
4fa238b
The Accept header should be set to json only, not raw and json
fpapadopou Nov 5, 2015
cb701b3
Removed apache alias config
fpapadopou Nov 5, 2015
2c6dfd7
Replaced hardcoded symlinks with a2ensite in apache config
fpapadopou Nov 5, 2015
2373106
Added missing variable initialisation
fpapadopou Nov 5, 2015
b6e4994
Fixed a truth check statement.
fpapadopou Nov 5, 2015
9583739
Typo
fpapadopou Nov 5, 2015
22fa055
Handle cases with no route params in listener
fpapadopou Nov 5, 2015
44b5955
Merge remote-tracking branch 'origin/fixtures-testing' into library-m…
fpapadopou Nov 5, 2015
d791fb6
Added travis and coveralls badges
fpapadopou Nov 5, 2015
88ec07b
Added missing conf extension to the apache 2.4 config file
fpapadopou Nov 5, 2015
f3f7ea0
Removed redundant chmod operation
fpapadopou Nov 5, 2015
0596c03
chmod to the whole build dir before tests
fpapadopou Nov 5, 2015
aca103e
enable Ubuntu 14.04 beta in travis
dastergon Nov 11, 2015
4a2186d
remove php-specific-config from travis.yml
dastergon Nov 11, 2015
ed011bc
enable mysql in travis via services key
dastergon Nov 11, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php
php:
- 5.5.9
sudo: required
dist: trusty
services: mysql

# Add encrypted env variables, used for setting up the test environment
env:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/codebendercc/eratosthenes.svg?branch=library-manager-updates-no-html-encode)](https://travis-ci.org/codebendercc/eratosthenes)
[![Coverage Status](https://coveralls.io/repos/codebendercc/eratosthenes/badge.svg?branch=library-manager-updates-no-html-encode&service=github)](https://coveralls.io/github/codebendercc/eratosthenes?branch=library-manager-updates-no-html-encode)
Arduino Library Management System
====

Expand Down
7 changes: 7 additions & 0 deletions Symfony/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ framework:
session: ~
fragments: ~

services:
kernel.listener.auth_listener:
class: Codebender\LibraryBundle\EventListener\AuthenticationListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
arguments: [ %authorizationKey% ]

# Twig Configuration
twig:
debug: %kernel.debug%
Expand Down
110 changes: 43 additions & 67 deletions Symfony/src/Codebender/LibraryBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Codebender\LibraryBundle\Entity\ExternalLibrary;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -18,38 +19,33 @@ class DefaultController extends Controller
*/
public function statusAction()
{
return new Response(json_encode(array("success" => true, "status" => "OK")));
return new JsonResponse(['success' => true, 'status' => 'OK']);
}

/**
* The main library manager API handler action.
* Checks the autorization credentials and the validity of the request.
* Can handle several types of requests, like code fetching, examples fetching, etc.
*
* @param $authorizationKey
* @param $version
* @return Response
*/
public function apiHandlerAction($authorizationKey, $version)
public function apiHandlerAction($version)
{
if ($authorizationKey !== $this->container->getParameter('authorizationKey')) {
return new Response(json_encode(array("success" => false, "message" => "Invalid library manager authorization key.")));
}

if ($version != "v1") {
return new Response(json_encode(array("success" => false, "message" => "Invalid library manager API version.")));
if ($version != 'v1') {
return new JsonResponse(['success' => false, 'message' => 'Invalid library manager API version.']);
}

$request = $this->getRequest();
$content = $request->getContent();

$content = json_decode($content, true);
if ($content === null) {
return new Response(json_encode(array("success" => false, "message" => "Wrong data")));
return new JsonResponse(['success' => false, 'message' => 'Wrong data']);
}

if ($this->isValid($content) === false) {
return new Response(json_encode(array("success" => false, "message" => "Incorrect request fields")));
return new JsonResponse(['success' => false, 'message' => 'Incorrect request fields']);
}

return $this->selectAction($content);
Expand All @@ -74,7 +70,7 @@ private function selectAction($content)
case "getKeywords":
return $this->getKeywords($content["library"]);
default:
return new Response(json_encode(array("success" => false, "message" => "No valid action requested")));
return new JsonResponse(['success' => false, 'message' => 'No valid action requested']);
}
}

Expand Down Expand Up @@ -112,25 +108,25 @@ private function listAll()
ksort($includedLibraries);
ksort($externalLibraries);

return new Response(json_encode(
array(
"success" => true,
"text" => "Successful Request!",
"categories" => array(
"Examples" => $builtinExamples,
"Builtin Libraries" => $includedLibraries,
"External Libraries" => $externalLibraries)
)
)
return new JsonResponse(
[
'success' => true,
'text' => 'Successful Request!',
'categories' => [
'Examples' => $builtinExamples,
'Builtin Libraries' => $includedLibraries,
'External Libraries' => $externalLibraries
]
]
);
}

private function getExampleCode($library, $example)
{

$type = json_decode($this->getLibraryType($library), true);
if (!$type['success']) {
return new Response(json_encode($type));
if ($type['success'] !== true) {
return new JsonResponse($type);
}

switch ($type['type']) {
Expand All @@ -150,50 +146,39 @@ private function getExampleCode($library, $example)
return new Response($example, 200, array('content-type' => 'application/json'));
}

public function getLibraryGitBranchesAction($authorizationKey)
public function getLibraryGitBranchesAction()
{
if ($authorizationKey !== $this->container->getParameter('authorizationKey')) {
return new Response(json_encode(array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.')));
}

$handler = $this->get('codebender_library.handler');

$githubUrl = $this->getRequest()->request->get('githubUrl');
$processedGitUrl = $handler->processGithubUrl($githubUrl);

if ($processedGitUrl['success'] !== true) {
return new Response(json_encode(array('success' => false, 'message' => 'Could not process provided url')));
return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
}

$repoBranches = $handler->fetchRepoRefsFromGit($processedGitUrl['owner'], $processedGitUrl['repo']);

if ($repoBranches['success'] != true) {
return new Response(json_encode(array(
'success' => false,
'message' => 'Something went wrong while fetching the library. Please double check the Url you provided.'
)));
if ($repoBranches['success'] !== true) {
return new JsonResponse([
'success' => false,
'message' => 'Something went wrong while fetching the library. Please double check the Url you provided.'
]);
}

$response = new Response(json_encode(array('success' => true, 'branches' => $repoBranches['headRefs'])));

$response->headers->set('Content-Type', 'application/json');
return $response;
return new JsonResponse(['success' => true, 'branches' => $repoBranches['headRefs']]);
}

public function getRepoGitTreeAndMetaAction($authorizationKey)
public function getRepoGitTreeAndMetaAction()
{
if ($authorizationKey !== $this->container->getParameter('authorizationKey')) {
return new Response(json_encode(array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.')));
}

$handler = $this->get('codebender_library.handler');

$githubUrl = $this->getRequest()->request->get('githubUrl');
$processedGitUrl = $handler->processGithubUrl($githubUrl);
$gitBranch = $this->getRequest()->request->get('githubBranch');

if ($processedGitUrl['success'] !== true) {
return new Response(json_encode(array('success' => false, 'message' => 'Could not process provided url')));
return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
}

$githubLibrary = json_decode(
Expand All @@ -207,25 +192,19 @@ public function getRepoGitTreeAndMetaAction($authorizationKey)
);

if (!$githubLibrary['success']) {
$response = new Response(json_encode($githubLibrary));
$response->headers->set('Content-Type', 'application/json');
return $response;
return new JsonResponse($githubLibrary);
}

$description = $handler->getRepoDefaultDescription($processedGitUrl['owner'], $processedGitUrl['repo']);

$response = new Response(json_encode(
array(
'success' => true,
'files' => $githubLibrary['files'],
'owner' => $processedGitUrl['owner'],
'repo' => $processedGitUrl['repo'],
'branch' => $gitBranch,
'description' => $description
)
));
$response->headers->set('Content-Type', 'application/json');
return $response;
return new JsonResponse([
'success' => true,
'files' => $githubLibrary['files'],
'owner' => $processedGitUrl['owner'],
'repo' => $processedGitUrl['repo'],
'branch' => $gitBranch,
'description' => $description
]);
}

private function getLibraryExamples($library)
Expand Down Expand Up @@ -495,23 +474,20 @@ private function getExampleAndLibNameFromRelativePath($path, $filename)
private function getKeywords($library)
{
if ($library === null) {

return new Response(json_encode(array("success" => false)));

return new JsonResponse(['success' => false]);
}

$exists = json_decode($this->getLibraryType($library), true);

if ($exists['success'] === false) {
return new Response(json_encode($exists));
return new JsonResponse($exists);
}

$path = "";
if ($exists['type'] == 'external') {
$path = $this->container->getParameter('external_libraries') . '/' . $library;
} else if ($exists['type'] = 'builtin') {
$path = $this->container->getParameter('builtin_libraries') . "/libraries/" . $library;
} else return new Response(json_encode(array("success" => false)));
} else return new JsonResponse(['success' => false]);

$keywords = array();

Expand Down Expand Up @@ -548,7 +524,7 @@ private function getKeywords($library)
break;
}

return new Response(json_encode(array('success' => true, 'keywords' => $keywords)));
return new JsonResponse(['success' => true, 'keywords' => $keywords]);

}

Expand Down
34 changes: 0 additions & 34 deletions Symfony/src/Codebender/LibraryBundle/Controller/TestController.php

This file was deleted.

Loading