Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed May 2, 2014
0 parents commit e6343dc
Show file tree
Hide file tree
Showing 29 changed files with 1,735 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
@@ -0,0 +1,5 @@
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
docs export-ignore
tests export-ignore
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
vendor
composer.lock
18 changes: 18 additions & 0 deletions .travis.yml
@@ -0,0 +1,18 @@
language: php

php:
- 5.3.3
- 5.4
- 5.5
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script:
- composer self-update
- composer install --no-interaction --prefer-source --dev

script: php tests/lint.php src/Kdyby/ tests/KdybyTests/ && VERBOSE=true ./tests/run-tests.sh -s tests/KdybyTests/
25 changes: 25 additions & 0 deletions README.md
@@ -0,0 +1,25 @@
Kdyby/Github [![Build Status](https://secure.travis-ci.org/Kdyby/Github.png?branch=master)](http://travis-ci.org/Kdyby/Github)
===========================


Requirements
------------

Kdyby/Github requires PHP 5.3.2 or higher with cUrl extension enabled.

- [Nette Framework 2.0.x](https://github.com/nette/nette)


Installation
------------

The best way to install Kdyby/Github is using [Composer](http://getcomposer.org/):

```sh
$ composer require kdyby/github:@dev
```


-----

Homepage [http://www.kdyby.org](http://www.kdyby.org) and repository [http://github.com/kdyby/github](http://github.com/kdyby/github).
41 changes: 41 additions & 0 deletions composer.json
@@ -0,0 +1,41 @@
{
"name": "kdyby/github",
"type": "library",
"description": "Extended Github PHP SDK with authorization from KnpLabs for Nette Framework",
"keywords": ["nette", "github", "sdk", "authorization"],
"homepage": "http://kdyby.org",
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"authors": [
{
"name": "Filip Procházka",
"homepage": "http://filip-prochazka.com",
"email": "filip@prochazka.su"
}
],
"require": {
"knplabs/github-api": "~1.2",
"nette/nette": "~2.1@dev",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"nette/tester": "@dev"
},
"support": {
"email": "filip@prochazka.su",
"issues": "https://github.com/kdyby/github/issues"
},
"autoload": {
"psr-0": {
"Kdyby\\Github\\": "src/"
},
"classmap": [
"src/Kdyby/Github/exceptions.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}
57 changes: 57 additions & 0 deletions license.md
@@ -0,0 +1,57 @@
Licenses
========

Good news! You may use Kdyby Framework under the terms of either
the New BSD License or the GNU General Public License (GPL) version 2 or 3.

The BSD License is recommended for most projects. It is easy to understand and it
places almost no restrictions on what you can do with the framework. If the GPL
fits better to your project, you can use the framework under this license.

You don't have to notify anyone which license you are using. You can freely
use Kdyby Framework in commercial projects as long as the copyright header
remains intact.



New BSD License
---------------

Copyright (c) 2008 Filip Procházka (http://filip-prochazka.com)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of "Kdyby Framework" nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall the copyright owner or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused and on
any theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.



GNU General Public License
--------------------------

GPL licenses are very very long, so instead of including them here we offer
you URLs with full text:

- [GPL version 2](http://www.gnu.org/licenses/gpl-2.0.html)
- [GPL version 3](http://www.gnu.org/licenses/gpl-3.0.html)
55 changes: 55 additions & 0 deletions src/Kdyby/Github/Api/AccessTokenListener.php
@@ -0,0 +1,55 @@
<?php

/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008 Filip Procházka (filip@prochazka.su)
*
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

namespace Kdyby\Github\Api;

use Github;
use Guzzle\Common\Event;
use Guzzle\Http\Message\Request;
use Kdyby;
use Kdyby\Github\SessionStorage;
use Nette;



/**
* @author Filip Procházka <filip@prochazka.su>
*/
class AccessTokenListener extends Nette\Object
{

/**
* @var SessionStorage
*/
private $session;



public function __construct(SessionStorage $session)
{
$this->session = $session;
}



/**
* @param Event|Request[] $event
*/
public function onRequestBeforeSend(Event $event)
{
// Skip by default
if ($this->session->access_token === NULL) {
return;
}

$event['request']->setHeader('Authorization', 'token ' . utf8_encode($this->session->access_token));
}

}
61 changes: 61 additions & 0 deletions src/Kdyby/Github/Api/ErrorListener.php
@@ -0,0 +1,61 @@
<?php

/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008 Filip Procházka (filip@prochazka.su)
*
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

namespace Kdyby\Github\Api;

use Guzzle\Common\Event;
use Guzzle\Http\Message\Request;
use Kdyby;
use Kdyby\Github\Diagnostics\Panel;
use Nette;



/**
* @author Filip Procházka <filip@prochazka.su>
*/
class ErrorListener extends \Github\HttpClient\Listener\ErrorListener
{

/**
* @var Panel
*/
private $panel;



/**
* @param Event|Request[] $event
* @throws \Exception
*/
public function onRequestError(Event $event)
{
try {
parent::onRequestError($event);

} catch (\Exception $e) {
if ($this->panel) {
$class = get_class($e);
$exception = new $class(trim($e->getMessage()) ?: $event['request']->getResponse()->getReasonPhrase(), $e->getCode(), $e);
$this->panel->failure(new Event(array('exception' => $exception) + $event->toArray()));
}

throw $e;
}
}



public function setPanel(Panel $panel)
{
$this->panel = $panel;
}

}
66 changes: 66 additions & 0 deletions src/Kdyby/Github/Api/HttpClient.php
@@ -0,0 +1,66 @@
<?php

/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008 Filip Procházka (filip@prochazka.su)
*
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

namespace Kdyby\Github\Api;

use Guzzle\Http\Client as GuzzleClient;
use Guzzle\Http\ClientInterface;
use Kdyby;
use Nette;
use Symfony\Component\EventDispatcher\EventDispatcher;



/**
* @author Filip Procházka <filip@prochazka.su>
*/
class HttpClient extends \Github\HttpClient\HttpClient
{

/**
* @var GuzzleClient
*/
protected $client;

/**
* @var ErrorListener
*/
private $errorListener;



public function __construct(Kdyby\Github\SessionStorage $session, array $options = array(), ClientInterface $client = null)
{
parent::__construct($options, $client);

// reset listeners
$this->client->setEventDispatcher(new EventDispatcher());

// add modified listeners
$this->addListener('request.error', array(
$this->errorListener = new ErrorListener($this->options),
'onRequestError'
));
$this->addListener('request.before_send', array(
new AccessTokenListener($session),
'onRequestBeforeSend'
));
}



public function setPanel(Kdyby\Github\Diagnostics\Panel $panel)
{
$this->addListener('request.before_send', array($panel, 'begin'));
$this->addListener('request.success', array($panel, 'success'));
$this->errorListener->setPanel($panel);
}

}

0 comments on commit e6343dc

Please sign in to comment.