1 <?php
2 /**
3 * Copyright 2014 Klarna AB
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * File containing the Connector interface.
18 */
19
20 namespace Klarna\Rest\Transport;
21
22 use GuzzleHttp\ClientInterface;
23 use GuzzleHttp\Exception\RequestException;
24 use GuzzleHttp\Message\RequestInterface;
25 use GuzzleHttp\Message\ResponseInterface;
26 use Klarna\Rest\Transport\Exception\ConnectorException;
27
28 /**
29 * HTTP transport connector interface used to authenticate and make HTTP requests
30 * against the Klarna APIs.
31 *
32 * The HTTP communication is handled by
33 * {@link http://guzzle.readthedocs.org/en/guzzle4/ Guzzle}.
34 */
35 interface ConnectorInterface
36 {
37 /**
38 * API base URL for Europe.
39 */
40 const EU_BASE_URL = 'https://api.klarna.com';
41
42 /**
43 * Testing API base URL for Europe.
44 */
45 const EU_TEST_BASE_URL = 'https://api.playground.klarna.com';
46
47 /**
48 * API base URL for North America.
49 */
50 const NA_BASE_URL = 'https://api-na.klarna.com';
51
52 /**
53 * Testing API base URL for North America.
54 */
55 const NA_TEST_BASE_URL = 'https://api-na.playground.klarna.com';
56
57 /**
58 * Creates a request object.
59 *
60 * @param string $url URL
61 * @param string $method HTTP method
62 * @param array $options Request options
63 *
64 * @return RequestInterface
65 */
66 public function createRequest($url, $method = 'GET', array $options = []);
67
68 /**
69 * Sends the request.
70 *
71 * @param RequestInterface $request Request to send
72 *
73 * @throws ConnectorException If the API returned an error response
74 * @throws RequestException When an error is encountered
75 * @throws \LogicException When the adapter does not populate a response
76 *
77 * @return ResponseInterface
78 */
79 public function send(RequestInterface $request);
80
81 /**
82 * Gets the HTTP transport client.
83 *
84 * @return ClientInterface
85 */
86 public function getClient();
87
88 /**
89 * Gets the user agent.
90 *
91 * @return UserAgentInterface
92 */
93 public function getUserAgent();
94 }
95