Created
December 1, 2011 03:28
-
-
Save xuwei-k/1413277 to your computer and use it in GitHub Desktop.
redmine scala client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalaVersion := "2.9.1" | |
libraryDependencies ++= { | |
val liftV = "2.4-M5" | |
Seq( | |
"net.liftweb" %% "lift-json" % liftV, | |
"net.liftweb" %% "lift-json-ext" % liftV, | |
"org.scala-tools.time" %% "time" % "0.5" | |
) | |
} | |
initialCommands in console := { | |
Seq( | |
"net.liftweb.json._","org.scala_tools.time.Imports._" | |
).map{"import "+}.mkString("\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.liftweb.json._ | |
import java.net.{Authenticator,PasswordAuthentication} | |
import scala.io.Source | |
import org.scala_tools.time.Imports._ | |
object Main{ | |
// http://www.redmine.org/projects/redmine/wiki/Rest_api | |
val TIME_ENTRIES = "http://hogeRedmine.com/time_entries.json?project_id=your_project_name" | |
val USER = "your_user_name" | |
val PASS = "your_password" | |
def setAuth(user:String,pass:String){ | |
Authenticator.setDefault( | |
new Authenticator{ | |
override def getPasswordAuthentication = new PasswordAuthentication( | |
user,pass.toCharArray | |
) | |
} | |
) | |
} | |
def getJsonStr = Source.fromURL(TIME_ENTRIES).mkString | |
def getTimeEntries = { | |
setAuth(USER,PASS) | |
val json = getJsonStr | |
(parse(json) \ "time_entries").children.map{TimeEntry.apply} | |
} | |
def main(args:Array[String]){ | |
println(getTimeEntries) | |
} | |
} | |
case class TimeEntry( | |
comments :String, | |
project :Project, | |
created_on :DateTime, | |
issue :Issue, | |
activity :Activity, | |
updated_on :DateTime, | |
spent_on :String, | |
user :User, | |
id :Long | |
) | |
object TimeEntry{ | |
def apply(entry:JValue):TimeEntry = { | |
implicit val formats = DefaultFormats | |
entry.extract[TimeEntry] | |
} | |
} | |
case class Project(name:String,id:Long) | |
case class Issue(id:Long) | |
case class Activity(name:String,id:Long) | |
case class User(name:String,id:Long) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment