Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Jan 31, 2020
1 parent de8bf6d commit 9e7d463
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
26 changes: 9 additions & 17 deletions composer.json
@@ -1,5 +1,5 @@
{
"name": "pixelfed/php-sdk",
"name": "dansup/pixelfed-php",
"description": "Pixelfed PHP SDK",
"keywords": [
"pixelfed",
Expand All @@ -8,7 +8,7 @@
"fediverse",
"library"
],
"homepage": "https://github.com/pixelfed/pixelfed-php",
"homepage": "https://github.com/dansup/pixelfed-php",
"license": "AGPL-3.0-only",
"authors": [
{
Expand All @@ -18,20 +18,22 @@
}
],
"require": {
"php": "^7.3"
"php": "^7.2",
"kitetail/zttp": "^0.6.0",
"guzzlehttp/guzzle": "^6.5"
},
"require-dev": {
"symfony/var-dumper": "^4.3",
"phpunit/phpunit": "^8.2"
"phpunit/phpunit": "^8.2",
"symfony/var-dumper": "^4.3"
},
"autoload": {
"psr-4": {
"Pixelfed\\Api\\": "src"
"Pixelfed\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Pixelfed\\Api\\Tests\\": "tests"
"Pixelfed\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -40,15 +42,5 @@
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Pixelfed\\Api\\ApiServiceProvider"
],
"aliases": {
"Api": "Pixelfed\\Api\\ApiFacade"
}
}
}
}
8 changes: 0 additions & 8 deletions src/Api.php

This file was deleted.

60 changes: 60 additions & 0 deletions src/PixelfedApi.php
@@ -0,0 +1,60 @@
<?php

namespace Pixelfed;

use \Zttp\Zttp;

class PixelfedApi
{
protected $domain;
protected $client;
protected $curl;

public function __construct(string $domain, $accessToken = null)
{
$this->domain = $domain;
$this->client = !$accessToken ? Zttp::new() : Zttp::new()->withHeaders([
'Authorization' => "Bearer {$accessToken}"
]);
}

protected function furl(string $url)
{
$this->curl = $this->domain . $url;
}

public function user()
{
$this->furl("/api/v1/accounts/verify_credentials");
return $this->get();
}

public function accountById(string $id)
{
$this->furl("/api/v1/accounts/{$id}");
return $this->get();
}

public function accountFollowersById(string $id)
{
$this->furl("/api/v1/accounts/{$id}/followers");
return $this->get();
}

public function accountFollowingById(string $id)
{
$this->furl("/api/v1/accounts/{$id}/following");
return $this->get();
}

public function accountStatusesById(string $id)
{
$this->furl("/api/v1/accounts/{$id}/statuses");
return $this->get();
}

protected function get()
{
return $this->client->get($this->curl)->json();
}
}

0 comments on commit 9e7d463

Please sign in to comment.