Last active
July 6, 2016 18:36
-
-
Save pentaho-nbaker/3445ff9344c0a2268f582ae3934ead2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 scala.util.{Failure, Success} | |
import scala.concurrent.duration._ | |
import akka.actor.ActorSystem | |
import akka.pattern.ask | |
import akka.event.Logging | |
import akka.io.IO | |
import spray.json.{DefaultJsonProtocol, JsonFormat} | |
import spray.can.Http | |
import spray.httpx.SprayJsonSupport | |
import spray.client.pipelining._ | |
import spray.util._ | |
import scala.collection.generic.SeqFactory | |
import scala.io.Source | |
case class Repository(ssh_url: String) | |
object ElevationJsonProtocol extends DefaultJsonProtocol { | |
// implicit val locationFormat = jsonFormat2(Location) | |
implicit val repository = jsonFormat1(Repository) | |
} | |
object Main extends App { | |
// we need an ActorSystem to host our application in | |
implicit val system = ActorSystem("simple-spray-client") | |
import system.dispatcher // execution context for futures below | |
val log = Logging(system, getClass) | |
import ElevationJsonProtocol._ | |
import SprayJsonSupport._ | |
val pipeline = sendReceive ~> unmarshal[List[Repository]] | |
private val repos: List[String] = Source.fromFile( "/Users/nbaker/Desktop/repos.txt" ).getLines().map( _.trim ).filter( !_.equals("") ).toList | |
for( rep <- repos ){ | |
println(rep) | |
} | |
val responseFuture = pipeline { | |
Get("https://api.github.com/users/pentaho/repos?per_page=1000") | |
} | |
responseFuture onComplete { | |
case Success(reps) => | |
println( "missing" ) | |
reps.map(_.ssh_url).filter( r => !repos.exists( r.contains( _ ) ) ).sorted.foreach( ( rep ) => { println( rep ) } ) | |
log.info("worked") | |
shutdown() | |
case Success(somethingUnexpected) => | |
shutdown() | |
case Failure(error) => | |
shutdown() | |
} | |
def shutdown(): Unit = { | |
IO(Http).ask(Http.CloseAll)(1.second).await | |
system.shutdown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment