Skip to content

Commit 86caa52

Browse files
authored
Fix location in client setup (#29)
fixed #25
1 parent e83ede4 commit 86caa52

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
class Client
1717
{
18-
19-
const API_ENDPOINT = 'chat-us-east-1.stream-io-api.com';
20-
2118
/**
2219
* @var string
2320
*/
@@ -65,7 +62,7 @@ class Client
6562
* @param string $location
6663
* @param float $timeout
6764
*/
68-
public function __construct($apiKey, $apiSecret, $apiVersion='v1.0', $location='', $timeout=3.0)
65+
public function __construct($apiKey, $apiSecret, $apiVersion='v1.0', $location='us-east', $timeout=3.0)
6966
{
7067
$this->apiKey = $apiKey;
7168
$this->apiSecret = $apiSecret;
@@ -110,21 +107,14 @@ public function getBaseUrl()
110107
// try STREAM_BASE_URL for backwards compatibility
111108
$baseUrl = getenv('STREAM_BASE_URL');
112109
}
113-
if (!$baseUrl) {
114-
$apiEndpoint = static::API_ENDPOINT;
115-
$localPort = getenv('STREAM_LOCAL_API_PORT');
116-
if ($localPort) {
117-
$baseUrl = "http://localhost:$localPort/api";
118-
} else {
119-
if ($this->location) {
120-
$subdomain = "{$this->location}-api";
121-
} else {
122-
$subdomain = 'api';
123-
}
124-
$baseUrl = "{$this->protocol}://" . $apiEndpoint;
125-
}
110+
if ($baseUrl) {
111+
return $baseUrl;
112+
}
113+
$localPort = getenv('STREAM_LOCAL_API_PORT');
114+
if ($localPort) {
115+
return "http://localhost:$localPort/api";
126116
}
127-
return $baseUrl;
117+
return "{$this->protocol}://chat-proxy-{$this->location}.stream-io-api.com";
128118
}
129119

130120
/**

tests/integration/IntegrationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function setUp():void
2121
'v1.0',
2222
getenv('STREAM_REGION')
2323
);
24-
$this->client->setLocation('qa');
24+
$this->client->setLocation('us-east');
2525
$this->client->timeout = 10000;
2626
}
2727

@@ -598,7 +598,7 @@ public function testGetMessage(){
598598
}
599599

600600
public function testChannelSendAndDeleteFile(){
601-
$url = "https://getstream.io/blog/static/stream_logo-d233917ae4f306fb8f43b56e65c7b18f.svg";
601+
$url = "https://stream-blog-v2.imgix.net/blog/wp-content/uploads/1f4a0a19b7533494c5341170abbf655e/stream_logo.svg";
602602
$user = $this->getUser();
603603
$channel = $this->getChannel();
604604
$resp = $channel->sendFile($url, "logo.svg", $user);
@@ -607,7 +607,7 @@ public function testChannelSendAndDeleteFile(){
607607
}
608608

609609
public function testChannelSendAndDeleteImage(){
610-
$url = "https://getstream.io/blog/wp-content/themes/stream-theme-wordpress_2018-05-24_10-41/assets/images/stream_logo.png";
610+
$url = "https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png";
611611
$user = $this->getUser();
612612
$channel = $this->getChannel();
613613
$resp = $channel->sendImage($url, "logo.png", $user);

tests/unit/ClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ public function testClientSetProtocol()
1919
$client = new Client('key', 'secret');
2020
$client->setProtocol('asdfg');
2121
$url = $client->buildRequestUrl('x');
22-
$this->assertSame('asdfg://chat-us-east-1.stream-io-api.com/x', $url);
22+
$this->assertSame('asdfg://chat-proxy-us-east.stream-io-api.com/x', $url);
2323
}
2424

2525
public function testClientHostnames()
2626
{
2727
$client = new Client('key', 'secret');
2828
$client->setLocation('qa');
2929
$url = $client->buildRequestUrl('x');
30-
$this->assertSame('https://chat-us-east-1.stream-io-api.com/x', $url);
30+
$this->assertSame('https://chat-proxy-qa.stream-io-api.com/x', $url);
3131

3232
$client = new Client('key', 'secret', $api_version = '1234', $location = 'asdfg');
3333
$url = $client->buildRequestUrl('y');
34-
$this->assertSame('https://chat-us-east-1.stream-io-api.com/y', $url);
34+
$this->assertSame('https://chat-proxy-asdfg.stream-io-api.com/y', $url);
3535

3636
$client = new Client('key', 'secret');
3737
$client->setLocation('us-east');
3838
$url = $client->buildRequestUrl('z');
39-
$this->assertSame('https://chat-us-east-1.stream-io-api.com/z', $url);
39+
$this->assertSame('https://chat-proxy-us-east.stream-io-api.com/z', $url);
4040
}
4141

4242
public function testEnvironmentVariable()

0 commit comments

Comments
 (0)