From e7884815d250bc74083f7d7ba8badfd2efd7dbc5 Mon Sep 17 00:00:00 2001 From: Haythem Tlili Date: Thu, 26 Jul 2012 17:33:02 +0200 Subject: [PATCH] Added Date Conversion Helper --- Source/Kippt.sln | 120 ++++++------ Source/Kippt.suo | Bin 46592 -> 58368 bytes Source/Kippt/KipptAccount.cs | 6 + Source/Kippt/KipptClip.cs | 4 +- Source/Kippt/KipptList.cs | 362 +++++++++++++++++------------------ Source/Kippt/Utils.cs | 148 ++++++++------ 6 files changed, 342 insertions(+), 298 deletions(-) diff --git a/Source/Kippt.sln b/Source/Kippt.sln index f218bf5..392ca24 100644 --- a/Source/Kippt.sln +++ b/Source/Kippt.sln @@ -1,54 +1,66 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt", "Kippt\Kippt.csproj", "{2D95826E-EE1F-4417-AE71-2D492F25CC6E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt.Silverlight", "Kippt.Silverlight\Kippt.Silverlight.csproj", "{7424C378-5F9B-4C5A-8190-92C25A28C915}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt.WindowsPhone", "Kippt.WindowsPhone\Kippt.WindowsPhone.csproj", "{AB64219C-EA63-4391-A9E1-27F4C9AF830C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|x86.ActiveCfg = Debug|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Any CPU.Build.0 = Release|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|x86.ActiveCfg = Release|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|x86.ActiveCfg = Debug|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Any CPU.Build.0 = Release|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|x86.ActiveCfg = Release|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|x86.ActiveCfg = Debug|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Any CPU.Build.0 = Release|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|x86.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt", "Kippt\Kippt.csproj", "{2D95826E-EE1F-4417-AE71-2D492F25CC6E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt.Silverlight", "Kippt.Silverlight\Kippt.Silverlight.csproj", "{7424C378-5F9B-4C5A-8190-92C25A28C915}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt.WindowsPhone", "Kippt.WindowsPhone\Kippt.WindowsPhone.csproj", "{AB64219C-EA63-4391-A9E1-27F4C9AF830C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kippt.Tests", "Kippt.Tests\Kippt.Tests.csproj", "{4BD9A16D-591A-47B0-99FF-60F26AA176B8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Debug|x86.ActiveCfg = Debug|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Any CPU.Build.0 = Release|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {2D95826E-EE1F-4417-AE71-2D492F25CC6E}.Release|x86.ActiveCfg = Release|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Debug|x86.ActiveCfg = Debug|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Any CPU.Build.0 = Release|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {7424C378-5F9B-4C5A-8190-92C25A28C915}.Release|x86.ActiveCfg = Release|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Debug|x86.ActiveCfg = Debug|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Any CPU.Build.0 = Release|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {AB64219C-EA63-4391-A9E1-27F4C9AF830C}.Release|x86.ActiveCfg = Release|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Debug|x86.ActiveCfg = Debug|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Release|Any CPU.Build.0 = Release|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {4BD9A16D-591A-47B0-99FF-60F26AA176B8}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Kippt.suo b/Source/Kippt.suo index 718ccbcecfa1ec3ababb40b3a2653c5fbffc003b..6fabfabf4585fb3618bacfa03393b6458c36a368 100644 GIT binary patch delta 4137 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 + /// Gets the profile url. + /// + [DataMember(Name = "app_url")] + public string Profile { get; set; } + /// /// Gets or sets the avatar url (Gravatar). /// diff --git a/Source/Kippt/KipptClip.cs b/Source/Kippt/KipptClip.cs index b7d8d7a..6bccc7e 100644 --- a/Source/Kippt/KipptClip.cs +++ b/Source/Kippt/KipptClip.cs @@ -70,7 +70,7 @@ public class KipptClip /// public DateTime DateCreated { - get { return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(dateCreated * 1000L); } + get { return Utils.FromUnixTime(dateCreated); } } [DataMember(Name = "updated")] @@ -80,7 +80,7 @@ public DateTime DateCreated /// public DateTime DateUpdated { - get { return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(dateUpdated * 1000L); } + get { return Utils.FromUnixTime(dateUpdated); } } [DataMember(Name = "list")] diff --git a/Source/Kippt/KipptList.cs b/Source/Kippt/KipptList.cs index cfaa9bd..296e492 100644 --- a/Source/Kippt/KipptList.cs +++ b/Source/Kippt/KipptList.cs @@ -1,182 +1,182 @@ -/* - Kippt.NET Library for consuming Kippt APIs. - Copyright (C) 2012 Haythem Tlili - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace Kippt -{ - /// - /// Lists are used to organize and categorize clips. Clips will have a list associated to them. - /// Every user has two lists predefined, inbox and read-later, which can't be deleted. - /// - [DataContract] - public class KipptList : KipptClient - { - #region Properties - - /// - /// Gets list id. - /// - [DataMember(Name = "id")] - public int Id { get; set; } - - /// - /// Gets or sets list title. - /// - [DataMember(Name = "title")] - public string Title { get; set; } - - /// - /// Gets list slug. - /// - [DataMember(Name = "slug")] - public string Slug { get; set; } - - [DataMember(Name = "created")] - public int dateCreated; - /// - /// Gets the creation date of a list. - /// - public DateTime DateCreated - { - get { return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(dateCreated * 1000L); } - } - - [DataMember(Name = "updated")] - public int dateUpdated; - /// - /// Gets the update date of a list. - /// - public DateTime DateUpdated - { - get { return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(dateUpdated * 1000L); } - } - - /// - /// Gets the permalink of a list. - /// - [DataMember(Name = "resource_uri")] - public string ResourceUri { get; set; } - - /// - /// Gets the rss uri of a list. - /// - [DataMember(Name = "rss_url")] - public Uri Rss { get; set; } - - #endregion Properties - - #region Public Methods - - /// - /// Returns a list of clips associated to the list instance. - /// - /// - /// - /// Results are paginated. - /// The default number of returned clips is 20. - /// Pagination information are stored in the Meta property of class. - /// - public KipptClipCollection GetClips() - { - return KipptClip.GetClipsByList(this.Id, 100000); - } - - /// - /// Creates a kippt list. - /// - public void Create() - { - KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Post, JsonSerializer.Serialize(this)); - } - - /// - /// Updates a kippt list. - /// - public void Update() - { - KipptApi.ApiAction(ApiCommand.List, HttpMethod.Put, JsonSerializer.Serialize(this), this.Id); - } - - /// - /// Deletes a kippt list. - /// - public void Delete() - { - KipptApi.ApiAction(ApiCommand.List, HttpMethod.Delete, this.Id); - } - - #endregion Public Methods - - #region Shared Methods - - /// - /// Returns a list of kippt lists. - /// - /// - /// - /// Results are paginated. - /// The default number of returned clips is 20. - /// Pagination information are stored in the Meta property of class. - /// - public static KipptListCollection GetLists() - { - return KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Get); - } - - /// - /// Returns a specific number of kippt lists. - /// - /// - /// Number of lists. - public static KipptListCollection GetLists(int limit) - { - return GetLists(limit, 0); - } - - /// - /// Returns a range of kippt lists. - /// - /// - /// End index. - /// Start index. - public static KipptListCollection GetLists(int limit, int offset) - { - Dictionary parameters = new Dictionary(); - - parameters.Add("limit", limit); - - if (offset > 0) parameters.Add("offset", offset); - - return KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Get, parameters); - } - - /// - /// Returns a kippt list by its id. - /// - /// - /// List id. - public static KipptList GetList(int id) - { - return KipptApi.ApiAction(ApiCommand.List, HttpMethod.Get, id); - } - - #endregion Shared Methods - } +/* + Kippt.NET Library for consuming Kippt APIs. + Copyright (C) 2012 Haythem Tlili + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Kippt +{ + /// + /// Lists are used to organize and categorize clips. Clips will have a list associated to them. + /// Every user has two lists predefined, inbox and read-later, which can't be deleted. + /// + [DataContract] + public class KipptList : KipptClient + { + #region Properties + + /// + /// Gets list id. + /// + [DataMember(Name = "id")] + public int Id { get; set; } + + /// + /// Gets or sets list title. + /// + [DataMember(Name = "title")] + public string Title { get; set; } + + /// + /// Gets list slug. + /// + [DataMember(Name = "slug")] + public string Slug { get; set; } + + [DataMember(Name = "created")] + public int dateCreated; + /// + /// Gets the creation date of a list. + /// + public DateTime DateCreated + { + get { return Utils.FromUnixTime(dateCreated); } + } + + [DataMember(Name = "updated")] + public int dateUpdated; + /// + /// Gets the update date of a list. + /// + public DateTime DateUpdated + { + get { return Utils.FromUnixTime(dateUpdated); } + } + + /// + /// Gets the permalink of a list. + /// + [DataMember(Name = "resource_uri")] + public string ResourceUri { get; set; } + + /// + /// Gets the rss uri of a list. + /// + [DataMember(Name = "rss_url")] + public Uri Rss { get; set; } + + #endregion Properties + + #region Public Methods + + /// + /// Returns a list of clips associated to the list instance. + /// + /// + /// + /// Results are paginated. + /// The default number of returned clips is 20. + /// Pagination information are stored in the Meta property of class. + /// + public KipptClipCollection GetClips() + { + return KipptClip.GetClipsByList(this.Id, 100000); + } + + /// + /// Creates a kippt list. + /// + public void Create() + { + KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Post, JsonSerializer.Serialize(this)); + } + + /// + /// Updates a kippt list. + /// + public void Update() + { + KipptApi.ApiAction(ApiCommand.List, HttpMethod.Put, JsonSerializer.Serialize(this), this.Id); + } + + /// + /// Deletes a kippt list. + /// + public void Delete() + { + KipptApi.ApiAction(ApiCommand.List, HttpMethod.Delete, this.Id); + } + + #endregion Public Methods + + #region Shared Methods + + /// + /// Returns a list of kippt lists. + /// + /// + /// + /// Results are paginated. + /// The default number of returned clips is 20. + /// Pagination information are stored in the Meta property of class. + /// + public static KipptListCollection GetLists() + { + return KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Get); + } + + /// + /// Returns a specific number of kippt lists. + /// + /// + /// Number of lists. + public static KipptListCollection GetLists(int limit) + { + return GetLists(limit, 0); + } + + /// + /// Returns a range of kippt lists. + /// + /// + /// End index. + /// Start index. + public static KipptListCollection GetLists(int limit, int offset) + { + Dictionary parameters = new Dictionary(); + + parameters.Add("limit", limit); + + if (offset > 0) parameters.Add("offset", offset); + + return KipptApi.ApiAction(ApiCommand.Lists, HttpMethod.Get, parameters); + } + + /// + /// Returns a kippt list by its id. + /// + /// + /// List id. + public static KipptList GetList(int id) + { + return KipptApi.ApiAction(ApiCommand.List, HttpMethod.Get, id); + } + + #endregion Shared Methods + } } \ No newline at end of file diff --git a/Source/Kippt/Utils.cs b/Source/Kippt/Utils.cs index f6be287..9f743bc 100644 --- a/Source/Kippt/Utils.cs +++ b/Source/Kippt/Utils.cs @@ -1,61 +1,87 @@ -/* - Kippt.NET Library for consuming Kippt APIs. - Copyright (C) 2012 Haythem Tlili - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -using System; -using System.Linq; -using System.Text; -using System.Collections.Generic; - -namespace Kippt -{ - /// - /// Common helpers. - /// - class Utils - { - #region Uri - - /// - /// Returns an Uri after replacement of the format item with the corresponding string representation. - /// - /// - /// Input Uri. - /// Format items. - public static Uri FormatToUri(Uri uri, params object[] keys) - { - return new Uri(string.Format(uri.ToString(), keys)); - } - - /// - /// Adds query strings to a given uri. - /// - /// - /// Input uri. - /// Dictionnary of parameters to add. - public static Uri AddParametersToUri(Uri baseUri, Dictionary parameters) - { - StringBuilder sb = new StringBuilder(baseUri.ToString()); - - sb.Append("?"); - sb.Append(string.Join("&", parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value.ToString())))); - - return new Uri(sb.ToString()); - } - - #endregion Uri - } -} +/* + Kippt.NET Library for consuming Kippt APIs. + Copyright (C) 2012 Haythem Tlili + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; + +namespace Kippt +{ + /// + /// Common helpers. + /// + class Utils + { + #region Uri + + /// + /// Returns an Uri after replacement of the format item with the corresponding string representation. + /// + /// + /// Input Uri. + /// Format items. + public static Uri FormatToUri(Uri uri, params object[] keys) + { + return new Uri(string.Format(uri.ToString(), keys)); + } + + /// + /// Adds query strings to a given uri. + /// + /// + /// Input uri. + /// Dictionnary of parameters to add. + public static Uri AddParametersToUri(Uri baseUri, Dictionary parameters) + { + StringBuilder sb = new StringBuilder(baseUri.ToString()); + + sb.Append("?"); + sb.Append(string.Join("&", parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value.ToString())))); + + return new Uri(sb.ToString()); + } + + #endregion Uri + + #region Date + + /// + /// Converts a date to Unix time format. + /// + /// + /// + /// + /// Date to convert. + public static int ToUnixTime(DateTime date) + { + return (date - new DateTime(1970, 1, 1, 0, 0, 0)).Milliseconds; + } + + /// + /// Converts unix time format to a date. + /// + /// + /// Unix time date. + public static DateTime FromUnixTime(int date) + { + return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(date * 1000L); + } + + #endregion Date + } +} \ No newline at end of file