Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/stream-net-tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ public async Task TestAddActivityWithString()
[Test]
public async Task TestAddActivityWithDictionary()
{
var dict = new Dictionary<String, String>();
dict["test1"] = "shawn";
dict["test2"] = "wedge";
var dict = new Dictionary<String, String>()
{
{"test1","shawn"},
{"test2", "wedge"}
};

var newActivity = new Stream.Activity("1", "test", "1");
newActivity.SetData("complex", dict);
Expand Down Expand Up @@ -162,10 +164,12 @@ public async Task TestAddActivityWithDifferentVariables()
{
int second = 2;
double third = 3;
var dict = new Dictionary<string, object>();
dict["test1"] = "shawn";
dict["test2"] = "wedge";
dict["test3"] = 42;
var dict = new Dictionary<string, object>()
{
{"test1", "shawn"},
{"test2", "wedge"},
{"test3", 42}
};

var newActivity = new Stream.Activity("1", "test", "1");
newActivity.SetData("complex", dict);
Expand Down
3 changes: 1 addition & 2 deletions src/stream-net/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ public class Images
public Images(StreamClient client)
{
_client = client;

}

public async Task<Image> Upload(System.IO.Stream image, string contentType)
{
var request = _client.BuildUploadRequest(this);
var request = _client.BuildUploadRequest();

request.SetFileStream(image, contentType);

Expand Down
4 changes: 2 additions & 2 deletions src/stream-net/Rest/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Parameter
public string Value { get; set; }
}

private IDictionary<string, string> _headers = new Dictionary<string, string>();
private IDictionary<string, string> _queryParameters = new Dictionary<string, string>();
private readonly IDictionary<string, string> _headers = new Dictionary<string, string>();
private readonly IDictionary<string, string> _queryParameters = new Dictionary<string, string>();

internal RestRequest(string resource, HttpMethod method)
{
Expand Down
13 changes: 6 additions & 7 deletions src/stream-net/StreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public StreamClient(string apiKey, string apiSecretOrToken, StreamClientOptions
_apiKey = apiKey;
_streamClientToken = TokenFactory.For(apiSecretOrToken);
_options = options ?? StreamClientOptions.Default;
_client = new RestClient(GetBaseUrl(_options.Location), TimeSpan.FromMilliseconds(_options.Timeout));
_client = new RestClient(GetBaseUrl(), TimeSpan.FromMilliseconds(_options.Timeout));
}

private StreamClient(string apiKey, IToken streamClientToken, RestClient client, StreamClientOptions options = null)
Expand Down Expand Up @@ -139,7 +139,7 @@ public Personalization Personalization
{
get
{
var _personalization = new RestClient(GetBasePersonalizationUrl(_options.PersonalizationLocation), TimeSpan.FromMilliseconds(_options.PersonalizationTimeout));
var _personalization = new RestClient(GetBasePersonalizationUrl(), TimeSpan.FromMilliseconds(_options.PersonalizationTimeout));
return new Personalization(new StreamClient(_apiKey, _streamClientToken, _personalization, _options));
}
}
Expand All @@ -152,12 +152,12 @@ public Images Images
}
}

private Uri GetBaseUrl(StreamApiLocation location)
private Uri GetBaseUrl()
{
return new Uri(string.Format(BaseUrlFormat, GetRegion(_options.Location)));
}

private Uri GetBasePersonalizationUrl(StreamApiLocation location)
private Uri GetBasePersonalizationUrl()
{
return new Uri(string.Format(BasePersonalizationUrlFormat, GetRegion(_options.PersonalizationLocation)));
}
Expand Down Expand Up @@ -199,15 +199,14 @@ internal RestRequest BuildEnrichedFeedRequest(StreamFeed feed, string path, Http
return BuildRestRequest(BaseUrlPath + feed.EnrichedPath + path, method);
}

internal RestRequest BuildActivitiesRequest(StreamFeed feed)
internal RestRequest BuildActivitiesRequest()
{
return BuildRestRequest(BaseUrlPath + ActivitiesUrlPath, HttpMethod.POST);
}

internal RestRequest BuildUploadRequest(Images images)
internal RestRequest BuildUploadRequest()
{
return BuildRestRequest(BaseUrlPath + ImagesUrlPath, HttpMethod.POST);

}

internal RestRequest BuildAppRequest(string path, HttpMethod method)
Expand Down
12 changes: 6 additions & 6 deletions src/stream-net/StreamFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Stream
{
public class StreamFeed : IStreamFeed
{
static Regex _feedRegex = new Regex(@"^\w+$", RegexOptions.Compiled);
static Regex _userRegex = new Regex(@"^[-\w]+$", RegexOptions.Compiled);
static readonly Regex _feedRegex = new Regex(@"^\w+$", RegexOptions.Compiled);
static readonly Regex _userRegex = new Regex(@"^[-\w]+$", RegexOptions.Compiled);

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

var request = _client.BuildActivitiesRequest(this);
var request = _client.BuildActivitiesRequest();
request.SetJsonBody(Activity.ToActivitiesJson(activities, this._client));

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

internal class FollowersResponse
{
public IEnumerable<Follower> results { get; set; }
public IEnumerable<Follower> Results { get; set; }
}

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

return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).results;
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).Results;
}

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

return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).results;
return JsonConvert.DeserializeObject<FollowersResponse>(response.Content).Results;
}

private void ValidateFeedFollow(IStreamFeed feed)
Expand Down