Skip to content

Commit

Permalink
Merge branch 'next' into develop
Browse files Browse the repository at this point in the history
* next: (29 commits)
  update documentation
  make SDK constructor private
  declare value objects immutable
  make Key constructor private
  lazy load catalog artist albums
  use sequences instead of sets as there is no guarantee there is no duplicates due to the pagination
  use lazy structure for top level fetchs
  return empty sets instead of throwing
  return an empty storefront set instead of throwing
  return a Maybe instead of throwing an error if the user token is invalid
  return a Maybe instead of raising errors when an element from the catalog is not found
  there is always an artwork for a catalog album
  load the artist artwork
  load link to catalog artist
  fix values that may not exist
  CS
  CS
  use Maybe instead of nullable types
  CS
  remove unused exceptions
  ...
  • Loading branch information
Baptouuuu committed Jul 24, 2022
2 parents d42286a + 3840ee8 commit 81bdae4
Show file tree
Hide file tree
Showing 108 changed files with 3,049 additions and 2,503 deletions.
47 changes: 10 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4', '8.0']
php-version: ['8.1']
name: 'PHPUnit'
steps:
- name: Checkout
Expand All @@ -20,17 +20,8 @@ jobs:
extensions: mbstring, intl
coverage: xdebug
ini-values: xdebug.max_nesting_level=2048
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress --prefer-source
- name: Composer
uses: "ramsey/composer-install@v2"
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
env:
Expand All @@ -42,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.0']
php-version: ['8.1']
name: 'Psalm'
steps:
- name: Checkout
Expand All @@ -52,24 +43,15 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Composer
uses: "ramsey/composer-install@v2"
- name: Psalm
run: vendor/bin/psalm --shepherd
cs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4']
php-version: ['8.1']
name: 'CS'
steps:
- name: Checkout
Expand All @@ -79,16 +61,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Composer
uses: "ramsey/composer-install@v2"
- name: CS
run: vendor/bin/php-cs-fixer fix --diff --dry-run --diff-format udiff
run: vendor/bin/php-cs-fixer fix --diff --dry-run
File renamed without changes.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,40 @@ use MusicCompanion\AppleMusic\{
Key,
};
use Innmind\OperatingSystem\Factory;
use Innmind\TimeContinuum\Period\Earth\Hour;
use Innmind\TimeContinuum\Earth\Period\Hour;
use Innmind\Url\Path;
use Innmind\Filesystem\Name;
use Innmind\Immutable\Set;

$os = Factory::build();

$sdk = new SDK\SDK(
$sdk = SDK::of(
$os->clock(),
$os->remote()->http(),
new Key( // @see https://help.apple.com/developer-account/#/devce5522674 to understand howto generate the key
Key::of( // @see https://help.apple.com/developer-account/#/devce5522674 to understand howto generate the key
'KEY_ID',
'TEAM_ID',
$os
->filesystem()
->mount(Path::of('config_dir/'))
->get(new Name('AuthKey_TEAM_ID.p8'))
->content(),
->match(
static fn($file) => $file->content(),
static fn() => throw new \RuntimeException('Key file not found'),
),
),
new Hour(1) // expire the generated token after an hour
);

$sdk->storefronts()->all(); // set<SDK\Storefront>
$sdk->storefronts()->all(); // Set<SDK\Storefront>
$catalog = $sdk->catalog(new SDK\Storefront\Id('fr'));
$result = $catalog->search('Pendulum Live at Brixton');
$albums = [];

foreach ($result->albums() as $id) {
$albums[] = $catalog->album($id);
}
$albums = $result->albums()->map($catalog->album(...));

// @see https://developer.apple.com/documentation/applemusicapi/getting_keys_and_creating_tokens
// to retrieve the user token
$sdk->library($userToken)->artists(); // set<SDK\Library\Artist>
$sdk->library($userToken)->match(
static fn($libray) => $libray->artists(), // Set<SDK\Library\Artist>
static fn() => throw new \RuntimeException('Invalid user token'),
);
```
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
"authors": [
{
"name": "Baptiste Langlade",
"email": "langlade.baptiste@gmail.com"
"email": "baptiste.langlade@hey.com"
}
],
"support": {
"issues": "http://github.com/MusicCompanion/AppleMusic/issues"
},
"require": {
"php": "~7.4|~8.0",
"innmind/immutable": "~3.5",
"innmind/url": "~3.3",
"innmind/colour": "~3.1",
"innmind/operating-system": "~2.0",
"php": "~8.1",
"innmind/immutable": "~4.4",
"innmind/url": "~4.1",
"innmind/colour": "~4.0",
"innmind/operating-system": "~3.1",
"innmind/json": "^1.1",
"lcobucci/jwt": "~4.0"
},
Expand All @@ -38,6 +38,6 @@
"phpunit/phpunit": "~9.0",
"innmind/black-box": "~4.9",
"vimeo/psalm": "~4.4",
"innmind/coding-standard": "^1.1"
"innmind/coding-standard": "~2.0"
}
}
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Album/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Id
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbers::any(),
);
}
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Artist/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Id
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbers::any(),
);
}
Expand Down
12 changes: 11 additions & 1 deletion fixtures/SDK/Catalog/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Fixtures\MusicCompanion\AppleMusic\SDK\Catalog;

use MusicCompanion\AppleMusic\SDK\Catalog\Artwork as Model;
use Innmind\Immutable\Maybe;
use Innmind\BlackBox\Set;
use Fixtures\Innmind\Colour\Colour;
use Fixtures\Innmind\Url\Url;
Expand All @@ -17,7 +18,16 @@ public static function any(): Set
{
return Set\Composite::immutable(
static function($width, $height, $url, $background, $text1, $text2, $text3, $text4): Model {
return new Model($width, $height, $url, $background, $text1, $text2, $text3, $text4);
return new Model(
$width,
$height,
$url,
Maybe::of($background),
Maybe::of($text1),
Maybe::of($text2),
Maybe::of($text3),
Maybe::of($text4),
);
},
Artwork\Width::any(),
Artwork\Height::any(),
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Genre
public static function any(): Set
{
return Set\Decorate::immutable(
static function(string $string): Model {
return new Model($string);
},
Model::of(...),
Set\Strings::any(),
);
}
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Song/DiscNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class DiscNumber
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbersExceptZero::any(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/SDK/Catalog/Song/ISRC.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function any(): Set

return Set\Composite::immutable(
static function(...$bits): Model {
return new Model(\implode('', $bits));
return Model::of(\implode('', $bits));
},
$c,
$c,
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Song/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Id
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbers::any(),
);
}
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Catalog/Song/TrackNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class TrackNumber
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbersExceptZero::any(),
);
}
Expand Down
3 changes: 2 additions & 1 deletion fixtures/SDK/Library/Album/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Fixtures\MusicCompanion\AppleMusic\SDK\Library\Album;

use MusicCompanion\AppleMusic\SDK\Library\Album\Artwork as Model;
use Innmind\Immutable\Maybe;
use Innmind\BlackBox\Set;
use Fixtures\Innmind\Url\Url;

Expand All @@ -16,7 +17,7 @@ public static function any(): Set
{
return Set\Composite::immutable(
static function($width, $height, $url): Model {
return new Model($width, $height, $url);
return new Model(Maybe::of($width), Maybe::of($height), $url);
},
new Set\Either(
Artwork\Width::any(),
Expand Down
2 changes: 1 addition & 1 deletion fixtures/SDK/Library/Album/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function any(): Set

return Set\Decorate::immutable(
static function(string $chars): Model {
return new Model('l.'.$chars);
return Model::of('l.'.$chars);
},
$chars,
)->take(100);
Expand Down
2 changes: 1 addition & 1 deletion fixtures/SDK/Library/Artist/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function any(): Set

return Set\Decorate::immutable(
static function(string $chars): Model {
return new Model('r.'.$chars);
return Model::of('r.'.$chars);
},
$chars,
)->take(100);
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Library/Song/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Genre
public static function any(): Set
{
return Set\Decorate::immutable(
static function(string $string): Model {
return new Model($string);
},
Model::of(...),
Set\Strings::any(),
);
}
Expand Down
4 changes: 1 addition & 3 deletions fixtures/SDK/Library/Song/TrackNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class TrackNumber
public static function any(): Set
{
return Set\Decorate::immutable(
static function(int $number): Model {
return new Model($number);
},
Model::of(...),
Set\NaturalNumbersExceptZero::any(),
);
}
Expand Down
5 changes: 2 additions & 3 deletions fixtures/SDK/Storefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use MusicCompanion\AppleMusic\SDK\Storefront as Model;
use Innmind\BlackBox\Set;
use function Innmind\Immutable\unwrap;
use Fixtures\Innmind\Immutable\Set as ISet;

final class Storefront
Expand All @@ -17,12 +16,12 @@ public static function any(): Set
{
return Set\Composite::immutable(
static function($id, $name, $default, $languages): Model {
return new Model($id, $name, $default, ...unwrap($languages));
return new Model($id, $name, $default, $languages);
},
Storefront\Id::any(),
Storefront\Name::any(),
Storefront\Language::any(),
ISet::of(Model\Language::class, Storefront\Language::any()),
ISet::of(Storefront\Language::any()),
)->take(100);
}
}
2 changes: 1 addition & 1 deletion fixtures/SDK/Storefront/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function any(): Set

return Set\Composite::immutable(
static function(string $char1, string $char2, string $region1, string $region2): Model {
return new Model($char1.$char2.'-'.$region1.$region2);
return Model::of($char1.$char2.'-'.$region1.$region2);
},
$char,
$char,
Expand Down
8 changes: 0 additions & 8 deletions src/Exception/InvalidToken.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/InvalidUserToken.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/RuntimeException.php

This file was deleted.

0 comments on commit 81bdae4

Please sign in to comment.