Skip to content

Updated dependencies to scala 2.10 and latest akka/spray versions #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ The Facebook Graph API is represented as a trait; each action that can be perfor
``` scala
//setup
implicit val system = ActorSystem()
val ioBridge = IOExtension(system).ioBridge()
val httpClient = system.actorOf(Props(new HttpClient(ioBridge)))
val facebookApiConduit = system.actorOf(
props = Props(new HttpConduit(httpClient, "graph.facebook.com", 443, sslEnabled = true)),
name = "facebook-api-conduit"
)
val facebook = new SprayClientFacebookGraphApi(facebookApiConduit)
implicit val timeout = Timeout(10 seconds)
implicit val ec = scala.concurrent.ExecutionContext.Implicits.global

val facebook = Future[SprayClientFacebookGraphApi] = for {
Http.HostConnectorInfo(connector, _) <- IO(Http) ? Http.HostConnectorSetup("graph.facebook.com", 443, true)
} yield {
new SprayClientFacebookGraphApi(connector)
}

//examples
val token: String = ???
val user: Future[User] = facebook.getUser(token)
val friends: Future[Seq[User]] = facebook.getFriends(token)
val event: Future[CreatedComment] = facebook.createComment(photoId, "That is totally rad!", token)
val user: Future[User] = facebook.flatMap(_.getUser(token))
val friends: Future[Seq[User]] = facebook.flatMap(_.getFriends(token))
val event: Future[CreatedComment] = facebook.flatMap(_.createComment(photoId, "That is totally rad!", token))
```

### License
Expand Down
71 changes: 12 additions & 59 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,23 @@ organization := "com.pongr"

name := "spracebook"

scalaVersion := "2.9.1"
scalaVersion := "2.11.5"

resolvers ++= Seq(
"Spray" at "http://repo.spray.io/"
"Spray" at "http://repo.spray.io/",
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"

)

libraryDependencies ++= {
val spray = "1.0-M7"
val akka = "2.0.5"
val spray = "1.3.2"
val akka = "2.3.9"
Seq(
"io.spray" % "spray-client" % spray,
"io.spray" % "spray-json_2.9.2" % "1.2.3",
"com.typesafe.akka" % "akka-actor" % akka,
"org.clapper" %% "grizzled-slf4j" % "0.6.10",
"org.specs2" %% "specs2" % "1.12.4" % "test"
"io.spray" % "spray-client_2.11" % spray,
"io.spray" % "spray-json_2.11" % "1.3.1",
"com.typesafe.akka" % "akka-actor_2.11" % akka,
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2",
"joda-time" % "joda-time" % "2.7",
"org.joda" % "joda-convert" % "1.7"
)
}

seq(sbtrelease.Release.releaseSettings: _*)

//http://www.scala-sbt.org/using_sonatype.html
//https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
publishTo <<= version { v: String =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots/")
else Some("releases" at nexus + "service/local/staging/deploy/maven2/")
}

publishMavenStyle := true

publishArtifact in Test := false

pomIncludeRepository := { _ => false }

licenses := Seq("Apache-2.0" -> url("http://opensource.org/licenses/Apache-2.0"))

homepage := Some(url("http://github.com/pongr/spracebook"))

organizationName := "Pongr"

organizationHomepage := Some(url("http://pongr.com"))

description := "Scala signed requests"

pomExtra := (
<scm>
<url>[email protected]:pongr/spracebook.git</url>
<connection>scm:git:[email protected]:pongr/spracebook.git</connection>
</scm>
<developers>
<developer>
<id>zcox</id>
<name>Zach Cox</name>
<url>https://github.com/zcox</url>
</developer>
<developer>
<id>pcetsogtoo</id>
<name>Byamba Tumurkhuu</name>
<url>https://github.com/pcetsogtoo</url>
</developer>
<developer>
<id>bayarmunkh</id>
<name>Bayarmunkh Davaadorj</name>
<url>https://github.com/bayarmunkh</url>
</developer>
</developers>
)
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.7
7 changes: 0 additions & 7 deletions project/plugins.sbt

This file was deleted.

8 changes: 6 additions & 2 deletions src/main/scala/FacebookGraphApi.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package spracebook

import akka.dispatch.Future
import scala.concurrent.Future
import FacebookGraphApiJsonProtocol._

trait FacebookGraphApi {
Expand Down Expand Up @@ -36,5 +36,9 @@ trait FacebookGraphApi {

def getApplicationOpenGraphActionClick(appId: String, accessToken: String, since: Long, until: Long): Future[Seq[Insight]]

def getApplicationOpenGraphActionImpressions(appId: String, accessToken: String, since: Long, until: Long): Future[Seq[Insight]]
def getApplicationOpenGraphActionImpressions(appId: String, accessToken: String, since: Long, until: Long): Future[Seq[Insight]]


//Get events
def getEvents(accessToken: String, since: Option[String] = None, until: Option[String] = None): Future[Seq[Event]]
}
77 changes: 47 additions & 30 deletions src/main/scala/FacebookGraphApiJsonProtocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
user_id: Long,
issued_at: Option[Long],
expires_at: Long,
scopes: Seq[String]
)
scopes: Seq[String])

case class TokenDataWrapper(data: TokenData)

case class AccessToken(
access_token: String,
expires: Long
)
expires: Long)

object AccessToken {
//for unmarshalling response from Graph API: String => AccessToken
Expand All @@ -35,8 +33,7 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
case class Image(
width: Int,
height: Int,
source: String
)
source: String)

object Image {
implicit val ordering: Ordering[Image] = new Ordering[Image] {
Expand All @@ -47,24 +44,20 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
case class Photo(
id: String,
name: Option[String], //this is the photo caption
images: Seq[Image]
)
images: Seq[Image])

case class Cursors(
after: String,
before: String
)
before: String)

case class Paging(
cursors: Option[Cursors],
next: Option[String],
previous: Option[String]
)
previous: Option[String])

case class Response[T](
data: Seq[T],
paging: Option[Paging]
)
paging: Option[Paging])

case class UserProfilePic (url: String, is_silhouette: Boolean)
case class UserProfilePicContainer (data: UserProfilePic)
Expand All @@ -79,8 +72,8 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
email: Option[String],
link: Option[String],
gender: Option[String],
picture: Option[UserProfilePicContainer]
) {
picture: Option[UserProfilePicContainer]){

// Ignores Facebook default photo
def profilePic: Option[String] = picture.flatMap(p => if (p.data.is_silhouette) None else Some(p.data.url))
}
Expand All @@ -94,8 +87,7 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
//{"id":"100914593450999","photos":["100914610117664"]}
case class CreatedStory(
id: String,
photos: Seq[String]
)
photos: Seq[String])

//{"id":"4286226694008_1953664"}
case class CreatedComment(id: String)
Expand All @@ -107,14 +99,12 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
can_remove: Boolean,
created_time: String,
like_count: Int,
user_likes: Boolean
)
user_likes: Boolean)

case class Properties(
name: String,
text: String,
href: String
)
href: String)

case class Share(
id: String,
Expand All @@ -128,30 +118,52 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {
properties: Seq[Properties],
status_type: String,
object_id: String,
created_time: String
)
created_time: String)

case class Insight(
id: String,
name: String,
period: String,
values: Seq[InsightDataPoint],
title: String,
description: String
)
description: String)

case class InsightValue(
action_type_id: Long,
action_type_name: String,
object_type_id: Long,
object_type_name: String,
value: Int
)
value: Int)

case class InsightDataPoint(
value: Seq[InsightValue],
end_time: String
)
end_time: String)




case class EventCoverPhoto(
cover_id: Option[String],
source: Option[String],
offset_y: Option[Int],
offset_x: Option[Int])

case class EventOwner(
name: String,
id: String)

case class Event(
id: String,
cover: Option[EventCoverPhoto],
description: Option[String],
start_time: String,
end_time: Option[String],
location: Option[String],
ticket_uri: Option[String],
name: String,
timezone: Option[String],
owner: EventOwner)


case class Error(message: String, `type`: String, code: Int, error_subcode: Option[Int])
case class ErrorResponse(error: Error)
Expand Down Expand Up @@ -181,4 +193,9 @@ object FacebookGraphApiJsonProtocol extends DefaultJsonProtocol {

implicit val errorFormat = jsonFormat4(Error)
implicit val errorResponseFormat = jsonFormat1(ErrorResponse)

implicit val eventCoverPhotoFormat = jsonFormat4(EventCoverPhoto)
implicit val eventOwnerFormat = jsonFormat2(EventOwner)
implicit val eventFormat = jsonFormat10(Event)

}
Loading