1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2022 Justin Stolpe.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ namespace Instagram \Comment ;
25
+
26
+ // other classes we need to use
27
+ use Instagram \Instagram ;
28
+ use Instagram \Request \Params ;
29
+ use Instagram \Request \Fields ;
30
+
31
+ /**
32
+ * Comment
33
+ *
34
+ * Get comments on a specific media.
35
+ * - Endpoint Format: GET /{ig-comment-id}?fields={fields}&access_token={access-token}
36
+ * - Endpoint Format: POST /{ig-comment-id}?hide={hide}&access_token={access-token}
37
+ * - Endpoint Format: DELETE /{ig-comment-id}?access_token={access-token}
38
+ * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-comment
39
+ *
40
+ * @package instagram-graph-api
41
+ * @author Justin Stolpe
42
+ * @link https://github.com/jstolpe/instagram-graph-api
43
+ * @license https://opensource.org/licenses/MIT
44
+ * @version 1.0
45
+ */
46
+ class Comment extends Instagram {
47
+ /**
48
+ * @var integer $commentId Instagram id of the comment.
49
+ */
50
+ protected $ commentId ;
51
+
52
+ /**
53
+ * Contructor for instantiating a new object.
54
+ *
55
+ * @param array $config for the class.
56
+ * @return void
57
+ */
58
+ public function __construct ( $ config ) {
59
+ // call parent for setup
60
+ parent ::__construct ( $ config );
61
+
62
+ // store the user id
63
+ $ this ->commentId = $ config ['comment_id ' ];
64
+ }
65
+
66
+ /**
67
+ * Get a comment.
68
+ *
69
+ * @param array $params params for the GET request.
70
+ * @return Instagram response.
71
+ */
72
+ public function getSelf ( $ params = array () ) {
73
+ $ getParams = array ( // parameters for our endpoint
74
+ 'endpoint ' => '/ ' . $ this ->commentId ,
75
+ 'params ' => $ this ->getParams ( $ params )
76
+ );
77
+
78
+ // ig get request
79
+ $ response = $ this ->get ( $ getParams );
80
+
81
+ // return response
82
+ return $ response ;
83
+ }
84
+
85
+ /**
86
+ * Get params for the request.
87
+ *
88
+ * @param array $params specific params for the request.
89
+ * @return array of params for the request.
90
+ */
91
+ public function getParams ( $ params = array () ) {
92
+ if ( $ params ) { // specific params have been requested
93
+ return $ params ;
94
+ } else { // get all params
95
+ // get field params
96
+ $ params [Params::FIELDS ] = Fields::getDefaultCommentFields () . ', ' .
97
+ Fields::REPLIES . '{ ' .
98
+ Fields::getDefaultCommentFields () .
99
+ '} '
100
+ ;
101
+
102
+ // return our params
103
+ return $ params ;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Set hide parameter on a comment.
109
+ *
110
+ * @param boolean $hide show or hide the comment with true|false.
111
+ * @return Instagram Response.
112
+ */
113
+ public function setHide ( $ hide ) {
114
+ $ postParams = array ( // parameters for our endpoint
115
+ 'endpoint ' => '/ ' . $ this ->commentId ,
116
+ 'params ' => array (
117
+ Params::HIDE => $ hide
118
+ )
119
+ );
120
+
121
+ // ig get request
122
+ $ response = $ this ->post ( $ postParams );
123
+
124
+ // return response
125
+ return $ response ;
126
+ }
127
+
128
+ /**
129
+ * Delete a comment.
130
+ *
131
+ * @return Instagram Response.
132
+ */
133
+ public function remove () {
134
+ $ postParams = array ( // parameters for our endpoint
135
+ 'endpoint ' => '/ ' . $ this ->commentId
136
+ );
137
+
138
+ // ig get request
139
+ $ response = $ this ->delete ( $ postParams );
140
+
141
+ // return response
142
+ return $ response ;
143
+ }
144
+ }
145
+
146
+ ?>
0 commit comments