Passed
Branch main (d68b9c)
by smiley
09:54
created

Discogs   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 22
c 1
b 0
f 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRequestToken() 0 19 1
1
<?php
2
/**
3
 * Class Discogs
4
 *
5
 * @link https://www.discogs.com/developers/
6
 * @link https://www.discogs.com/developers/#page:authentication,header:authentication-oauth-flow
7
 *
8
 * @filesource   Discogs.php
9
 * @created      08.04.2018
10
 * @package      chillerlan\OAuth\Providers\Discogs
11
 * @author       Smiley <[email protected]>
12
 * @copyright    2018 Smiley
13
 * @license      MIT
14
 */
15
16
namespace chillerlan\OAuth\Providers\Discogs;
17
18
use chillerlan\OAuth\Core\{AccessToken, OAuth1Provider};
19
use DateTime;
20
21
use function chillerlan\HTTP\Psr7\build_http_query;
22
23
/**
24
 * @method \Psr\Http\Message\ResponseInterface artist(string $artist_id)
25
 * @method \Psr\Http\Message\ResponseInterface artistReleases(string $artist_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
26
 * @method \Psr\Http\Message\ResponseInterface collectionCreateFolder(string $username, array $body = ['name'])
27
 * @method \Psr\Http\Message\ResponseInterface collectionDeleteFolder(string $username, string $folder_id)
28
 * @method \Psr\Http\Message\ResponseInterface collectionFields(string $username)
29
 * @method \Psr\Http\Message\ResponseInterface collectionFolder(string $username, string $folder_id)
30
 * @method \Psr\Http\Message\ResponseInterface collectionFolderAddRelease(string $username, string $folder_id, string $release_id)
31
 * @method \Psr\Http\Message\ResponseInterface collectionFolderRateRelease(string $username, string $folder_id, string $release_id, string $instance_id, array $body = ['rating'])
32
 * @method \Psr\Http\Message\ResponseInterface collectionFolderReleases(string $username, string $folder_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
33
 * @method \Psr\Http\Message\ResponseInterface collectionFolderRemoveRelease(string $username, string $folder_id, string $release_id, string $instance_id)
34
 * @method \Psr\Http\Message\ResponseInterface collectionFolderUpdateReleaseField(string $username, string $folder_id, string $release_id, string $instance_id, string $field_id, array $body = ['value'])
35
 * @method \Psr\Http\Message\ResponseInterface collectionFolders(string $username)
36
 * @method \Psr\Http\Message\ResponseInterface collectionRelease(string $username, string $release_id)
37
 * @method \Psr\Http\Message\ResponseInterface collectionUpdateFolder(string $username, string $folder_id, array $body = ['name'])
38
 * @method \Psr\Http\Message\ResponseInterface collectionValue(string $username)
39
 * @method \Psr\Http\Message\ResponseInterface contributions(string $username, array $params = ['page', 'per_page', 'sort', 'sort_order'])
40
 * @method \Psr\Http\Message\ResponseInterface identity()
41
 * @method \Psr\Http\Message\ResponseInterface inventory(string $username, array $params = ['page', 'per_page', 'status', 'sort', 'sort_order'])
42
 * @method \Psr\Http\Message\ResponseInterface label(string $label_id)
43
 * @method \Psr\Http\Message\ResponseInterface labelReleases(string $label_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
44
 * @method \Psr\Http\Message\ResponseInterface list(string $list_id)
45
 * @method \Psr\Http\Message\ResponseInterface lists(string $username)
46
 * @method \Psr\Http\Message\ResponseInterface marketplaceCreateListing(array $body = ['release_id', 'condition', 'sleeve_condition', 'price', 'comments', 'allow_offers', 'status', 'external_id', 'location', 'weight', 'format_quantity'])
47
 * @method \Psr\Http\Message\ResponseInterface marketplaceFee(string $price)
48
 * @method \Psr\Http\Message\ResponseInterface marketplaceFeeCurrency(string $price, string $currency)
49
 * @method \Psr\Http\Message\ResponseInterface marketplaceListing(string $listing_id, array $params = ['curr_abbr'])
50
 * @method \Psr\Http\Message\ResponseInterface marketplaceOrder(string $order_id)
51
 * @method \Psr\Http\Message\ResponseInterface marketplaceOrderAddMessage(string $order_id, array $body = ['message', 'status'])
52
 * @method \Psr\Http\Message\ResponseInterface marketplaceOrderMessages(string $order_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
53
 * @method \Psr\Http\Message\ResponseInterface marketplaceOrders(array $params = ['status', 'page', 'per_page', 'sort', 'sort_order'])
54
 * @method \Psr\Http\Message\ResponseInterface marketplaceRemoveListing(string $listing_id)
55
 * @method \Psr\Http\Message\ResponseInterface marketplaceUpdateListing(string $listing_id, array $body = ['release_id', 'condition', 'sleeve_condition', 'price', 'comments', 'allow_offers', 'status', 'external_id', 'location', 'weight', 'format_quantity'])
56
 * @method \Psr\Http\Message\ResponseInterface marketplaceUpdateOrder(string $order_id, array $body = ['status', 'shipping'])
57
 * @method \Psr\Http\Message\ResponseInterface master(string $master_id)
58
 * @method \Psr\Http\Message\ResponseInterface masterVersions(string $master_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
59
 * @method \Psr\Http\Message\ResponseInterface profile(string $username)
60
 * @method \Psr\Http\Message\ResponseInterface profileUpdate(string $username, array $body = ['name', 'home_page', 'location', 'profile', 'curr_abbr'])
61
 * @method \Psr\Http\Message\ResponseInterface release(string $release_id, array $params = ['curr_abbr'])
62
 * @method \Psr\Http\Message\ResponseInterface releasePriceSuggestion(string $release_id)
63
 * @method \Psr\Http\Message\ResponseInterface releaseRating(string $release_id)
64
 * @method \Psr\Http\Message\ResponseInterface releaseRemoveUserRating(string $release_id, string $username)
65
 * @method \Psr\Http\Message\ResponseInterface releaseUpdateUserRating(string $release_id, string $username, array $params = ['rating'])
66
 * @method \Psr\Http\Message\ResponseInterface releaseUserRating(string $release_id, string $username)
67
 * @method \Psr\Http\Message\ResponseInterface search(array $params = ['q', 'query', 'type', 'title', 'release_title', 'credit', 'artist', 'anv', 'label', 'genre', 'style', 'country', 'year', 'format', 'catno', 'barcode', 'track', 'submitter', 'contributor'])
68
 * @method \Psr\Http\Message\ResponseInterface submissions(string $username, array $params = ['page', 'per_page', 'sort', 'sort_order'])
69
 * @method \Psr\Http\Message\ResponseInterface wantlist(string $username, array $params = ['page', 'per_page', 'sort', 'sort_order'])
70
 * @method \Psr\Http\Message\ResponseInterface wantlistAdd(string $username, string $release_id, array $body = ['notes', 'rating'])
71
 * @method \Psr\Http\Message\ResponseInterface wantlistRemove(string $username, string $release_id)
72
 * @method \Psr\Http\Message\ResponseInterface wantlistUpdate(string $username, string $release_id, array $body = ['notes', 'rating'])
73
 */
74
class Discogs extends OAuth1Provider{
75
76
	protected string $requestTokenURL = 'https://api.discogs.com/oauth/request_token';
77
	protected string $authURL         = 'https://www.discogs.com/oauth/authorize';
78
	protected string $accessTokenURL  = 'https://api.discogs.com/oauth/access_token';
79
	protected ?string $apiURL         = 'https://api.discogs.com';
80
	protected ?string $revokeURL      = 'https://www.discogs.com/oauth/revoke'; // ?access_key=<TOKEN>
81
	protected ?string $userRevokeURL  = 'https://www.discogs.com/settings/applications';
82
	protected ?string $endpointMap    = DiscogsEndpoints::class;
83
	protected ?string $apiDocs        = 'https://www.discogs.com/developers/';
84
	protected ?string $applicationURL = 'https://www.discogs.com/settings/developers';
85
	protected array $apiHeaders       = ['Accept' => 'application/vnd.discogs.v2.discogs+json'];
86
87
	/**
88
	 * @return \chillerlan\OAuth\Core\AccessToken
89
	 */
90
	public function getRequestToken():AccessToken{
91
92
		$params = [
93
			'oauth_callback'         => $this->options->callbackURL,
94
			'oauth_consumer_key'     => $this->options->key,
95
			'oauth_nonce'            => $this->nonce(),
96
			'oauth_signature'        => $this->options->secret.'&',
97
			'oauth_signature_method' => 'PLAINTEXT',
98
			'oauth_timestamp'        => (new DateTime)->format('U'),
99
		];
100
101
		$params['oauth_signature'] = $this->getSignature($this->requestTokenURL, $params, 'POST');
102
103
		$request = $this->requestFactory
104
			->createRequest('POST', $this->requestTokenURL)
105
			->withHeader('Authorization', 'OAuth '.build_http_query($params, true, ', ', '"'));
106
		;
107
108
		return $this->parseTokenResponse($this->http->sendRequest($request), true);
109
	}
110
111
}
112