Completed
Pull Request — master (#19)
by Sergey
03:17
created

Pins::comment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4286
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use seregazhuk\PinterestBot\Helpers\UrlHelper;
6
use seregazhuk\PinterestBot\Helpers\SearchHelper;
7
use seregazhuk\PinterestBot\Helpers\Requests\PinHelper;
8
9
class Pins extends Provider
10
{
11
    use SearchHelper;
12
13
    /**
14
     * Likes pin with current ID
15
     *
16
     * @param integer $pinId
17
     * @return bool
18
     */
19
    public function like($pinId)
20
    {
21
        return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_LIKE_PIN);
22
    }
23
24
    /**
25
     * Removes your like from pin with current ID
26
     *
27
     * @param integer $pinId
28
     * @return bool
29
     */
30
    public function unLike($pinId)
31
    {
32
        return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_UNLIKE_PIN);
33
    }
34
35
    /**
36
     * Calls pinterest API to like or unlike Pin by ID
37
     *
38
     * @param $pinId
39
     * @param $url
40
     * @return bool
41
     */
42
    protected function likePinMethodCall($pinId, $url)
43
    {
44
        $this->request->checkLoggedIn();
45
        $data = PinHelper::createPinIdRequest($pinId);
46
        $post = PinHelper::createPinRequestData($data);
47
        $postString = URlHelper::buildRequestString($post);
48
        $response = $this->request->exec($url, $postString);
49
        return $this->response->checkErrorInResponse($response);
50
    }
51
52
    /**
53
     * Writes comment for pin with current id
54
     *
55
     * @param integer $pinId
56
     * @param string  $text Comment
57
     * @return array
58
     */
59 View Code Duplication
    public function comment($pinId, $text)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $this->request->checkLoggedIn();
62
        $post = PinHelper::createCommentRequest($pinId, $text);
63
        $postString = UrlHelper::buildRequestString($post);
64
        $response = $this->request->exec(UrlHelper::RESOURCE_COMMENT_PIN, $postString);
65
        return $this->response->getData($response);
66
    }
67
68
    /**
69
     * Writes comment for pin with current id
70
     *
71
     * @param integer $pinId
72
     * @param integer $commentId
73
     * @return bool
74
     */
75 View Code Duplication
    public function deleteComment($pinId, $commentId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $this->request->checkLoggedIn();
78
        $post = PinHelper::createCommentDeleteRequest($pinId, $commentId);
79
        $postString = UrlHelper::buildRequestString($post);
80
        $response = $this->request->exec(UrlHelper::RESOURCE_COMMENT_DELETE_PIN, $postString);
81
82
        return $this->response->checkErrorInResponse($response);
83
    }
84
85
    /**
86
     * Create pin. Returns created pin ID
87
     *
88
     * @param string $imageUrl
89
     * @param int    $boardId
90
     * @param string $description
91
     * @return bool|int
92
     */
93
    public function create($imageUrl, $boardId, $description = "")
94
    {
95
        $this->request->checkLoggedIn();
96
        $post = PinHelper::createPinCreationRequest($imageUrl, $boardId, $description);
97
        $postString = UrlHelper::buildRequestString($post);
98
        $res = $this->request->exec(UrlHelper::RESOURCE_CREATE_PIN, $postString);
99
100
        return $this->response->getData($res, 'id');
101
    }
102
103
    /**
104
     * Repin
105
     *
106
     * @param int    $repinId
107
     * @param int    $boardId
108
     * @param string $description
109
     * @return bool|int
110
     */
111
    public function repin($repinId, $boardId, $description = "")
112
    {
113
        $this->request->checkLoggedIn();
114
115
        $post = PinHelper::createRepinRequest($repinId, $boardId, $description);
116
        $postString = UrlHelper::buildRequestString($post);
117
        $res = $this->request->exec(UrlHelper::RESOURCE_REPIN, $postString);
118
119
        return $this->response->getData($res, 'id');
120
    }
121
122
    /**
123
     * Delete pin
124
     *
125
     * @param int $pinId
126
     * @return bool
127
     */
128 View Code Duplication
    public function delete($pinId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $this->request->checkLoggedIn();
131
132
        $post = PinHelper::createSimplePinRequest($pinId);
133
        $postString = UrlHelper::buildRequestString($post);
134
        $response = $this->request->exec(UrlHelper::RESOURCE_DELETE_PIN, $postString);
135
        return $this->response->checkResponse($response);
136
    }
137
138
    /**
139
     * Get information of pin by PinID
140
     *
141
     * @param $pinId
142
     * @return array|bool
143
     */
144 View Code Duplication
    public function info($pinId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $get = PinHelper::createInfoRequest($pinId);
147
        $url = UrlHelper::RESOURCE_PIN_INFO.'?'.UrlHelper::buildRequestString($get);
148
        $response = $this->request->exec($url);
149
150
        return $this->response->checkResponse($response);
151
    }
152
153
154
    protected function getScope()
155
    {
156
        return 'pins';
157
    }
158
}
159