-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSearch.scala
74 lines (63 loc) · 2.29 KB
/
Search.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package codecheck.github.models
import org.json4s.JValue
import org.json4s.JArray
sealed abstract class SearchSort(val name: String) {
override def toString = name
}
object SearchSort {
//for serachRepositories
case object stars extends SearchSort("stars")
case object forks extends SearchSort("forks")
case object updated extends SearchSort("updated")
//for searchCode
case object indexed extends SearchSort("indexed")
//for searchIssues
case object comments extends SearchSort("comments")
case object created extends SearchSort("created")
//case object updated extends SearchSort("updated")
//for searchUser
case object followers extends SearchSort("followers")
case object repositories extends SearchSort("repositories")
case object joined extends SearchSort("joined")
}
case class SearchInput (
q: String,
sort: Option[SearchSort] = None,
order: SortDirection = SortDirection.desc
) extends AbstractInput
case class SearchRepositoryResult(value: JValue) extends AbstractJson(value) {
def total_count: Long = get("total_count").toLong
def incomplete_results: Boolean = boolean("incomplete_results")
lazy val items = (value \ "items") match {
case JArray(arr) => arr.map(new Repository(_))
case _ => Nil
}
}
case class searchCodeItems (value: JValue) extends AbstractJson(value){
def name: String = get("name")
lazy val Repo = new Repository(value \ "repository")
}
case class SearchCodeResult(value: JValue) extends AbstractJson(value) {
def total_count: Long = get("total_count").toLong
def incomplete_results: Boolean = boolean("incomplete_results")
lazy val items = (value \ "items") match {
case JArray(arr) => arr.map(new searchCodeItems(_))
case _ => Nil
}
}
case class SearchIssueResult(value: JValue) extends AbstractJson(value) {
def total_count: Long = get("total_count").toLong
def incomplete_results: Boolean = boolean("incomplete_results")
lazy val items = (value \ "items") match {
case JArray(arr) => arr.map(new Issue(_))
case _ => Nil
}
}
case class SearchUserResult(value: JValue) extends AbstractJson(value) {
def total_count: Long = get("total_count").toLong
def incomplete_results: Boolean = boolean("incomplete_results")
lazy val items = (value \ "items") match {
case JArray(arr) => arr.map(new User(_))
case _ => Nil
}
}