Completed
Push — master ( a2b906...d5b295 )
by Peter
03:27
created

IronMQ::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PeterColes\Cluster\Queues\Adapters;
4
5
use PeterColes\Cluster\Contracts\Adapter;
6
use PeterColes\Cluster\Contracts\QueueAdapterInterface;
7
8
class IronMQ extends Adapter implements QueueAdapterInterface
9
{
10
    /**
11
     * The endpoint for all API calls to Digital Ocean (currently at v2)
12
     */
13
    // @todo support for all regions
14
    protected $apiEndpoint = 'https://mq-aws-us-east-1.iron.io/1';
15
16
    /**
17
     * List details for an indexed server, or all servers if id is null.
18
     *
19
     * @param string $queue
20
     * @return integer
21
     */
22
    public function count($queue)
23
    {
24
        // @todo remove hard-coded project
25
        $response = $this->client->request->get(
26
            $this->apiEndpoint.'/projects/'.$this->params['project'].'/queues/'.$queue
27
        );
28
29
        return $this->client->getBody($response);
30
    }
31
32
    /**
33
     * Receives the name of a queue and clears it.
34
     *
35
     * @param string $queue
36
     * @return void
37
     */
38
    public function clear($queue)
39
    {
40
        $this->client->request->post(
41
            $this->apiEndpoint.'/projects/'.$this->params['project'].'/queues/'.$queue.'/clear'
42
        );
43
    }
44
45
    /**
46
     * Construct http client request headers.
47
     *
48
     * @return void
49
     */
50
    protected function setHeaders()
51
    {
52
        parent::setHeaders();
53
54
        $this->headers['headers']['Authorization'] = 'OAuth '.$this->params['token'];
55
    }
56
}
57