Skip to content

Commit

Permalink
Change to Lift-style logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbriccetti committed Dec 13, 2009
1 parent 25cb643 commit 600cbd5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/birdshow/model/flickr/Flickr.scala
Expand Up @@ -4,11 +4,11 @@ import java.net.URLEncoder
import java.util.Random
import xml.NodeSeq
import flickr.{Photo, PhotoSet, FlickrUser, PictureIdAndSizes}
import birdshow.util.{XmlFetcher, Parallelizer, Loggable}
import birdshow.util.{XmlFetcher, Parallelizer}

case class PhotoAndSizes(val photo: Photo, val pictureIdAndSizes: PictureIdAndSizes)

object Flickr extends Loggable {
object Flickr {

private val urlPart1 = "http://api.flickr.com/services/rest/?method=flickr."
private val apiKey = "&api_key=979e4a1aa2eb498c845415e254e70f53"
Expand All @@ -35,7 +35,7 @@ object Flickr extends Loggable {
photos(new Random().nextInt(numPhotos)).url("")
}

def getSets: Seq[PhotoSet] = getUser.sets
def getSets: Seq[PhotoSet] = getUser.photoSets

def getFromFlickr(urlBody: String): NodeSeq = XmlFetcher.get(urlPart1 + urlBody + apiKey)

Expand Down
14 changes: 5 additions & 9 deletions src/main/scala/birdshow/model/flickr/FlickrUser.scala
Expand Up @@ -2,30 +2,26 @@ package birdshow.model.flickr

import xml.NodeSeq
import birdshow.model.Flickr
import birdshow.util.Loggable

case class FlickrUser(val userName: String, val topCollectionTitle: String,
val homeSetTitle: String, val showSetTitle: String) extends Loggable {
val homeSetTitle: String, val showSetTitle: String) {

val userId: String = (Flickr.getFromFlickr("people.findByUsername&username=" +
Flickr.enc(userName)) \ "user" \ "@nsid").text

private val collections: NodeSeq =
Flickr.getFromFlickr("collections.getTree&user_id=" + userId) \\ "collection"

private val setIds: Seq[String] = ((collections filter (
private val topCollectionSetIds: Seq[String] = ((collections filter (
c => (c \ "@title") == topCollectionTitle)) \\ "set").map(set => (set \ "@id").text)

private val allSets: Seq[PhotoSet] =
private val allPhotoSets: Seq[PhotoSet] =
(Flickr.getFromFlickr("photosets.getList&user_id=" + userId) \
"photosets" \ "photoset").map(PhotoSet.apply)

val sets: Seq[PhotoSet] = allSets filter (s => setIds.contains(s.id))
val photoSets: Seq[PhotoSet] = allPhotoSets filter (s => topCollectionSetIds.contains(s.id))

private def getSetIdFromTitle(title: String): String = {
val set = allSets.find(_.title == title).get
set.id
}
private def getSetIdFromTitle(title: String) = allPhotoSets.find(_.title == title).get.id

val homeSetId: String = getSetIdFromTitle(homeSetTitle)
val showSetId: String = getSetIdFromTitle(showSetTitle)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/birdshow/snippet/Pictures.scala
Expand Up @@ -5,9 +5,8 @@ import xml.{Text, NodeSeq}
import net.liftweb.util.{Full}
import net.liftweb.http.{RequestVar, SHtml, S}
import birdshow.model.Flickr
import birdshow.util.{Loggable}

class Pictures extends Loggable with PhotoRows {
class Pictures extends PhotoRows {
private object searchText extends RequestVar("")

def search(content: NodeSeq) = bind("search", content,
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/birdshow/snippet/Shows.scala
Expand Up @@ -2,10 +2,9 @@ package birdshow.snippet

import net.liftweb.util.Helpers._
import xml.NodeSeq
import birdshow.util.Loggable
import birdshow.model.{PhotoAndSizes, Flickr}

class Shows extends Loggable with PhotoRows {
class Shows extends PhotoRows {

def showShowPictures(content: NodeSeq): NodeSeq = {
def pImg(photoAndSize: Option[PhotoAndSizes]): NodeSeq = photoAndSize match {
Expand Down
12 changes: 0 additions & 12 deletions src/main/scala/birdshow/util/Loggable.scala

This file was deleted.

5 changes: 3 additions & 2 deletions src/main/scala/birdshow/util/XmlFetcher.scala
Expand Up @@ -2,13 +2,14 @@ package birdshow.util

import xml.{Node, XML}
import java.net.{URL, HttpURLConnection}
import net.liftweb.util.Log

object XmlFetcher extends Loggable {
object XmlFetcher {
def get(urlString: String): Node = {
val conn = new URL(urlString).openConnection.asInstanceOf[HttpURLConnection]
val statusCode = conn.getResponseCode
if (statusCode != 200)
error(statusCode.toString)
Log.error(statusCode.toString)
XML.load(conn.getInputStream())
}
}
Expand Down

0 comments on commit 600cbd5

Please sign in to comment.