Skip to content

Commit

Permalink
Merge pull request #261 from elifesciences/import-api-client
Browse files Browse the repository at this point in the history
import ApiClient classes from api-client
  • Loading branch information
scottaubrey authored Nov 7, 2024
2 parents 7739384 + 3bfa6cb commit 7e4262e
Show file tree
Hide file tree
Showing 132 changed files with 2,345 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:
docker buildx build --build-arg=PHP_VERSION=$(PHP_VERSION) -t php-composer:$(PHP_VERSION) .

lint: build
docker run --rm -v ./:/code -v/code/vendor php-composer:$(PHP_VERSION) bash -c 'vendor/bin/phpcs --standard=phpcs.xml.dist --warning-severity=0 -p src/ scripts/ test/'
docker run --rm -v ./:/code -v/code/vendor php-composer:$(PHP_VERSION) bash -c 'vendor/bin/phpcs --standard=phpcs.xml.dist --warning-severity=0 -p src/ scripts/ test/ spec/'

test: build lint
docker run --rm -v ./:/code -v/code/vendor php-composer:$(PHP_VERSION) bash -c './project_tests.sh'
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"autoload-dev": {
"psr-4": {
"test\\eLife\\ApiSdk\\": "./test"
"test\\eLife\\ApiSdk\\": "./test",
"spec\\eLife\\ApiSdk\\": "./spec"
}
},
"require": {
Expand All @@ -28,6 +29,8 @@
"justinrainbow/json-schema": "^3.0 || ^4.0 || ^5.0",
"mindplay/composer-locator": "^2.1.1",
"mtdowling/jmespath.php": "^2.0",
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.5",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^5.2",
"psr/http-message": "^1.0",
"squizlabs/php_codesniffer": "^3.5"
Expand Down
4 changes: 4 additions & 0 deletions phpspec.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
suites:
api-client:
namespace: eLife\ApiSdk
psr4_prefix: eLife\ApiSdk
3 changes: 2 additions & 1 deletion project_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#!/bin/bash
set -e

vendor/bin/phpcs --standard=phpcs.xml.dist --warning-severity=0 -p src/ scripts/ test/
vendor/bin/phpcs --standard=phpcs.xml.dist --warning-severity=0 -p src/ scripts/ test/ spec/
vendor/bin/phpunit --log-junit="build/${dependencies}-phpunit.xml"
vendor/bin/phpspec run
36 changes: 36 additions & 0 deletions spec/ApiClient/AnnotationsClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class AnnotationsClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_lists_annotations()
{
$request = new Request('GET', 'annotations?by=user&page=1&per-page=20&order=desc&use-date=updated&access=restricted',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.annotation-list+json; version=1', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.annotation-list+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->listAnnotations(['Accept' => 'application/vnd.elife.annotation-list+json; version=1'], 'user', 1, 20, true, 'updated', 'restricted')
->shouldBeLike($response);
}
}
49 changes: 49 additions & 0 deletions spec/ApiClient/AnnualReportsClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class AnnualReportsClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_gets_an_annual_report()
{
$request = new Request('GET', 'annual-reports/2012',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.annual-report+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.annual-report+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getReport(['Accept' => 'application/vnd.elife.annual-report+json; version=2'], 2012)
->shouldBeLike($response);
}

public function it_lists_annual_reports()
{
$request = new Request('GET', 'annual-reports?page=1&per-page=20&order=desc',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.annual-report-list+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.annual-report-list+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->listReports(['Accept' => 'application/vnd.elife.annual-report-list+json; version=2'], 1, 20, true)
->shouldBeLike($response);
}
}
93 changes: 93 additions & 0 deletions spec/ApiClient/ArticlesClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class ArticlesClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_gets_a_latest_version_for_an_article()
{
$request = new Request('GET', 'articles/3',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.article-poa+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.article-poa+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getArticleLatestVersion(['Accept' => 'application/vnd.elife.article-poa+json; version=2'], '3')
->shouldBeLike($response)
;
}

public function it_gets_a_history_for_an_article()
{
$request = new Request('GET', 'articles/3/versions',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.article-history+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.article-history+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getArticleHistory(['Accept' => 'application/vnd.elife.article-history+json; version=2'], '3')
->shouldBeLike($response)
;
}

public function it_gets_related_articles_for_an_article()
{
$request = new Request('GET', 'articles/3/related',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.article-related+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.article-related+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getRelatedArticles(['Accept' => 'application/vnd.elife.article-related+json; version=2'], '3')
->shouldBeLike($response);
}

public function it_gets_a_version_for_an_article()
{
$request = new Request('GET', 'articles/3/versions/2',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.article-poa+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.article-poa+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getArticleVersion(['Accept' => 'application/vnd.elife.article-poa+json; version=2'], '3', 2)
->shouldBeLike($response)
;
}

public function it_lists_articles()
{
$request = new Request('GET', 'articles?page=1&per-page=20&order=desc&subject[]=cell-biology',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.articles-list+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.articles-list+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->listArticles(['Accept' => 'application/vnd.elife.articles-list+json; version=2'],
1, 20, true, ['cell-biology'])
->shouldBeLike($response)
;
}
}
36 changes: 36 additions & 0 deletions spec/ApiClient/BioprotocolClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class BioprotocolClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_queries()
{
$request = new Request('GET', 'bioprotocol/article/12345',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.bioprotocol+json; version=1', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.bioprotocol+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->list(['Accept' => 'application/vnd.elife.bioprotocol+json; version=1'], 'article', '12345')
->shouldBeLike($response);
}
}
52 changes: 52 additions & 0 deletions spec/ApiClient/BlogClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class BlogClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_gets_an_article()
{
$request = new Request('GET', 'blog-articles/3',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.blog-article+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.blog-article+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getArticle(['Accept' => 'application/vnd.elife.blog-article+json; version=2'], '3')
->shouldBeLike($response)
;
}

public function it_lists_articles()
{
$request = new Request('GET', 'blog-articles?page=1&per-page=20&order=desc&subject[]=cell-biology',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.blog-article-list+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.blog-article-list+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->listArticles(['Accept' => 'application/vnd.elife.blog-article-list+json; version=2'],
1, 20, true,
['cell-biology'])->shouldBeLike($response)
;
}
}
52 changes: 52 additions & 0 deletions spec/ApiClient/CollectionsClientSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace spec\eLife\ApiSdk\ApiClient;

use eLife\ApiClient\HttpClient;
use eLife\ApiClient\MediaType;
use eLife\ApiClient\Result\ArrayResult;
use eLife\ApiClient\Version;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Request;
use PhpSpec\ObjectBehavior;

final class CollectionsClientSpec extends ObjectBehavior
{
private $httpClient;

public function let(HttpClient $httpClient)
{
$this->httpClient = $httpClient;

$this->beConstructedWith($httpClient, ['X-Foo' => 'bar']);
}

public function it_gets_a_collection()
{
$request = new Request('GET', 'collections/3',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.collection+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.collection+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->getCollection(['Accept' => 'application/vnd.elife.collection+json; version=2'], '3')
->shouldBeLike($response)
;
}

public function it_lists_collections()
{
$request = new Request('GET', 'collections?page=1&per-page=20&order=desc&subject[]=cell-biology&containing[]=article/1234&containing[]=interview/5678',
['X-Foo' => 'bar', 'Accept' => 'application/vnd.elife.collection-list+json; version=2', 'User-Agent' => 'eLifeApiClient/'.Version::get()]);
$response = new FulfilledPromise(new ArrayResult(new MediaType('application/vnd.elife.collection-list+json',
2), ['foo' => ['bar', 'baz']]));

$this->httpClient->send($request)->willReturn($response);

$this->listCollections(['Accept' => 'application/vnd.elife.collection-list+json; version=2'],
1, 20, true,
['cell-biology'], ['article/1234', 'interview/5678'])->shouldBeLike($response)
;
}
}
Loading

0 comments on commit 7e4262e

Please sign in to comment.