Skip to content

Commit

Permalink
Merge pull request #88 from aiham/release-2.4.4
Browse files Browse the repository at this point in the history
Release 2.4.4
  • Loading branch information
aiham committed Aug 10, 2017
2 parents 51ea646 + 2375042 commit 0ff123f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 18 deletions.
12 changes: 5 additions & 7 deletions CONTRIBUTING.md
@@ -1,24 +1,22 @@
# Contributing Guidelines

For anyone looking to get involved to this project, we are glad to hear from you. Here are a few types of contributions
that we would be interested in hearing about.
If you're interested in contributing to this project, here are a few ways to do so:

* Bug fixes
- If you find a bug, please first report it using Github Issues.
- Issues that have already been identified as a bug will be labelled `bug`.
- If you'd like to submit a fix for a bug, send a Pull Request from your own fork and mention the Issue number.
+ Include a test that isolates the bug and verifies that it was fixed.
* New Features
- If you'd like to accomplish something in the library that it doesn't already do, describe the problem in a new
- If you'd like to add a feature to the library that doesn't already exist, feel free to describe the feature in a new
Github Issue.
- Issues that have been identified as a feature request will be labelled `enhancement`.
- If you'd like to implement the new feature, please wait for feedback from the project maintainers before spending
too much time writing the code. In some cases, `enhancement`s may not align well with the project objectives at
the time.
* Tests, Documentation, Miscellaneous
- If you think the test coverage could be improved, the documentation could be clearer, you've got an alternative
implementation of something that may have more advantages, or any other change we would still be glad hear about
it.
- If you think the test coverage could be improved, the documentation could be clearer, or you have an alternative
implementation of something that may have more advantages, we would love to hear it.
- If its a trivial change, go ahead and send a Pull Request with the changes you have in mind
- If not, open a Github Issue to discuss the idea first.

Expand All @@ -44,4 +42,4 @@ continue to add more commits to the branch you have sent the Pull Request from.

## Developer Guidelines

See DEVELOPING.md for guidelines for developing this project.
See DEVELOPING.md for guidelines for developing this project.
13 changes: 7 additions & 6 deletions DEVELOPING.md
Expand Up @@ -37,7 +37,7 @@ You can now either click the Run All command or use the keyboard shortcut (Ctrl+
In order to create a release, the following should be completed in order.

1. Build the solution using the Release confgiuration. Ensure all the tests are passing and that there is enough test coverage.
1. Make sure you are on the `master` branch of the repository, with all changes merged/commited already.
1. Make sure you are on the `dev` branch of the repository, with all changes merged/commited already.
1. Update the version number in the source code and the README. See [Versioning](#versioning) for information
about selecting an appropriate version number. Files to change:
- OpenTok\Properties\AssemblyInfo.cs (AssemblyInformationalVersion contains full semver, AssemblyVersion only
Expand All @@ -53,7 +53,7 @@ In order to create a release, the following should be completed in order.
1. Change the version number for future development by incrementing the patch number and
adding "-Alpha1" in each file except the README. Then stage the remaining files and commit with the message
"Begin development on next version".
1. Push the changes to the source repository: `git push origin master; git push --tags origin`
1. Push the changes to the source repository: `git push origin dev; git push --tags origin`
1. Compress the contents of the `OpenTok\bin\Release\` directory, name it using the following template: `OpenTokSDK_x.y.z.zip`
Upload the zip as an attached file in the latest GitHub Release. Add release notes with a description of changes and fixes.

Expand All @@ -70,11 +70,12 @@ Using a "." in the prerelease tag is not allowed in the .NET platform.

### Branches

* `master` - the main development branch.
* `dev` - the main development branch.
* `master` - reflects the latest stable release.
* `feat.foo` - feature branches. these are used for longer running tasks that cannot be accomplished in one commit.
once merged into master, these branches should be deleted.
* `vx.x.x` - if development for a future version/milestone has begun while master is working towards a sooner
release, this is the naming scheme for that branch. once merged into master, these branches should be deleted.
once merged into dev, these branches should be deleted.
* `vx.x.x` - if development for a future version/milestone has begun while dev is working towards a sooner
release, this is the naming scheme for that branch. once merged into dev, these branches should be deleted.

### Tags

Expand Down
16 changes: 16 additions & 0 deletions OpenTok/OpenTok.cs
Expand Up @@ -30,6 +30,20 @@ public class OpenTok
/** For internal use. */
public HttpClient Client { private get; set; }

/**
* Enables writing request/response details to console.
* Don't use in a production environment.
*/
private bool _debug;
public bool Debug {
get { return _debug; }
set
{
_debug = value;
Client.debug = _debug;
}
}

/**
* Creates an OpenTok object.
*
Expand All @@ -44,6 +58,7 @@ public OpenTok(int apiKey, string apiSecret)
this.ApiSecret = apiSecret;
this.OpenTokServer = "https://api.opentok.com";
Client = new HttpClient(apiKey, apiSecret, this.OpenTokServer);
this.Debug = false;
}

/**
Expand All @@ -55,6 +70,7 @@ public OpenTok(int apiKey, string apiSecret, string apiUrl)
this.ApiSecret = apiSecret;
this.OpenTokServer = apiUrl;
Client = new HttpClient(apiKey, apiSecret, this.OpenTokServer);
this.Debug = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion OpenTok/Properties/AssemblyInfo.cs
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.*")]
[assembly: AssemblyInformationalVersion("2.4.3")]
[assembly: AssemblyInformationalVersion("2.4.4")]
66 changes: 62 additions & 4 deletions OpenTok/Util/HttpClient.cs
Expand Up @@ -28,6 +28,10 @@ public class HttpClient
private int apiKey;
private string apiSecret;
private string server;
public bool debug = false;
private readonly DateTime unixEpoch = new DateTime(
1970, 1, 1, 0, 0, 0, DateTimeKind.Utc
);

public HttpClient()
{
Expand Down Expand Up @@ -71,16 +75,26 @@ public virtual string Delete(string url, Dictionary<string, string> headers, Dic
string data = GetRequestPostData(bodyData, specificHeaders);
var headers = GetRequestHeaders(specificHeaders);
HttpWebRequest request = CreateRequest(url, headers, data);

DebugLog("Request Method: " + request.Method);
DebugLog("Request URI: " + request.RequestUri);
DebugLogHeaders(request.Headers, "Request");

HttpWebResponse response;

try
{
if (!String.IsNullOrEmpty(data))
{
DebugLog("Request Body: " + data);
SendData(request, data);
}
using (response = (HttpWebResponse) request.GetResponse())
{
DebugLog("Response Status Code: " + response.StatusCode);
DebugLog("Response Status Description: " + response.StatusDescription);
DebugLogHeaders(response.Headers, "Response");

switch (response.StatusCode)
{
case HttpStatusCode.OK:
Expand All @@ -98,6 +112,22 @@ public virtual string Delete(string url, Dictionary<string, string> headers, Dic
}
catch (WebException e)
{
DebugLog("WebException Status: " + e.Status + ", Message: " + e.Message);

response = (HttpWebResponse)e.Response;

DebugLog("Response Status Code: " + response.StatusCode);
DebugLog("Response Status Description: " + response.StatusDescription);
DebugLogHeaders(response.Headers, "Response");

if (this.debug)
{
using (var stream = new StreamReader(response.GetResponseStream()))
{
DebugLog("Response Body: " + stream.ReadToEnd());
}
}

throw new OpenTokWebException("Error with request submission", e);
}

Expand Down Expand Up @@ -183,21 +213,25 @@ private string ProcessParameters(Dictionary<string, object> parameters)
return data.Substring(0, data.Length - 1);
}

private string GenerateJwt(int key, string secret, int expiryPeriod = 300)
private int CurrentTime()
{
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow();

var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
int secondsSinceEpoch = (int) Math.Round((now - unixEpoch).TotalSeconds);
return secondsSinceEpoch;
}

int expiry = secondsSinceEpoch + expiryPeriod;
private string GenerateJwt(int key, string secret, int expiryPeriod = 300)
{
int now = CurrentTime();
int expiry = now + expiryPeriod;

var payload = new Dictionary<string, object>
{
{ "iss", Convert.ToString(key) },
{ "ist", "project" },
{ "iat", secondsSinceEpoch },
{ "iat", now },
{ "exp", expiry }
};

Expand All @@ -217,5 +251,29 @@ private string GenerateJwt(int key, string secret, int expiryPeriod = 300)
{ "X-TB-VERSION", "1" },
};
}

private void DebugLog(string message)
{
if (this.debug)
{
var now = Convert.ToString(CurrentTime());
Console.WriteLine("[{0}] {1}", now, message);
}
}

private void DebugLogHeaders(WebHeaderCollection headers, string label)
{
if (this.debug)
{
for(int i = 0; i < headers.Count; ++i)
{
string header = headers.GetKey(i);
foreach(string value in headers.GetValues(i))
{
DebugLog(label + " Header: " + header + " = " + value);
}
}
}
}
}
}

0 comments on commit 0ff123f

Please sign in to comment.