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

[WIP] Follow base api 1.0 #8

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script:
- composer install --dev --prefer-source

script: phpunit --coverage-text
script: vendor/bin/phpspec run

# YoutubeAPI should be compatible hhvm but tests are not !
matrix:
allow_failures:
- php: hhvm
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1.0.0 (2014-09-XX)
==================

Most changes are because of the new base api release.

New features
------------

* Compatibility with HHVM

Changes
-----------

* Configuring authentication is now possible by using the method `useAuthentication`
* Getting API classes is done via getter, before: `->api('videos')`, now: `->getVideosApi()` this method is IDE-friendly
* Authentication can now use the same client as the api itself
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 Nekland
Copyright (c) 2013-2015 Nekland

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
27 changes: 19 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"name": "nekland/youtube-api",
"type": "library",
"description": "Simple library you can build you're api upon.",
"keywords": ["nekland", "api", "base"],
"description": "Youtube API made easy !",
"keywords": ["nekland", "api", "youtube"],
"license": "MIT",
"authors": [
{
"name": "Maxime Veber",
"email": "nekland@gmail.com",
"email": "nek.dev@gmail.com",
"homepage": "http://nekland.fr"
},
{
"name": "Nekland Team",
"email": "[email protected]",
"homepage": "http://team.nekland.fr"
}
],
"require": {
"php": ">=5.4",
"guzzle/guzzle": ">=3.7",
"nekland/base-api": "~0.0.1",
"namshi/jose": "~1.2"
"php": ">=5.4",
"guzzlehttp/guzzle": "~4.0",
"nekland/base-api": "~1.0",
"namshi/jose": "~1.2"
},
"suggest": {
"nekland/soundcloud-api": "Soundcloud API made easy !"
Expand All @@ -24,6 +29,12 @@
"psr-0": { "Nekland\\": "lib/" }
},
"require-dev": {
"phpunit/phpunit": ">=3.7"
"phpspec/phpspec": "~2.0"
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
}
}
4 changes: 2 additions & 2 deletions docs/Api/playlists.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ First retrieve the playlist api object (`Nekland\YoutubeApi\Api\Playlists`).
<?php

$youtube = new Youtube();
$playlistApi = $youtube->api('playlists');
$playlistApi = $youtube->getPlayslistsApi();
```

List playlists
Expand Down Expand Up @@ -72,6 +72,6 @@ The day this lines are written, it's:
* id: 0
* player: 0
* snippet: 2
*status: 2
* status: 2

> For now the playlist api only retrieve information. More coming ! PRs are accepted on the topic :) .
39 changes: 39 additions & 0 deletions lib/Nekland/YoutubeApi/Api/Activities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is a part of nekland youtube api package
*
* (c) Nekland <[email protected]>
*
* For the full license, take a look to the LICENSE file
* on the root directory of this project
*/

namespace Nekland\YoutubeApi\Api;

use Nekland\BaseApi\Api\AbstractApi;
use Nekland\YoutubeApi\Api\Behavior\ListTrait;

/**
* Class Activities
*
* Note about the "parts" array: it can take the following values:
* id, contentDetails, snippet.
*
* @see https://developers.google.com/youtube/v3/docs/activities/list for more information about paramaters
* @see https://developers.google.com/youtube/v3/docs/activities#resource for more information about json format
*/
class Activities extends AbstractApi
{
use ListTrait;

public function getUrl()
{
return 'youtube/v3/activities';
}

public function getType()
{
return 'activity';
}
}
14 changes: 9 additions & 5 deletions lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Nekland\YoutubeApi\Api\Behavior;

use Nekland\YoutubeApi\Transformer\Model\Collection;

trait ListTrait
{
/**
Expand All @@ -21,12 +23,12 @@ trait ListTrait
*/
public function listById($id, array $parts = ['snippet'], array $otherParameters = [])
{
$parameters = array_merge(
$body = array_merge(
['part' => implode(',', $parts), 'id' => $id],
$otherParameters
);

return $this->get(static::URL, $parameters);
return $this->get($this->getUrl(), $body);
}

/**
Expand All @@ -39,7 +41,9 @@ public function listById($id, array $parts = ['snippet'], array $otherParameters
*/
public function getById($id, array $parts = ['snippet'], array $otherParameters = [])
{
return $this->listById($id, $parts, $otherParameters)['items'][0];
$res = $this->listById($id, $parts, $otherParameters);

return $res['items'][0];
}

/**
Expand All @@ -50,12 +54,12 @@ public function getById($id, array $parts = ['snippet'], array $otherParameters
*/
public function listBy(array $filters, array $parts = ['snippet'], array $otherParameters = [])
{
$parameters = array_merge(
$body = array_merge(
['part' => $parts],
$filters,
$otherParameters
);

return $this->get(static::URL, $parameters);
return $this->get($this->getUrl(), $body);
}
}
35 changes: 35 additions & 0 deletions lib/Nekland/YoutubeApi/Api/ChannelSections.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is a part of nekland youtube api package
*
* (c) Nekland <[email protected]>
*
* For the full license, take a look to the LICENSE file
* on the root directory of this project
*/

namespace Nekland\YoutubeApi\Api;


use Nekland\BaseApi\Api\AbstractApi;
use Nekland\YoutubeApi\Api\Behavior\ListTrait;

/**
* Class ChannelSections
*
* Note about the "parts" array: it can take the following values:
* id, contentDetails, snippet.
*
* @see https://developers.google.com/youtube/v3/docs/channelSections/list for more information about paramaters
* @see https://developers.google.com/youtube/v3/docs/channelSections#resource for more information about json format
*/
class ChannelSections extends AbstractApi
{
use ListTrait;

public function getUrl()
{
return 'youtube/v3/channelSections';
}
}
41 changes: 41 additions & 0 deletions lib/Nekland/YoutubeApi/Api/Channels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is a part of nekland youtube api package
*
* (c) Nekland <[email protected]>
*
* For the full license, take a look to the LICENSE file
* on the root directory of this project
*/

namespace Nekland\YoutubeApi\Api;


use Nekland\BaseApi\Api\AbstractApi;
use Nekland\YoutubeApi\Api\Behavior\ListTrait;

/**
* Class Channels
*
* Note about the "parts" array: it can take the following values:
* id, contentDetails, snippet, brandingSettings, auditDetails,
* contentOwnerDetails, invideoPromotion, statistics, status, topicDetails.
*
* @see https://developers.google.com/youtube/v3/docs/channels/list for more information about paramaters
* @see https://developers.google.com/youtube/v3/docs/channels#resource for more information about json format
*/
class Channels extends AbstractApi
{
use ListTrait;

public function getUrl()
{
return 'youtube/v3/channels';
}

public function getType()
{
return 'channel';
}
}
35 changes: 35 additions & 0 deletions lib/Nekland/YoutubeApi/Api/GuideCategories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is a part of nekland youtube api package
*
* (c) Nekland <[email protected]>
*
* For the full license, take a look to the LICENSE file
* on the root directory of this project
*/

namespace Nekland\YoutubeApi\Api;


use Nekland\BaseApi\Api\AbstractApi;
use Nekland\YoutubeApi\Api\Behavior\ListTrait;

/**
* Class GuideCategories
*
* Note about the "parts" array: it can take the following values:
* snippet
*
* @see https://developers.google.com/youtube/v3/docs/guideCategories/list for more information about paramaters
* @see https://developers.google.com/youtube/v3/docs/guideCategories#resource for more information about json format
*/
class GuideCategories extends AbstractApi
{
use ListTrait;

public function getUrl()
{
return 'youtube/v3/guideCategories';
}
}
12 changes: 10 additions & 2 deletions lib/Nekland/YoutubeApi/Api/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
*/
class Playlists extends AbstractApi
{
const URL = 'youtube/v3/playlists';

use ListTrait;

public function getUrl()
{
return 'youtube/v3/playlists';
}

public function getType()
{
return 'playlist';
}
}
14 changes: 11 additions & 3 deletions lib/Nekland/YoutubeApi/Api/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/

namespace Nekland\YoutubeApi\Api;

use Nekland\BaseApi\Api\AbstractApi;
use Nekland\YoutubeApi\Api\Behavior\ListTrait;


/**
* Class Videos
*
Expand All @@ -26,7 +26,15 @@
*/
class Videos extends AbstractApi
{
const URL = 'youtube/v3/videos';

use ListTrait;

public function getUrl()
{
return 'youtube/v3/videos';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To force a user extending AbstractApi to define theses methods.
He don't have to if they are just consts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and with return self::URL; ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the interest of having 2 way to get the information

}

public function getType()
{
return 'video';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best practice in constant

}
}
Loading