@@ 86-122 (lines=37) @@ | ||
83 | * |
|
84 | * @throws Exception |
|
85 | */ |
|
86 | public function create(string $message, string $location, array $hashtags = []) |
|
87 | { |
|
88 | if (empty($message)) { |
|
89 | throw new InvalidArgumentException('Message cannot be empty'); |
|
90 | } |
|
91 | ||
92 | if (empty($location)) { |
|
93 | throw new InvalidArgumentException('Location cannot be empty'); |
|
94 | } |
|
95 | ||
96 | $params = [ |
|
97 | 'message' => $message, |
|
98 | 'location' => $location, |
|
99 | 'hashtags' => $hashtags, |
|
100 | ]; |
|
101 | ||
102 | $response = $this->httpPost('/v1/tweets', $params); |
|
103 | ||
104 | if (!$this->hydrator) { |
|
105 | return $response; |
|
106 | } |
|
107 | ||
108 | // Use any valid status code here |
|
109 | if ($response->getStatusCode() !== 201) { |
|
110 | switch ($response->getStatusCode()) { |
|
111 | case 400: |
|
112 | throw new DomainExceptions\ValidationException(); |
|
113 | break; |
|
114 | ||
115 | default: |
|
116 | $this->handleErrors($response); |
|
117 | break; |
|
118 | } |
|
119 | } |
|
120 | ||
121 | return $this->hydrator->hydrate($response, TweetCreated::class); |
|
122 | } |
|
123 | ||
124 | /** |
|
125 | * @param int $id |
|
@@ 134-170 (lines=37) @@ | ||
131 | * |
|
132 | * @throws Exception |
|
133 | */ |
|
134 | public function update(int $id, string $message, string $location, array $hashtags = []) |
|
135 | { |
|
136 | if (empty($message)) { |
|
137 | throw new InvalidArgumentException('Message cannot be empty'); |
|
138 | } |
|
139 | ||
140 | if (empty($location)) { |
|
141 | throw new InvalidArgumentException('Location cannot be empty'); |
|
142 | } |
|
143 | ||
144 | $params = [ |
|
145 | 'message' => $message, |
|
146 | 'location' => $location, |
|
147 | 'hashtags' => $hashtags, |
|
148 | ]; |
|
149 | ||
150 | $response = $this->httpPut(sprintf('/v1/tweets/%d', $id), $params); |
|
151 | ||
152 | if (!$this->hydrator) { |
|
153 | return $response; |
|
154 | } |
|
155 | ||
156 | // Use any valid status code here |
|
157 | if ($response->getStatusCode() !== 200) { |
|
158 | switch ($response->getStatusCode()) { |
|
159 | case 400: |
|
160 | throw new DomainExceptions\ValidationException(); |
|
161 | break; |
|
162 | ||
163 | default: |
|
164 | $this->handleErrors($response); |
|
165 | break; |
|
166 | } |
|
167 | } |
|
168 | ||
169 | return $this->hydrator->hydrate($response, TweetUpdated::class); |
|
170 | } |
|
171 | ||
172 | /** |
|
173 | * @param int $id |