summaryrefslogtreecommitdiffstats
path: root/Twilio/Rest/Monitor/V1/EventInstance.php
blob: 50ea98e8731fea5c0cdd28118ead286baae72403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

/**
 * This code was generated by
 * \ / _    _  _|   _  _
 * | (_)\/(_)(_|\/| |(/_  v1.0.0
 * /       /
 */

namespace Twilio\Rest\Monitor\V1;

use Twilio\Deserialize;
use Twilio\Exceptions\TwilioException;
use Twilio\InstanceResource;
use Twilio\Version;

/**
 * @property string accountSid
 * @property string actorSid
 * @property string actorType
 * @property string description
 * @property string eventData
 * @property \DateTime eventDate
 * @property string eventType
 * @property string resourceSid
 * @property string resourceType
 * @property string sid
 * @property string source
 * @property string sourceIpAddress
 */
class EventInstance extends InstanceResource {
    /**
     * Initialize the EventInstance
     * 
     * @param \Twilio\Version $version Version that contains the resource
     * @param mixed[] $payload The response payload
     * @param string $sid The sid
     * @return \Twilio\Rest\Monitor\V1\EventInstance 
     */
    public function __construct(Version $version, array $payload, $sid = null) {
        parent::__construct($version);
        
        // Marshaled Properties
        $this->properties = array(
            'accountSid' => $payload['account_sid'],
            'actorSid' => $payload['actor_sid'],
            'actorType' => $payload['actor_type'],
            'description' => $payload['description'],
            'eventData' => $payload['event_data'],
            'eventDate' => Deserialize::iso8601DateTime($payload['event_date']),
            'eventType' => $payload['event_type'],
            'resourceSid' => $payload['resource_sid'],
            'resourceType' => $payload['resource_type'],
            'sid' => $payload['sid'],
            'source' => $payload['source'],
            'sourceIpAddress' => $payload['source_ip_address'],
        );
        
        $this->solution = array(
            'sid' => $sid ?: $this->properties['sid'],
        );
    }

    /**
     * Generate an instance context for the instance, the context is capable of
     * performing various actions.  All instance actions are proxied to the context
     * 
     * @return \Twilio\Rest\Monitor\V1\EventContext Context for this EventInstance
     */
    protected function proxy() {
        if (!$this->context) {
            $this->context = new EventContext(
                $this->version,
                $this->solution['sid']
            );
        }
        
        return $this->context;
    }

    /**
     * Fetch a EventInstance
     * 
     * @return EventInstance Fetched EventInstance
     */
    public function fetch() {
        return $this->proxy()->fetch();
    }

    /**
     * Magic getter to access properties
     * 
     * @param string $name Property to access
     * @return mixed The requested property
     * @throws TwilioException For unknown properties
     */
    public function __get($name) {
        if (array_key_exists($name, $this->properties)) {
            return $this->properties[$name];
        }
        
        if (property_exists($this, '_' . $name)) {
            $method = 'get' . ucfirst($name);
            return $this->$method();
        }
        
        throw new TwilioException('Unknown property: ' . $name);
    }

    /**
     * Provide a friendly representation
     * 
     * @return string Machine friendly representation
     */
    public function __toString() {
        $context = array();
        foreach ($this->solution as $key => $value) {
            $context[] = "$key=$value";
        }
        return '[Twilio.Monitor.V1.EventInstance ' . implode(' ', $context) . ']';
    }
}