Completed
Push — master ( 1f0278...22c246 )
by
unknown
12s
created

Moip::keys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Moip;
4
5
use Moip\Contracts\Authentication;
6
use Moip\Resource\Account;
7
use Moip\Resource\Customer;
8
use Moip\Resource\Entry;
9
use Moip\Resource\Keys;
10
use Moip\Resource\Multiorders;
11
use Moip\Resource\NotificationPreferences;
12
use Moip\Resource\Orders;
13
use Moip\Resource\Payment;
14
use Moip\Resource\Transfers;
15
use Moip\Resource\WebhookList;
16
use Requests_Session;
17
18
/**
19
 * Class Moip.
20
 */
21
class Moip
22
{
23
    /**
24
     * endpoint of production.
25
     *
26
     * @const string
27
     */
28
    const ENDPOINT_PRODUCTION = 'https://api.moip.com.br';
29
30
    /**
31
     * endpoint of sandbox.
32
     *
33
     * @const string
34
     */
35
    const ENDPOINT_SANDBOX = 'https://sandbox.moip.com.br';
36
37
    /**
38
     * Client name.
39
     *
40
     * @const string
41
     * */
42
    const CLIENT = 'MoipPhpSDK';
43
44
    /**
45
     * Client Version.
46
     *
47
     * @const string
48
     */
49
    const CLIENT_VERSION = '1.3.2';
50
51
    /**
52
     * Authentication that will be added to the header of request.
53
     *
54
     * @var \Moip\MoipAuthentication
55
     */
56
    private $moipAuthentication;
57
58
    /**
59
     * Endpoint of request.
60
     *
61
     * @var \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX
62
     */
63
    private $endpoint;
64
65
    /**
66
     * @var Requests_Session HTTP session configured to use the moip API.
67
     */
68
    private $session;
69
70
    /**
71
     * Create a new aurhentication with the endpoint.
72
     *
73
     * @param \Moip\Auth\MoipAuthentication $moipAuthentication
74
     * @param string                        $endpoint
75
     */
76
    public function __construct(Authentication $moipAuthentication, $endpoint = self::ENDPOINT_PRODUCTION)
77
    {
78
        $this->moipAuthentication = $moipAuthentication;
0 ignored issues
show
Documentation Bug introduced by
It seems like $moipAuthentication of type object<Moip\Contracts\Authentication> is incompatible with the declared type object<Moip\MoipAuthentication> of property $moipAuthentication.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
79
        $this->endpoint = $endpoint;
0 ignored issues
show
Documentation Bug introduced by
It seems like $endpoint of type string is incompatible with the declared type object<Moip\Moip::ENDPOI...Moip::ENDPOINT_SANDBOX> of property $endpoint.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
80
        $this->createNewSession();
81
    }
82
83
    /**
84
     * Creates a new Request_Session with all the default values.
85
     * A Session is created at construction.
86
     *
87
     * @param float $timeout         How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01).
88
     * @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01)
89
     */
90
    public function createNewSession($timeout = 30.0, $connect_timeout = 30.0)
91
    {
92
        $user_agent = sprintf('%s/%s (+https://github.com/moip/moip-sdk-php/)', self::CLIENT, self::CLIENT_VERSION);
93
        $sess = new Requests_Session($this->endpoint);
94
        $sess->options['auth'] = $this->moipAuthentication;
95
        $sess->options['timeout'] = $timeout;
96
        $sess->options['connect_timeout'] = $connect_timeout;
97
        $sess->options['useragent'] = $user_agent;
98
        $this->session = $sess;
99
    }
100
101
    /**
102
     * Returns the http session created.
103
     *
104
     * @return Requests_Session
105
     */
106
    public function getSession()
107
    {
108
        return $this->session;
109
    }
110
111
    /**
112
     * Replace the http session by a custom one.
113
     *
114
     * @param Requests_Session $session
115
     */
116
    public function setSession($session)
117
    {
118
        $this->session = $session;
119
    }
120
121
    /**
122
     * Create a new Customer instance.
123
     *
124
     * @return \Moip\Resource\Customer
125
     */
126
    public function customers()
127
    {
128
        return new Customer($this);
129
    }
130
131
    /**
132
     * Create a new Account instance.
133
     *
134
     * @return \Moip\Resource\Account
135
     */
136
    public function accounts()
137
    {
138
        return new Account($this);
139
    }
140
141
    /**
142
     * Create a new Entry instance.
143
     *
144
     * @return \Moip\Resource\Entry
145
     */
146
    public function entries()
147
    {
148
        return new Entry($this);
149
    }
150
151
    /**
152
     * Create a new Orders instance.
153
     *
154
     * @return \Moip\Resource\Orders
155
     */
156
    public function orders()
157
    {
158
        return new Orders($this);
159
    }
160
161
    /**
162
     * Create a new Payment instance.
163
     *
164
     * @return \Moip\Resource\Payment
165
     */
166
    public function payments()
167
    {
168
        return new Payment($this);
169
    }
170
171
    /**
172
     * Create a new Multiorders instance.
173
     *
174
     * @return \Moip\Resource\Multiorders
175
     */
176
    public function multiorders()
177
    {
178
        return new Multiorders($this);
179
    }
180
181
    /**
182
     * Create a new Transfers.
183
     *
184
     * @return \Moip\Resource\Transfers
185
     */
186
187
    /**
188
     * Create a new Transfers instance.
189
     *
190
     * @return Transfers
191
     */
192
    public function transfers()
193
    {
194
        return new Transfers($this);
195
    }
196
197
    /**
198
     * Create a new Notification Prefences instance.
199
     *
200
     * @return NotificationPreferences
201
     */
202
    public function notifications()
203
    {
204
        return new NotificationPreferences($this);
205
    }
206
207
    /**
208
     * Create a new WebhookList instance.
209
     *
210
     * @return WebhookList
211
     */
212
    public function webhooks()
213
    {
214
        return new WebhookList($this);
215
    }
216
217
    /**
218
     * Create a new Keys instance.
219
     *
220
     * @return Keys
221
     */
222
    public function keys()
223
    {
224
        return new Keys($this);
225
    }
226
227
    /**
228
     * Get the endpoint.
229
     *
230
     * @return \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX
231
     */
232
    public function getEndpoint()
233
    {
234
        return $this->endpoint;
235
    }
236
}
237