DirectMessage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveLatestMessages() 0 12 1
A retrieveLatestSentMessages() 0 12 1
1
<?php
2
namespace Wheedle;
3
4
use \GuzzleHttp\Exception\ClientException;
5
6
/**
7
 * A collection of convenience methods for the direct message endpoints for
8
 * the twitter API
9
 *
10
 * @author Matt Frost <[email protected]>
11
 * @package Wheedle
12
 * @license MIT http://opensource.org/licenses/MIT
13
 */
14
class DirectMessage
15
{
16
    /**
17
     * ENDPOINT CONSTANTS
18
     */
19
    const RETRIEVE_MESSAGES_ENDPOINT = 'direct_messages.json';
20
    const RETRIEVE_SENT_MESSAGES_ENDPOINT = 'direct_messages/sent.json';
21
22
    use OptionsFilter;
23
24
    /**
25
     * Twitter Client, needed for making requests
26
     *
27
     * @var TwitterClient $client
28
     */
29
    private $client;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param TwitterClient $client
35
     */
36
    public function __construct(TwitterClient $client)
37
    {
38
        $this->client = $client;
39
    }
40
41
    /**
42
     * Method to retrieve the most recent direct messages sent to the
43
     * authenticated user
44
     *
45
     * @param Array $options
46
     *   - since_id int returns results with an ID more recent than the provided ID
47
     *   - max_id int returns results with an ID older than the provided ID
48
     *   - count int number of results to return, up to 200, if omitted returns 20
49
     *   - include_entities boolean entities node will be excluded when set to false
50
     *   - skip_status boolean statues will not be returned with the user objects when true
51
     * @return string
52
     */
53
    public function retrieveLatestMessages(Array $options = [])
54
    {
55
        $availableOptions = [
56
            'since_id',
57
            'max_id',
58
            'count',
59
            'include_entities',
60
            'skip_status'
61
        ];
62
        $options = $this->filterOptions($availableOptions, $options);
63
        return $this->client->makeGetRequest(self::RETRIEVE_MESSAGES_ENDPOINT, $options);
64
    }
65
66
    /**
67
     * Method to retrieve the most recent direct messages sent from the
68
     * authenticated user
69
     *
70
     * @param Array $options
71
     *   - since_id int returns results with an ID more recent than the provided ID
72
     *   - max_id int returns results with an ID older than the provided ID
73
     *   - count int number of results to return, up to 200, if omitted returns 20
74
     *   - include_entities boolean entities node will be excluded when set to false
75
     *   - page int the page of results to retrieve
76
     * @return string
77
     */
78
    public function retrieveLatestSentMessages(Array $options = [])
79
    {
80
        $availableOptions = [
81
            'since_id',
82
            'max_id',
83
            'count',
84
            'include_entities',
85
            'page'
86
        ];
87
        $options = $this->filterOptions($availableOptions, $options);
88
        return $this->client->makeGetRequest(self::RETRIEVE_SENT_MESSAGES_ENDPOINT, $options);
89
    }
90
}
91