Initial commit. Playing with VK api for the bot.
This commit is contained in:
40
src/main/scala/eu/xeppaka/bot1/AccessTokenActor.scala
Normal file
40
src/main/scala/eu/xeppaka/bot1/AccessTokenActor.scala
Normal file
@@ -0,0 +1,40 @@
|
||||
package eu.xeppaka.bot1
|
||||
|
||||
import akka.actor.{Actor, Props}
|
||||
import akka.http.scaladsl.Http
|
||||
import akka.http.scaladsl.model.{HttpEntity, HttpRequest, HttpResponse, StatusCodes}
|
||||
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
|
||||
import eu.xeppaka.bot1.AccessTokenActor.GetToken
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class AccessTokenActor extends Actor {
|
||||
import akka.pattern.pipe
|
||||
import context.dispatcher
|
||||
|
||||
private val OAUTH_URL_TEMPLATE = "https://oauth.vk.com/authorize?client_id=%d&scope=friends&redirect_uri=https://oauth.vk.com/blank.html&display=page&v=5.74&response_type=token"
|
||||
private implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))
|
||||
private val http = Http(context.system)
|
||||
|
||||
override def receive: Receive = {
|
||||
case GetToken(clientId) =>
|
||||
val uri = OAUTH_URL_TEMPLATE.format(clientId)
|
||||
val request = HttpRequest(uri = uri)
|
||||
|
||||
http.singleRequest(request).pipeTo(self)
|
||||
case HttpResponse(StatusCodes.OK, headers, entity, _) =>
|
||||
println("OK")
|
||||
entity.withoutSizeLimit().toStrict(1 second).pipeTo(self)
|
||||
case resp @ HttpResponse(code, _, _, _) =>
|
||||
println(s"Failed with HTTP code $code")
|
||||
case HttpEntity.Strict(contentType, data) =>
|
||||
println(data.utf8String)
|
||||
}
|
||||
}
|
||||
|
||||
object AccessTokenActor {
|
||||
|
||||
case class GetToken(clientId: Int)
|
||||
|
||||
def props: Props = Props[AccessTokenActor]
|
||||
}
|
||||
17
src/main/scala/eu/xeppaka/bot1/DialogActor.scala
Normal file
17
src/main/scala/eu/xeppaka/bot1/DialogActor.scala
Normal file
@@ -0,0 +1,17 @@
|
||||
package eu.xeppaka.bot1
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import akka.actor.Actor
|
||||
|
||||
class DialogActor extends Actor {
|
||||
private val dialogId = UUID.randomUUID()
|
||||
|
||||
override def receive: Receive = {
|
||||
case 1 =>
|
||||
}
|
||||
}
|
||||
|
||||
object DialogActor {
|
||||
|
||||
}
|
||||
31
src/main/scala/eu/xeppaka/bot1/VkApiTests.scala
Normal file
31
src/main/scala/eu/xeppaka/bot1/VkApiTests.scala
Normal file
@@ -0,0 +1,31 @@
|
||||
package eu.xeppaka.bot1
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.vk.api.sdk.client.VkApiClient
|
||||
import com.vk.api.sdk.client.actors.UserActor
|
||||
import com.vk.api.sdk.httpclient.HttpTransportClient
|
||||
|
||||
object VkApiTests {
|
||||
private val APP_ID = 6472591
|
||||
private val APP_SECRET = "iGClqTncCZpzEqD8m5Wt"
|
||||
private val USER_SECRET_CODE = "4180052ce419f0470d"
|
||||
|
||||
private val vkTransportClient = HttpTransportClient.getInstance()
|
||||
private val vkApiClient = new VkApiClient(vkTransportClient)
|
||||
|
||||
// private val actorSystem = ActorSystem("vk")
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
// val accessTokenActor = actorSystem.actorOf(AccessTokenActor.props)
|
||||
// accessTokenActor ! GetToken(APP_ID)
|
||||
|
||||
// val authResponse = vkApiClient.oauth()
|
||||
// .userAuthorizationCodeFlow(APP_ID, APP_SECRET, "https://oauth.vk.com/blank.html", USER_SECRET_CODE)
|
||||
// .execute()
|
||||
|
||||
val userActor = new UserActor(6242549, "2ab6508fbc2ff7d2a23fd07cf6b6cb79354abc6c1276447bf2bfb6bfe4bca5cc8d5ecc83dbead6efa04d4")
|
||||
|
||||
val resp = vkApiClient.messages().get(userActor).execute()
|
||||
println(resp)
|
||||
}
|
||||
}
|
||||
9
src/main/scala/example/Hello.scala
Normal file
9
src/main/scala/example/Hello.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package example
|
||||
|
||||
object Hello extends Greeting with App {
|
||||
println(greeting)
|
||||
}
|
||||
|
||||
trait Greeting {
|
||||
lazy val greeting: String = "hello"
|
||||
}
|
||||
9
src/test/scala/example/HelloSpec.scala
Normal file
9
src/test/scala/example/HelloSpec.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package example
|
||||
|
||||
import org.scalatest._
|
||||
|
||||
class HelloSpec extends FlatSpec with Matchers {
|
||||
"The Hello object" should "say hello" in {
|
||||
Hello.greeting shouldEqual "hello"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user