1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
declare ( strict_types = 1 );
|
4
|
|
|
|
5
|
|
|
namespace Ch0c01dxyz\InstaToken\Endpoints;
|
6
|
|
|
|
7
|
|
|
use Http\Client\HttpClient;
|
8
|
|
|
use Http\Discovery\HttpClientDiscovery;
|
9
|
|
|
use Http\Discovery\MessageFactoryDiscovery;
|
10
|
|
|
use Http\Message\RequestFactory;
|
11
|
|
|
use Ch0c01dxyz\InstaToken\Objects\AccessToken;
|
12
|
|
|
use Ch0c01dxyz\InstaToken\Objects\TagName;
|
13
|
|
|
use Ch0c01dxyz\InstaToken\Interfaces\TagInterface;
|
14
|
|
|
use Ch0c01dxyz\InstaToken\Exceptions\TagException;
|
15
|
|
|
|
16
|
|
|
/**
|
17
|
|
|
* @author Egar Rizki <[email protected]>
|
18
|
|
|
*/
|
19
|
|
|
class Tag implements TagInterface
|
20
|
|
|
{
|
21
|
|
|
/**
|
22
|
|
|
* @var \Ch0c01dxyz\InstaToken\AccessToken
|
|
|
|
|
23
|
|
|
*/
|
24
|
|
|
protected $accessToken;
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* @var \Http\Client\HttpClient
|
28
|
|
|
*/
|
29
|
|
|
protected $httpClient;
|
30
|
|
|
|
31
|
|
|
/**
|
32
|
|
|
* @var \Http\Message\RequestFactory
|
33
|
|
|
*/
|
34
|
|
|
protected $requestFactory;
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* New instance of Tag class
|
38
|
|
|
*
|
39
|
|
|
* @param \Http\Client\HttpClient|null $httpClient
|
40
|
|
|
* @param \Http\Message\RequestFactory|null $requestFactory
|
41
|
|
|
*/
|
42
|
4 |
|
public function __construct ( HttpClient $httpClient = null, RequestFactory $requestFactory = null )
|
43
|
|
|
{
|
44
|
4 |
|
$this->httpClient = $httpClient ?: HttpClientDiscovery::find ();
|
45
|
|
|
|
46
|
4 |
|
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find ();
|
47
|
4 |
|
}
|
48
|
|
|
|
49
|
|
|
/**
|
50
|
|
|
* @param Access Token Setter
|
|
|
|
|
51
|
|
|
*/
|
52
|
3 |
|
public function setToken ( $token )
|
53
|
|
|
{
|
54
|
3 |
|
$this->accessToken = new AccessToken ( $token );
|
|
|
|
|
55
|
3 |
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* @return Access Token Getter
|
|
|
|
|
59
|
|
|
*/
|
60
|
|
|
public function getToken () : AccessToken
|
61
|
|
|
{
|
62
|
|
|
return $this->accessToken;
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* Get recent Tag Media
|
67
|
|
|
*
|
68
|
|
|
* @param string $tagName
|
69
|
|
|
* @return array
|
70
|
|
|
*/
|
71
|
1 |
|
public function listTag ( TagName $tagName ) : array
|
72
|
|
|
{
|
73
|
1 |
|
if ( false === ( $tagName instanceof TagName ) )
|
74
|
|
|
{
|
75
|
|
|
throw new TagException ( "Current param isn't instance of TagName." );
|
76
|
|
|
}
|
77
|
|
|
|
78
|
1 |
|
$uri = sprintf ( "https://api.instagram.com/v1/tags/%s?access_token=%s", $tagName, $this->accessToken );
|
79
|
|
|
|
80
|
1 |
|
$request = $this->requestFactory->createRequest ( "GET", $uri );
|
81
|
|
|
|
82
|
1 |
|
$response = $this->httpClient->sendRequest ( $request );
|
83
|
|
|
|
84
|
1 |
|
if ( $response->getStatusCode () === 400 )
|
85
|
|
|
{
|
86
|
|
|
$body = json_decode ( ( string ) $response->getBody () );
|
87
|
|
|
|
88
|
|
|
throw new TagException ( $body->meta->error_message );
|
89
|
|
|
}
|
90
|
|
|
|
91
|
1 |
|
return json_decode ( ( string ) $response->getBody ()->getContents (), true );
|
92
|
|
|
}
|
93
|
|
|
|
94
|
|
|
/**
|
95
|
|
|
* Get Information about Tag object
|
96
|
|
|
*
|
97
|
|
|
* @param string $tagName
|
98
|
|
|
* @return array
|
99
|
|
|
*/
|
100
|
1 |
|
public function infoTag ( TagName $tagName ) : array
|
101
|
|
|
{
|
102
|
1 |
|
if ( false === ( $tagName instanceof TagName ) )
|
103
|
|
|
{
|
104
|
|
|
throw new TagException ( "Current param isn't instance of TagName." );
|
105
|
|
|
}
|
106
|
|
|
|
107
|
1 |
|
$uri = sprintf ( "https://api.instagram.com/v1/tags/%s/media/recent?access_token=%s", $tagName, $this->accessToken );
|
108
|
|
|
|
109
|
1 |
|
$request = $this->requestFactory->createRequest ( "GET", $uri );
|
110
|
|
|
|
111
|
1 |
|
$response = $this->httpClient->sendRequest ( $request );
|
112
|
|
|
|
113
|
1 |
|
if ( $response->getStatusCode () === 400 )
|
114
|
|
|
{
|
115
|
|
|
$body = json_decode ( ( string ) $response->getBody () );
|
116
|
|
|
|
117
|
|
|
throw new TagException ( $body->meta->error_message );
|
118
|
|
|
}
|
119
|
|
|
|
120
|
1 |
|
return json_decode ( ( string ) $response->getBody ()->getContents (), true );
|
121
|
|
|
}
|
122
|
|
|
|
123
|
|
|
/**
|
124
|
|
|
* Search tag by Name
|
125
|
|
|
*
|
126
|
|
|
* @param string $tagName
|
127
|
|
|
* @return array
|
128
|
|
|
*/
|
129
|
1 |
|
public function searchTag ( TagName $tagName ) : array
|
130
|
|
|
{
|
131
|
1 |
|
if ( false === ( $tagName instanceof TagName ) )
|
132
|
|
|
{
|
133
|
|
|
throw new TagException ( "Current param isn't instance of TagName." );
|
134
|
|
|
}
|
135
|
|
|
|
136
|
1 |
|
$uri = sprintf ( "https://api.instagram.com/v1/tags/search?q=%s&access_token=%s", $tagName, $this->accessToken );
|
137
|
|
|
|
138
|
1 |
|
$request = $this->requestFactory->createRequest ( "GET", $uri );
|
139
|
|
|
|
140
|
1 |
|
$response = $this->httpClient->sendRequest ( $request );
|
141
|
|
|
|
142
|
1 |
|
if ( $response->getStatusCode () === 400 )
|
143
|
|
|
{
|
144
|
|
|
$body = json_decode ( ( string ) $response->getBody () );
|
145
|
|
|
|
146
|
|
|
throw new TagException ( $body->meta->error_message );
|
147
|
|
|
}
|
148
|
|
|
|
149
|
1 |
|
return json_decode ( ( string ) $response->getBody ()->getContents (), true );
|
150
|
|
|
}
|
151
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths