Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Check that user name is valid

  • Loading branch information...
commit ccd8ce97ebe33e63c3b919122702dbf97c2ddc11 1 parent 9397954
Brian Blaine authored December 09, 2011

Showing 1 changed file with 33 additions and 21 deletions. Show diff stats Hide diff stats

  1. 54  src/main/scala/Vain.scala
54  src/main/scala/Vain.scala
@@ -7,6 +7,8 @@ import scala.collection.mutable.ListBuffer
7 7
 case class Repository(has_downloads: Boolean, watchers: Int, url: String, has_wiki: Boolean, fork: Boolean, forks: Int, created_at: Option[Date], size: Int, private_repo: Option[Boolean], open_issues: Int, pushed_at: Option[Date], name: String, owner: String, has_issues: Boolean)
8 8
 case class Repositories(repos: List[Repository])
9 9
 
  10
+case class User(gravatar_id: String, company: String, name: String, created_at: Option[Date], location: String, public_repo_count: Int, public_gist_count: Int, blog: String, following_count: Int, id: Int, usertype: String, permission: String, followers_count: Int, login: String, email: String)
  11
+
10 12
 object Main {
11 13
   def fork(fork: Int): String = fork match {
12 14
     case 0 => "(FORK)"
@@ -18,36 +20,46 @@ object Main {
18 20
   def main(args: Array[String]) {
19 21
     val github = new Github()
20 22
     val name = args(0)
21  
-    val user = github.getUser(name)
  23
+    val user = github.getUser(name)    
22 24
 
23  
-    val login = (user \\ "login") match {
24  
-      case login: JField => login.value.values
25  
-      case _ => Nil
  25
+    val valid = user match {
  26
+      case validUser: JField => true
  27
+      case invalidUser: JObject => false
  28
+      case _ => false
26 29
     }
27 30
 
28  
-    val followers = (user \\ "followers_count") match {
29  
-      case followers: JField => followers.value.values
30  
-      case _ => Nil
31  
-    }
  31
+    if(valid){
  32
+      val login = (user \\ "login") match { 
  33
+	case login: JField => login.value.values
  34
+	case _ => Nil
  35
+      }
32 36
 
33  
-    val repo_count = (user \\ "public_repo_count") match {
34  
-      case repo_count: JField => repo_count.value.values
35  
-      case _ => Nil
36  
-    }
  37
+      val followers = (user \\ "followers_count") match {
  38
+	case followers: JField => followers.value.values
  39
+	case _ => Nil
  40
+      }
37 41
 
38  
-    //TODO - Only get repos if user valid.
39  
-    val jsonRepos = github.getRepos(name, repo_count.toString.toInt)
  42
+      val repo_count = (user \\ "public_repo_count") match {
  43
+	case repo_count: JField => repo_count.value.values
  44
+	case _ => Nil
  45
+      }
40 46
 
41  
-    System.out.println(login + " - " + followers + " followers - " + repo_count + " public repositories")
  47
+      //TODO - Only get repos if user valid.
  48
+      val jsonRepos = github.getRepos(name, repo_count.toString.toInt)
42 49
 
43  
-    var listRepos = ListBuffer[Repository]()
  50
+      System.out.println(login + " - " + followers + " followers - " + repo_count + " public repositories")
44 51
 
45  
-    for (i <- 0 until repo_count.toString.toInt) {
46  
-      listRepos += (jsonRepos \\ "repositories")(i).extract[Repository]
47  
-    }
  52
+      var listRepos = ListBuffer[Repository]()
  53
+
  54
+      for (i <- 0 until repo_count.toString.toInt) {
  55
+	  listRepos += (jsonRepos \\ "repositories")(i).extract[Repository]
  56
+      }
48 57
 
49  
-    val orderedrepos = listRepos.sortBy(_.watchers).reverse
  58
+      val orderedrepos = listRepos.sortBy(_.watchers).reverse
50 59
 
51  
-    orderedrepos.foreach(repo => printf("%-25s %12d %12s %12d %12s %6s\n", repo.name, repo.watchers, " watchers", repo.forks, " forks", fork(repo.forks)))
  60
+      orderedrepos.foreach(repo => printf("%-25s %12d %12s %12d %12s %6s\n", repo.name, repo.watchers, " watchers", repo.forks, " forks", fork(repo.forks)))
  61
+    }else{
  62
+      println("Invalid user")
  63
+    }
52 64
   }
53 65
 }

0 notes on commit ccd8ce9

Please sign in to comment.
Something went wrong with that request. Please try again.