[banshee: 22/61] [InternetArchive] Reorganize some code
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee: 22/61] [InternetArchive] Reorganize some code
- Date: Tue, 3 Nov 2009 06:29:41 +0000 (UTC)
commit 7ed94dd45bae3aa0856350a5b5a3b3491c4e1f02
Author: Gabriel Burt <gabriel burt gmail com>
Date: Sat Oct 10 15:09:27 2009 -0700
[InternetArchive] Reorganize some code
.../File.cs | 5 +-
.../InternetArchive/JsonExtensions.cs | 93 ++++++++++++++++++++
.../InternetArchive/JsonItem.cs | 57 ------------
.../Banshee.InternetArchive/InternetArchive/README | 2 +
.../Review.cs | 5 +-
src/Extensions/Banshee.InternetArchive/Makefile.am | 7 +-
6 files changed, 101 insertions(+), 68 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/File.cs
similarity index 96%
rename from src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs
rename to src/Extensions/Banshee.InternetArchive/InternetArchive/File.cs
index 6749412..6b26bd1 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/File.cs
@@ -34,10 +34,7 @@ using Mono.Unix;
using Hyena.Json;
-using InternetArchive;
-using IA=InternetArchive;
-
-namespace Banshee.InternetArchive
+namespace InternetArchive
{
public class File
{
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs
new file mode 100644
index 0000000..efe8822
--- /dev/null
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs
@@ -0,0 +1,93 @@
+//
+// JsonExtensions.cs
+//
+// Author:
+// Gabriel Burt <gabriel burt gmail com>
+//
+// Copyright (c) 2009 Gabriel Burt
+//
+// 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.
+
+using System;
+using System.IO;
+using System.Net;
+using System.Linq;
+using System.Collections.Generic;
+
+using Hyena.Json;
+
+namespace InternetArchive
+{
+ public static class JsonExtensions
+ {
+ public static T Get<T> (this JsonObject item, string key)
+ {
+ object result;
+ if (item.TryGetValue (key, out result)) {
+ try {
+ if (result is T) {
+ result = (T)result;
+ } else if (result is string) {
+ var type = typeof (T);
+ string i = result as string;
+ if (type == typeof(Int32)) {
+ result = Int32.Parse (i);
+ } else if (type == typeof(Int64)) {
+ result = Int64.Parse (i);
+ } else if (type == typeof(double)) {
+ result = Double.Parse (i);
+ } else if (type == typeof(TimeSpan)) {
+ int h = 0, m = 0, s = 0;
+ var bits = i.Split (':');
+
+ if (bits.Length > 0)
+ s = Int32.Parse (bits[bits.Length - 1]);
+
+ if (bits.Length > 1)
+ m = Int32.Parse (bits[bits.Length - 2]);
+
+ if (bits.Length > 2)
+ h = Int32.Parse (bits[bits.Length - 3]);
+
+ result = new TimeSpan (h, m, s);
+ }
+ } else {
+ result = default (T);
+ }
+
+ return (T) result;
+ } catch {
+ Console.WriteLine ("Couldn't cast {0} ({1}) as {2} for key {3}", result, result.GetType (), typeof(T), key);
+ }
+ }
+
+ return default (T);
+ }
+
+ public static string GetJoined (this JsonObject item, string key, string with)
+ {
+ var ary = item.Get<System.Collections.IEnumerable> (key);
+ if (ary != null) {
+ return String.Join (with, ary.Cast<object> ().Select (o => o.ToString ()).ToArray ());
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonItem.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonItem.cs
index 7d4d1c4..141d467 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonItem.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonItem.cs
@@ -34,63 +34,6 @@ using Hyena.Json;
namespace InternetArchive
{
- public static class JsonExtensions
- {
- public static T Get<T> (this JsonObject item, string key)
- {
- object result;
- if (item.TryGetValue (key, out result)) {
- try {
- if (result is T) {
- result = (T)result;
- } else if (result is string) {
- var type = typeof (T);
- string i = result as string;
- if (type == typeof(Int32)) {
- result = Int32.Parse (i);
- } else if (type == typeof(Int64)) {
- result = Int64.Parse (i);
- } else if (type == typeof(double)) {
- result = Double.Parse (i);
- } else if (type == typeof(TimeSpan)) {
- int h = 0, m = 0, s = 0;
- var bits = i.Split (':');
-
- if (bits.Length > 0)
- s = Int32.Parse (bits[bits.Length - 1]);
-
- if (bits.Length > 1)
- m = Int32.Parse (bits[bits.Length - 2]);
-
- if (bits.Length > 2)
- h = Int32.Parse (bits[bits.Length - 3]);
-
- result = new TimeSpan (h, m, s);
- }
- } else {
- result = default (T);
- }
-
- return (T) result;
- } catch {
- Console.WriteLine ("Couldn't cast {0} ({1}) as {2} for key {3}", result, result.GetType (), typeof(T), key);
- }
- }
-
- return default (T);
- }
-
- public static string GetJoined (this JsonObject item, string key, string with)
- {
- var ary = item.Get<System.Collections.IEnumerable> (key);
- if (ary != null) {
- return String.Join (with, ary.Cast<object> ().Select (o => o.ToString ()).ToArray ());
- }
-
- return null;
- }
- }
-
public class JsonItem : Item
{
JsonObject item;
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/README b/src/Extensions/Banshee.InternetArchive/InternetArchive/README
new file mode 100644
index 0000000..8f045da
--- /dev/null
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/README
@@ -0,0 +1,2 @@
+There is documentation of the Internet Archive's APIs at
+http://www.archive.org/help/
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Review.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/Review.cs
similarity index 96%
rename from src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Review.cs
rename to src/Extensions/Banshee.InternetArchive/InternetArchive/Review.cs
index 2157666..6e25482 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Review.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/Review.cs
@@ -34,10 +34,7 @@ using Mono.Unix;
using Hyena.Json;
-using InternetArchive;
-using IA=InternetArchive;
-
-namespace Banshee.InternetArchive
+namespace InternetArchive
{
public class Review
{
diff --git a/src/Extensions/Banshee.InternetArchive/Makefile.am b/src/Extensions/Banshee.InternetArchive/Makefile.am
index 9ed5b7f..f65c741 100644
--- a/src/Extensions/Banshee.InternetArchive/Makefile.am
+++ b/src/Extensions/Banshee.InternetArchive/Makefile.am
@@ -7,21 +7,22 @@ SOURCES = \
InternetArchive/Collection.cs \
InternetArchive/Field.cs \
InternetArchive/FieldValue.cs \
+ InternetArchive/File.cs \
InternetArchive/MediaType.cs \
InternetArchive/ResultsFormat.cs \
InternetArchive/Search.cs \
InternetArchive/Results.cs \
+ InternetArchive/Review.cs \
InternetArchive/Item.cs \
- InternetArchive/JsonResults.cs \
+ InternetArchive/JsonExtensions.cs \
InternetArchive/JsonItem.cs \
+ InternetArchive/JsonResults.cs \
InternetArchive/Sort.cs \
Banshee.InternetArchive/Actions.cs \
- Banshee.InternetArchive/File.cs \
Banshee.InternetArchive/Item.cs \
Banshee.InternetArchive/ItemSource.cs \
Banshee.InternetArchive/ItemSourceContents.cs \
Banshee.InternetArchive/HeaderFilters.cs \
- Banshee.InternetArchive/Review.cs \
Banshee.InternetArchive/Source.cs
RESOURCES = \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]