[tomboy] Add new web API files.
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Subject: [tomboy] Add new web API files.
- Date: Mon, 18 May 2009 10:22:32 -0400 (EDT)
commit 98d228ec1ca368ff54f0232104354429007fee05
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Fri May 15 12:21:33 2009 -0700
Add new web API files.
---
Tomboy.mdp | 2 +
.../Addins/WebSyncService/Api/ResourceReference.cs | 35 +++++++
Tomboy/Addins/WebSyncService/Api/WebHelper.cs | 99 ++++++++++++++++++++
Tomboy/Addins/WebSyncService/Makefile.am | 4 +-
4 files changed, 139 insertions(+), 1 deletions(-)
diff --git a/Tomboy.mdp b/Tomboy.mdp
index 0193e55..690bb6a 100644
--- a/Tomboy.mdp
+++ b/Tomboy.mdp
@@ -151,6 +151,8 @@
<File name="Tomboy/Addins/WebSyncService/Api" subtype="Directory" buildaction="Compile" />
<File name="Tomboy/Addins/WebSyncService/Api/NoteInfo.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Addins/WebSyncService/Api/UserInfo.cs" subtype="Code" buildaction="Compile" />
+ <File name="Tomboy/Addins/WebSyncService/Api/ResourceReference.cs" subtype="Code" buildaction="Compile" />
+ <File name="Tomboy/Addins/WebSyncService/Api/WebHelper.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
diff --git a/Tomboy/Addins/WebSyncService/Api/ResourceReference.cs b/Tomboy/Addins/WebSyncService/Api/ResourceReference.cs
new file mode 100644
index 0000000..cdbcf4d
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Api/ResourceReference.cs
@@ -0,0 +1,35 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Sandy Armstrong <sanfordarmstrong gmail com>
+//
+
+using System;
+
+namespace Tomboy.WebSync.Api
+{
+ public class ResourceReference
+ {
+ public string Href { get; private set; }
+ public string ApiRef { get; private set; }
+ }
+}
diff --git a/Tomboy/Addins/WebSyncService/Api/WebHelper.cs b/Tomboy/Addins/WebSyncService/Api/WebHelper.cs
new file mode 100644
index 0000000..599fcf6
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Api/WebHelper.cs
@@ -0,0 +1,99 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Sandy Armstrong <sanfordarmstrong gmail com>
+//
+
+using System;
+using System.Net;
+using System.IO;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tomboy.WebSync.Api
+{
+ public class WebHelper
+ {
+ public string Get (string uri, IDictionary<string, string> queryParameters)
+ {
+ WebRequest request = BuildRequest (uri, queryParameters);
+ request.Method = "GET";
+
+ // TODO: Set ContentLength, UserAgent, Timeout, KeepAlive, Proxy, ContentType?
+ // (May only be available if we cast back to HttpWebRequest)
+
+ return ProcessResponse (request);
+ }
+
+ public string PutJson (string uri, IDictionary<string, string> queryParameters, string postValue)
+ {
+ WebRequest request = BuildRequest (uri, queryParameters);
+ request.Method = "POST";
+
+ // TODO: Set ContentLength, UserAgent, Timeout, KeepAlive, Proxy, ContentType?
+ // (May only be available if we cast back to HttpWebRequest)
+ request.ContentType = "application/json";
+
+ byte [] data = Encoding.UTF8.GetBytes (postValue);
+ request.ContentLength = data.Length;
+
+ // TODO: try/finally error handling
+ Stream requestStream = request.GetRequestStream ();
+ requestStream.Write (data, 0, data.Length);
+ requestStream.Close ();
+
+ return ProcessResponse (request);
+ }
+
+ private string ProcessResponse (WebRequest request)
+ {
+ string responseString;
+
+ // TODO: Error-checking
+ WebResponse response = request.GetResponse ();
+
+ using (StreamReader sr = new StreamReader (response.GetResponseStream ())) {
+ responseString = sr.ReadToEnd ();
+ }
+
+ return responseString;
+ }
+
+ private WebRequest BuildRequest (string uri, IDictionary<string, string> queryParameters)
+ {
+ StringBuilder urlBuilder = new StringBuilder (uri); // TODO: Capacity?
+ urlBuilder.Append ("?");
+ if (queryParameters != null) {
+ foreach (var param in queryParameters) {
+ urlBuilder.Append (param.Key);
+ urlBuilder.Append ("=");
+ urlBuilder.Append (param.Value);
+ urlBuilder.Append ("&");
+ }
+ }
+ // Get rid of trailing ? or &
+ urlBuilder.Remove (urlBuilder.Length - 1, 1);
+
+ return HttpWebRequest.Create (urlBuilder.ToString ());
+ }
+ }
+}
diff --git a/Tomboy/Addins/WebSyncService/Makefile.am b/Tomboy/Addins/WebSyncService/Makefile.am
index 3b434d7..a67fb35 100644
--- a/Tomboy/Addins/WebSyncService/Makefile.am
+++ b/Tomboy/Addins/WebSyncService/Makefile.am
@@ -21,7 +21,9 @@ CSFILES = \
$(srcdir)/WebSyncServer.cs \
$(srcdir)/WebSyncServiceAddin.cs \
$(srcdir)/Api/NoteInfo.cs \
- $(srcdir)/Api/UserInfo.cs
+ $(srcdir)/Api/ResourceReference.cs \
+ $(srcdir)/Api/UserInfo.cs \
+ $(srcdir)/Api/WebHelper.cs
RESOURCES = \
-resource:$(srcdir)/WebSyncService.addin.xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]