GithubHelp home page GithubHelp logo

backlog4s's Introduction

Backlog SDK for Scala

Goals

  1. Support All public Backlog Api
  2. Modular can use any http library if user want to switch. For now by default we use akka-http. Later we will provide support for others libraries
  3. Streaming support
  4. Setup webhook
  5. OAuth2 support

Optional Goals and interesting experiment

  1. Scalajs support
  2. GraphQL server
  3. Usage of auto code generation for protocol by analyse json files at compile-time or using cli tools

Installation

Add sonatype resolver

resolvers ++= Seq(
  Resolver.sonatypeRepo("snapshots")
)

Core

libraryDependencies += "com.github.chaabaj" %% "backlog4s-core" % "0.8.1-SNAPSHOT"

Using Akka to execute the requests

libraryDependencies += "com.github.chaabaj" %% "backlog4s-akka" % "0.8.1-SNAPSHOT"

Simple API usage

Look at backlog4s-test contain a program sample

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.github.chaabaj.backlog4s.datas._
import com.github.chaabaj.backlog4s.streaming.ApiStream
import com.github.chaabaj.backlog4s.apis.AllApi
import com.github.chaabaj.backlog4s.interpreters.BacklogHttpDslOnAkka

import scala.util.{Failure, Success}
import com.github.chaabaj.backlog4s.dsl.syntax._

object App {

  def usingAkka(apiUrl: String, apiKey: String): Unit = {
    implicit val system = ActorSystem("test")
    implicit val mat = ActorMaterializer()
    implicit val scheduler = monix.execution.Scheduler.Implicits.global

    val akkaHttpDsl = new BacklogHttpDslOnAkka()
    val allApi = new AllApi(apiUrl, AccessKey(apiKey))(akkaHttpDsl)
    import allApi._

    val task = for {
      projects <- projectApi.all().handleError
      issues <- issueApi.search(IssueSearch(projectIds = projects.map(_.id))).handleError
    } yield issues

    task.value.runToFuture.onComplete { response =>
      response match {
        case Success(data) =>
          println(data)
        case Failure(ex) =>
          ex.printStackTrace()
      }
      akkaHttpDsl.terminate()
      system.terminate()
    }
  }

  def main(args: Array[String]): Unit = {
    if (args.length > 1) {
      val apiUrl = args.apply(0)
      val apiKey = args.apply(1)
      usingAkka(apiUrl, apiKey)
    } else {
      println("Missing argument api url and api key")
    }
  }
}

Stream API usage example

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.github.chaabaj.backlog4s.datas._
import com.github.chaabaj.backlog4s.streaming.ApiStream
import com.github.chaabaj.backlog4s.apis.AllApi
import com.github.chaabaj.backlog4s.interpreters.BacklogHttpDslOnAkka

import scala.util.{Failure, Success}
import com.github.chaabaj.backlog4s.dsl.syntax._

object App {

  def usingAkka(apiUrl: String, apiKey: String): Unit = {
    implicit val system = ActorSystem("test")
    implicit val mat = ActorMaterializer()
    implicit val scheduler = monix.execution.Scheduler.Implicits.global

    val akkaHttpDsl = new BacklogHttpDslOnAkka()
    val allApi = new AllApi(apiUrl, AccessKey(apiKey))(akkaHttpDsl)
    import allApi._

    val stream = ApiStream.stream(10000, 4)(
      (index, count) => issueApi.search(IssueSearch(offset = index, count = count))
    ).map { issues =>
      println(issues.map(_.summary).mkString("\n"))
      println()
      issues
    }

    stream.foreach(println).onComplete { response =>
      response match {
        case Success(_) =>
          println("Done")
        case Failure(ex) =>
          ex.printStackTrace()
      }
      akkaHttpDsl.terminate()
      system.terminate()
    }
  }

  def main(args: Array[String]): Unit = {
    if (args.length > 1) {
      val apiUrl = args.apply(0)
      val apiKey = args.apply(1)
      usingAkka(apiUrl, apiKey)
    } else {
      println("Missing argument api url and api key")
    }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.