Skip to content

Commit f45fb50

Browse files
authored
Some simple improvements (#48)
1 parent 26f5a79 commit f45fb50

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/stream-net-tests/IntegrationTests.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ public async Task TestAddActivityWithString()
124124
[Test]
125125
public async Task TestAddActivityWithDictionary()
126126
{
127-
var dict = new Dictionary<String, String>();
128-
dict["test1"] = "shawn";
129-
dict["test2"] = "wedge";
127+
var dict = new Dictionary<String, String>()
128+
{
129+
{"test1","shawn"},
130+
{"test2", "wedge"}
131+
};
130132

131133
var newActivity = new Stream.Activity("1", "test", "1");
132134
newActivity.SetData("complex", dict);
@@ -162,10 +164,12 @@ public async Task TestAddActivityWithDifferentVariables()
162164
{
163165
int second = 2;
164166
double third = 3;
165-
var dict = new Dictionary<string, object>();
166-
dict["test1"] = "shawn";
167-
dict["test2"] = "wedge";
168-
dict["test3"] = 42;
167+
var dict = new Dictionary<string, object>()
168+
{
169+
{"test1", "shawn"},
170+
{"test2", "wedge"},
171+
{"test3", 42}
172+
};
169173

170174
var newActivity = new Stream.Activity("1", "test", "1");
171175
newActivity.SetData("complex", dict);

src/stream-net/Images.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ public class Images
1010
public Images(StreamClient client)
1111
{
1212
_client = client;
13-
1413
}
1514

1615
public async Task<Image> Upload(System.IO.Stream image, string contentType)
1716
{
18-
var request = _client.BuildUploadRequest(this);
17+
var request = _client.BuildUploadRequest();
1918

2019
request.SetFileStream(image, contentType);
2120

src/stream-net/Rest/RestRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class Parameter
1212
public string Value { get; set; }
1313
}
1414

15-
private IDictionary<string, string> _headers = new Dictionary<string, string>();
16-
private IDictionary<string, string> _queryParameters = new Dictionary<string, string>();
15+
private readonly IDictionary<string, string> _headers = new Dictionary<string, string>();
16+
private readonly IDictionary<string, string> _queryParameters = new Dictionary<string, string>();
1717

1818
internal RestRequest(string resource, HttpMethod method)
1919
{

src/stream-net/StreamClient.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public StreamClient(string apiKey, string apiSecretOrToken, StreamClientOptions
4444
_apiKey = apiKey;
4545
_streamClientToken = TokenFactory.For(apiSecretOrToken);
4646
_options = options ?? StreamClientOptions.Default;
47-
_client = new RestClient(GetBaseUrl(_options.Location), TimeSpan.FromMilliseconds(_options.Timeout));
47+
_client = new RestClient(GetBaseUrl(), TimeSpan.FromMilliseconds(_options.Timeout));
4848
}
4949

5050
private StreamClient(string apiKey, IToken streamClientToken, RestClient client, StreamClientOptions options = null)
@@ -139,7 +139,7 @@ public Personalization Personalization
139139
{
140140
get
141141
{
142-
var _personalization = new RestClient(GetBasePersonalizationUrl(_options.PersonalizationLocation), TimeSpan.FromMilliseconds(_options.PersonalizationTimeout));
142+
var _personalization = new RestClient(GetBasePersonalizationUrl(), TimeSpan.FromMilliseconds(_options.PersonalizationTimeout));
143143
return new Personalization(new StreamClient(_apiKey, _streamClientToken, _personalization, _options));
144144
}
145145
}
@@ -152,12 +152,12 @@ public Images Images
152152
}
153153
}
154154

155-
private Uri GetBaseUrl(StreamApiLocation location)
155+
private Uri GetBaseUrl()
156156
{
157157
return new Uri(string.Format(BaseUrlFormat, GetRegion(_options.Location)));
158158
}
159159

160-
private Uri GetBasePersonalizationUrl(StreamApiLocation location)
160+
private Uri GetBasePersonalizationUrl()
161161
{
162162
return new Uri(string.Format(BasePersonalizationUrlFormat, GetRegion(_options.PersonalizationLocation)));
163163
}
@@ -199,15 +199,14 @@ internal RestRequest BuildEnrichedFeedRequest(StreamFeed feed, string path, Http
199199
return BuildRestRequest(BaseUrlPath + feed.EnrichedPath + path, method);
200200
}
201201

202-
internal RestRequest BuildActivitiesRequest(StreamFeed feed)
202+
internal RestRequest BuildActivitiesRequest()
203203
{
204204
return BuildRestRequest(BaseUrlPath + ActivitiesUrlPath, HttpMethod.POST);
205205
}
206206

207-
internal RestRequest BuildUploadRequest(Images images)
207+
internal RestRequest BuildUploadRequest()
208208
{
209209
return BuildRestRequest(BaseUrlPath + ImagesUrlPath, HttpMethod.POST);
210-
211210
}
212211

213212
internal RestRequest BuildAppRequest(string path, HttpMethod method)

src/stream-net/StreamFeed.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Stream
1313
{
1414
public class StreamFeed : IStreamFeed
1515
{
16-
static Regex _feedRegex = new Regex(@"^\w+$", RegexOptions.Compiled);
17-
static Regex _userRegex = new Regex(@"^[-\w]+$", RegexOptions.Compiled);
16+
static readonly Regex _feedRegex = new Regex(@"^\w+$", RegexOptions.Compiled);
17+
static readonly Regex _userRegex = new Regex(@"^[-\w]+$", RegexOptions.Compiled);
1818

1919
readonly StreamClient _client;
2020
readonly string _feedSlug;
@@ -111,7 +111,7 @@ public async Task UpdateActivities(IEnumerable<Activity> activities)
111111
if (activities.SafeCount() > 100)
112112
throw new ArgumentNullException("activities", "Maximum length is 100");
113113

114-
var request = _client.BuildActivitiesRequest(this);
114+
var request = _client.BuildActivitiesRequest();
115115
request.SetJsonBody(Activity.ToActivitiesJson(activities, this._client));
116116

117117
var response = await _client.MakeRequest(request);
@@ -369,7 +369,7 @@ public Task UnfollowFeed(string targetFeedSlug, string targetUserId, bool keepHi
369369

370370
internal class FollowersResponse
371371
{
372-
public IEnumerable<Follower> results { get; set; }
372+
public IEnumerable<Follower> Results { get; set; }
373373
}
374374

375375
public async Task<IEnumerable<Follower>> Followers(int offset = 0, int limit = 25, string[] filterBy = null)
@@ -391,7 +391,7 @@ public async Task<IEnumerable<Follower>> Followers(int offset = 0, int limit = 2
391391
if (response.StatusCode != System.Net.HttpStatusCode.OK)
392392
throw StreamException.FromResponse(response);
393393

394-
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).results;
394+
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).Results;
395395
}
396396

397397
public async Task<IEnumerable<Follower>> Following(int offset = 0, int limit = 25, string[] filterBy = null)
@@ -413,7 +413,7 @@ public async Task<IEnumerable<Follower>> Following(int offset = 0, int limit = 2
413413
if (response.StatusCode != System.Net.HttpStatusCode.OK)
414414
throw StreamException.FromResponse(response);
415415

416-
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).results;
416+
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).Results;
417417
}
418418

419419
private void ValidateFeedFollow(IStreamFeed feed)

0 commit comments

Comments
 (0)