Skip to content

Commit 60f8e9b

Browse files
authored
Add og (#50)
1 parent f94a30d commit 60f8e9b

File tree

4 files changed

+158
-3
lines changed

4 files changed

+158
-3
lines changed

src/stream-net-tests/IntegrationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,5 +2489,19 @@ public async Task TestUpload()
24892489
Assert.IsNotEmpty(upload.File);
24902490
}
24912491
}
2492+
2493+
[Test]
2494+
public async Task TestOG()
2495+
{
2496+
var og = await _client.Og("https://getstream.io/blog/try-out-the-stream-api-with-postman");
2497+
2498+
Assert.IsNotEmpty(og.Type);
2499+
Assert.IsNotEmpty(og.Title);
2500+
Assert.IsNotEmpty(og.Description);
2501+
Assert.IsNotEmpty(og.URL);
2502+
Assert.IsNotEmpty(og.Favicon);
2503+
Assert.IsNotEmpty(og.Images);
2504+
Assert.IsNotEmpty(og.Images[0].Image);
2505+
}
24922506
}
24932507
}

src/stream-net/IStreamClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Threading.Tasks;
33

44
namespace Stream
@@ -16,7 +16,7 @@ public interface IStreamClient
1616

1717
Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable<string> unset = null);
1818
IStreamFeed Feed(string feedSlug, string userId);
19-
19+
Task<Og> Og(string url);
2020
string CreateUserToken(string userId, IDictionary<string, object> extraData = null);
2121
}
2222
}

src/stream-net/Og.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Stream
4+
{
5+
public class OgImage
6+
{
7+
[JsonProperty("image")]
8+
public string Image { get; set; }
9+
10+
[JsonProperty("url")]
11+
public string URL { get; set; }
12+
13+
[JsonProperty("secure_url")]
14+
public string SecureURL { get; set; }
15+
16+
[JsonProperty("width")]
17+
public int Width { get; set; }
18+
19+
[JsonProperty("height")]
20+
public int Height { get; set; }
21+
22+
[JsonProperty("type")]
23+
public string Type { get; set; }
24+
25+
[JsonProperty("alt")]
26+
public string Alt { get; set; }
27+
28+
[JsonConstructor]
29+
internal OgImage()
30+
{
31+
}
32+
}
33+
34+
public class OgVideo
35+
{
36+
37+
[JsonProperty("video")]
38+
public string Video { get; set; }
39+
40+
[JsonProperty("url")]
41+
public string URL { get; set; }
42+
43+
[JsonProperty("secure_url")]
44+
public string SecureURL { get; set; }
45+
46+
[JsonProperty("width")]
47+
public int Width { get; set; }
48+
49+
[JsonProperty("height")]
50+
public int Height { get; set; }
51+
52+
[JsonProperty("type")]
53+
public string Type { get; set; }
54+
55+
[JsonConstructor]
56+
internal OgVideo()
57+
{
58+
}
59+
}
60+
61+
public class OgAudio
62+
{
63+
64+
[JsonProperty("audio")]
65+
public string Audio { get; set; }
66+
67+
[JsonProperty("url")]
68+
public string URL { get; set; }
69+
70+
[JsonProperty("secure_url")]
71+
public string SecureURL { get; set; }
72+
73+
[JsonProperty("type")]
74+
public string Type { get; set; }
75+
76+
[JsonConstructor]
77+
internal OgAudio()
78+
{
79+
}
80+
}
81+
82+
public class Og
83+
{
84+
85+
[JsonProperty("title")]
86+
public string Title { get; set; }
87+
88+
[JsonProperty("type")]
89+
public string Type { get; set; }
90+
91+
[JsonProperty("url")]
92+
public string URL { get; set; }
93+
94+
[JsonProperty("site")]
95+
public string Site { get; set; }
96+
97+
[JsonProperty("site_name")]
98+
public string SiteName { get; set; }
99+
100+
[JsonProperty("description")]
101+
public string Description { get; set; }
102+
103+
[JsonProperty("favicon")]
104+
public string Favicon { get; set; }
105+
106+
[JsonProperty("determiner")]
107+
public string Determiner { get; set; }
108+
109+
[JsonProperty("images")]
110+
public OgImage[] Images { get; set; }
111+
112+
[JsonProperty("videos")]
113+
public OgVideo[] Videos { get; set; }
114+
115+
[JsonProperty("audios")]
116+
public OgAudio[] Audios { get; set; }
117+
118+
[JsonProperty("duration")]
119+
public string Duration { get; set; }
120+
121+
[JsonConstructor]
122+
internal Og()
123+
{
124+
}
125+
}
126+
}
127+
128+

src/stream-net/StreamClient.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Stream.Rest;
1+
using Newtonsoft.Json;
2+
using Stream.Rest;
23
using System;
34
using System.Collections.Generic;
45
using System.Threading.Tasks;
@@ -92,6 +93,18 @@ public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignI
9293
await this.Batch.ActivitiesPartialUpdate(new ActivityPartialUpdateRequestObject[] { update });
9394
}
9495

96+
public async Task<Og> Og(string url)
97+
{
98+
var request = this.BuildAppRequest("og/", HttpMethod.GET);
99+
request.AddQueryParameter("url", url);
100+
101+
var response = await this.MakeRequest(request);
102+
if (response.StatusCode != System.Net.HttpStatusCode.OK)
103+
throw StreamException.FromResponse(response);
104+
105+
return JsonConvert.DeserializeObject<Og>(response.Content);
106+
}
107+
95108
public string CreateUserToken(string userId, IDictionary<string, object> extraData = null)
96109
{
97110
return _streamClientToken.CreateUserToken(userId, extraData);

0 commit comments

Comments
 (0)