1+ <?php
2+ namespace RocketAPI ;
3+
4+ class InstagramAPI extends RocketAPI {
5+ public function __construct ($ token )
6+ {
7+ parent ::__construct ($ token );
8+ }
9+
10+ /**
11+ * @throws NotFoundException
12+ * @throws BadResponseException
13+ */
14+ protected function request ($ method , $ data )
15+ {
16+ $ response = parent ::request ($ method , $ data );
17+ if ($ response ['status ' ] == 'done ' ) {
18+ if ($ response ['response ' ]['status_code ' ] == 200 && $ response ['response ' ]['content_type ' ] == 'application/json ' ) {
19+ return $ response ['response ' ]['body ' ];
20+ } else if ($ response ['response ' ]['status_code ' ] == 404 ) {
21+ throw new NotFoundException ('Instagram resource not found ' );
22+ } else {
23+ throw new BadResponseException ('Bad response from Instagram ' );
24+ }
25+ } else {
26+ throw new BadResponseException ('Bad response from RocketAPI ' );
27+ }
28+ }
29+
30+ /**
31+ * @throws NotFoundException
32+ * @throws BadResponseException
33+ */
34+ public function search ($ query ) {
35+ return $ this ->request ('instagram/search ' , [
36+ 'query ' => $ query ,
37+ ]);
38+ }
39+
40+ /**
41+ * @throws NotFoundException
42+ * @throws BadResponseException
43+ */
44+ public function getUserInfo ($ username ) {
45+ return $ this ->request ('instagram/user/get_info ' , [
46+ 'username ' => $ username ,
47+ ]);
48+ }
49+
50+ /**
51+ * @throws NotFoundException
52+ * @throws BadResponseException
53+ */
54+ public function getUserInfoById ($ user_id ) {
55+ return $ this ->request ('instagram/user/get_info_by_id ' , [
56+ 'id ' => $ user_id ,
57+ ]);
58+ }
59+
60+ /**
61+ * @throws NotFoundException
62+ * @throws BadResponseException
63+ */
64+ public function getUserMedia ($ user_id , $ count =12 , $ max_id =null ) {
65+ $ payload = ['id ' => $ user_id , 'count ' => $ count ];
66+ if ($ max_id ) {
67+ $ payload ['max_id ' ] = $ max_id ;
68+ }
69+ return $ this ->request ('instagram/user/get_media ' , $ payload );
70+ }
71+
72+ /**
73+ * @throws NotFoundException
74+ * @throws BadResponseException
75+ */
76+ public function getUserFollowing ($ user_id , $ count =12 , $ max_id =null ) {
77+ $ payload = ['id ' => $ user_id , 'count ' => $ count ];
78+ if ($ max_id ) {
79+ $ payload ['max_id ' ] = $ max_id ;
80+ }
81+ return $ this ->request ('instagram/user/get_following ' , $ payload );
82+ }
83+
84+ /**
85+ * @throws NotFoundException
86+ * @throws BadResponseException
87+ */
88+ public function getUserFollowers ($ user_id , $ count =12 , $ max_id =null )
89+ {
90+ $ payload = ['id ' => $ user_id , 'count ' => $ count ];
91+ if ($ max_id ) {
92+ $ payload ['max_id ' ] = $ max_id ;
93+ }
94+ return $ this ->request ('instagram/user/get_followers ' , $ payload );
95+ }
96+
97+ /**
98+ * @throws NotFoundException
99+ * @throws BadResponseException
100+ */
101+ public function searchUserFollowers ($ user_id , $ query ) {
102+ return $ this ->request ('instagram/user/get_followers ' , [
103+ 'id ' => $ user_id ,
104+ 'query ' => $ query ,
105+ ]);
106+ }
107+
108+ /**
109+ * @throws NotFoundException
110+ * @throws BadResponseException
111+ */
112+ public function getUserStoriesBulk ($ user_ids ) {
113+ return $ this ->request ('instagram/user/get_stories ' , [
114+ 'ids ' => $ user_ids ,
115+ ]);
116+ }
117+
118+ /**
119+ * @throws NotFoundException
120+ * @throws BadResponseException
121+ */
122+ public function getUserStories ($ user_id ) {
123+ return $ this ->getUserStoriesBulk ([$ user_id ]);
124+ }
125+
126+ /**
127+ * @throws NotFoundException
128+ * @throws BadResponseException
129+ */
130+ public function getMediaInfo ($ media_id ) {
131+ return $ this ->request ('instagram/media/get_info ' , [
132+ 'id ' => $ media_id ,
133+ ]);
134+ }
135+
136+ /**
137+ * @throws NotFoundException
138+ * @throws BadResponseException
139+ */
140+ public function getMediaLikes ($ shortcode , $ count =12 , $ max_id =null ) {
141+ $ payload = ['shortcode ' => $ shortcode , 'count ' => $ count ];
142+ if ($ max_id ) {
143+ $ payload ['max_id ' ] = $ max_id ;
144+ }
145+ return $ this ->request ('instagram/media/get_likes ' , $ payload );
146+ }
147+
148+ /**
149+ * @throws NotFoundException
150+ * @throws BadResponseException
151+ */
152+ public function getMediaComments ($ media_id , $ can_support_threading =true , $ min_id =null ) {
153+ $ payload = ['id ' => $ media_id , 'can_support_threading ' => $ can_support_threading ];
154+ if ($ min_id ) {
155+ $ payload ['min_id ' ] = $ min_id ;
156+ }
157+ return $ this ->request ('instagram/media/get_comments ' , $ payload );
158+ }
159+
160+ /**
161+ * @throws NotFoundException
162+ * @throws BadResponseException
163+ */
164+ public function getCommentLikes ($ comment_id , $ max_id =null ) {
165+ $ payload = ['id ' => $ comment_id ];
166+ if ($ max_id ) {
167+ $ payload ['max_id ' ] = $ max_id ;
168+ }
169+ return $ this ->request ('instagram/comment/get_likes ' , $ payload );
170+ }
171+ }
0 commit comments