Permalink
Browse files

added some doc and polishing

  • Loading branch information...
1 parent e2bc9d0 commit 9ae21338d09388ea006f7a0d4e876822150d39a9 @mhausenblas committed Apr 9, 2012
Showing with 41 additions and 22 deletions.
  1. +1 −0 .gitignore
  2. +17 −10 README.md
  3. +23 −12 info.paygoo.core.scala
View
@@ -0,0 +1 @@
+*.class
View
@@ -14,20 +14,27 @@ Then you can run the built-in test:
...which should yield something like the following:
- <div>About &lt;a href=&quot;http://data.example.com/test#it&quot;&gt;pg0&lt;/a&gt;, last updated 2012-04-09</div>
- {"base" : "http:\/\/data.example.com\/test#", "label" : "pg0", "date" : 2012-04-09}
- base=http://data.example.com/test#, label=pg0, date=2012-04-09
- <http://data.example.com/test#it> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Thing> .
- <http://data.example.com/test#it> <http://purl.org/dc/terms/title> "pg0" .
- <http://data.example.com/test#it> <http://purl.org/dc/terms/date> "2012-04-09"^^<http://www.w3.org/2001/XMLSchema#date> .
+ As HTML:
+ <div>About <a href='http://data.example.com/#it'>pg0</a>, last updated 2012-04-09</div>
- [PayGooResource: base=http://data.example.com/test# | label=pg0 | date=2012-04-09]
+ As JSON:
+ {"id" : "http:\/\/data.example.com\/#it", "label" : "pg0", "modified" : 2012-04-09}
+ As plain text:
+ id=http://data.example.com/#it, label=pg0, modified=2012-04-09
+
+ As RDF/NTriple:
+ <http://data.example.com/#it> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Thing> .
+ <http://data.example.com/#it> <http://purl.org/dc/terms/title> "pg0" .
+ <http://data.example.com/#it> <http://purl.org/dc/terms/modified> "2012-04-09"^^<http://www.w3.org/2001/XMLSchema#date> .
+
+ [PayGooResource: id=http://data.example.com/#it | label=pg0 | modified=2012-04-09]
+
## Dependencies
-* Scala 2.9.1
-* [scardf](http://code.google.com/p/scardf/ "Scala RDF API - Google Project Hosting")
-* [spray](spray.cc "A suite of lightweight Scala libraries for building and consuming RESTful web services on top of Akka")
+* Tested against Scala 2.9.1
+* Using [scardf](http://code.google.com/p/scardf/ "Scala RDF API - Google Project Hosting") for RDF parsing and serialisation
+* Using [spray](spray.cc "A suite of lightweight Scala libraries for building and consuming RESTful web services on top of Akka") for HTTP interfacing
## License
@@ -7,7 +7,7 @@ import org.joda.time.LocalDate
package info.paygoo.core {
/**
- * Represent a PayGoo's serialisation (aka wire format).
+ * Represents a PayGoo's serialisation (aka wire format).
* A PayGoo MUST support all of the following four media types.
*
* @param mediatype as of http://www.iana.org/assignments/media-types/
@@ -21,12 +21,20 @@ package info.paygoo.core {
/**
* The core PayGoo class, just has a label.
*
+ * @param id the PayGoo identifier, MUST be a HTTP URI
* @param label a human-readable label for the PayGoo
*/
- abstract class PayGoo (val base: String, var label: String ) {
+ abstract class PayGoo (val pgid: String, var label: String ) {
val s = Vocabulary( "http://schema.org/" )
val dc = Vocabulary( "http://purl.org/dc/terms/" )
val bp = Vocabulary( "http://open-services.net/ns/basicProfile#" )
+
+ /**
+ * Returns a serialisation in the specified format, defaults to JSON.
+ *
+ * @param format the selected wire format, one of {HTML, JSON, Text, NTriple}
+ * @return a string representation in the selected wire format
+ */
def ser( format: WireFormat = JSON ) : String
}
@@ -36,35 +44,38 @@ package info.paygoo.core {
* @param rlabel a human-readable label for the PayGoo resource
* @return dunno
*/
- case class PayGooResource (rbase: String, rlabel: String ) extends PayGoo ( rbase, rlabel ) {
- private var r = Map ( "base" -> rbase, "label" -> rlabel, "date" -> new LocalDate())
- private val rself = r("base") + "it"
+ case class PayGooResource (rpgid: String, rlabel: String ) extends PayGoo ( rpgid, rlabel ) {
+ private var r = Map ( "id" -> rpgid, "label" -> rlabel, "modified" -> new LocalDate())
override def ser ( format: WireFormat = JSON ) : String = format match {
- case HTML => "<div>About <a href='" + rself + "'>" + r("label") + "</a>, last updated " + r("date") + "</div>"
+ case HTML => "<div>About <a href='" + r("id") + "'>" + r("label") + "</a>, last updated " + r("modified") + "</div>"
case JSON => JSONObject(r).toString
- case Text => "base=" + r("base") + ", label=" + r("label") + ", date=" + r("date")
- case NTriple => val g = Graph.build( UriRef( rself ) - (
+ case Text => "id=" + r("id") + ", label=" + r("label") + ", modified=" + r("modified")
+ case NTriple => val g = Graph.build( UriRef( r("id").toString ) - (
RDF.Type -> s.uriref("Thing"),
dc.uriref("title") -> r("label"),
- dc.uriref("date") -> r("date")
+ dc.uriref("modified") -> r("modified")
)
)
g.rend
}
- override def toString = "[PayGooResource: base=" + r("base") + " | label=" + r("label") + " | date=" + r("date") + "]"
+ override def toString = "[PayGooResource: id=" + r("id") + " | label=" + r("label") + " | modified=" + r("modified") + "]"
}
/**
- * Testing the resource ...
+ * Testing a sample PayGoo resource.
*/
object PayGooResource extends App {
- val r = new PayGooResource("http://data.example.com/test#", "pg0")
+ val r = new PayGooResource("http://data.example.com/#it", "pg0")
+ println("As HTML:")
println(r.ser(format=HTML))
+ println("\nAs JSON:")
println(r.ser(format=JSON))
+ println("\nAs plain text:")
println(r.ser(format=Text))
+ println("\nAs RDF/NTriple:")
println(r.ser(format=NTriple))
println(r)
}

0 comments on commit 9ae2133

Please sign in to comment.