• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala NetHttpTransport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.google.api.client.http.javanet.NetHttpTransport的典型用法代码示例。如果您正苦于以下问题:Scala NetHttpTransport类的具体用法?Scala NetHttpTransport怎么用?Scala NetHttpTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了NetHttpTransport类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Googlemonitoringapiworks

//设置package包名称以及导入依赖的类
package com.berkgokden

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.monitoring.v3.{Monitoring, MonitoringScopes}

object Googlemonitoringapiworks extends App {
  println("Hello, google-monitoring-api-works")

  val project = "your-project-name" // you should have one on google.
  val projectResource = "projects/" + project

  // Grab the Application Default Credentials from the environment.
  // Download authentication json form Google Cloud and Put conf.json into resources folder!
  val resourceAsStream = getClass.getResourceAsStream("/conf.json")
  println("ok")
  val credential = GoogleCredential.fromStream(resourceAsStream)
    .createScoped(MonitoringScopes.all())

  println(credential.getServiceAccountId) // this only works if you have a service account

  // Create and return the CloudMonitoring service object
  val httpTransport = new NetHttpTransport()
  val jsonFactory = new JacksonFactory()
  val service = new Monitoring.Builder(httpTransport,
    jsonFactory, credential)
    .setApplicationName("Monitoring Sample")
    .build()

  val res = service.projects().metricDescriptors().list(projectResource).execute()
  println(res.toPrettyString)
} 
开发者ID:bgokden,项目名称:google-monitoring-api-works,代码行数:34,代码来源:Googlemonitoringapiworks.scala


示例2: AppModule

//设置package包名称以及导入依赖的类
package conf

import java.time.{Clock, ZoneId}

import akka.actor.{Actor, ActorRef, Props}
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.util.store.AbstractDataStoreFactory
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import com.google.inject.util.Providers
import controllers.AppController
import play.api.libs.concurrent.{Akka, AkkaGuiceSupport}
import services._
import services.support.SystemClock

import scala.reflect.ClassTag

class AppModule extends AbstractModule {
  def configure = {
    bind(classOf[AppController]).asEagerSingleton // in prod mode all dependencies of AppController get built at startup time
    bind(classOf[AbstractDataStoreFactory]).to(classOf[RepositoryDataStoreFactory])
    bind(classOf[GoogleIdTokenVerifier]).toInstance(new GoogleIdTokenVerifier.Builder(new NetHttpTransport, new JacksonFactory).build)
    bind(classOf[Clock]).toInstance(new SystemClock(ZoneId.systemDefault()))
  }
}

class AkkaModule extends AbstractModule with AkkaGuiceSupport {
  def configure = {
    bindActorNoEager[SuperSupervisorActor](SuperSupervisorActor.actorName)
    bindActorFactory[UserSupervisorActor, UserSupervisorActor.Factory]
  }

  private def bindActorNoEager[T <: Actor : ClassTag](name: String, props: Props => Props = identity): Unit = {
    binder.bind(classOf[ActorRef])
      .annotatedWith(Names.named(name))
      .toProvider(Providers.guicify(Akka.providerOf[T](name, props)))
  }
} 
开发者ID:phdezann,项目名称:connectus,代码行数:41,代码来源:Module.scala


示例3: GoogleAuthorization

//设置package包名称以及导入依赖的类
package services

import java.io.StringReader
import javax.inject.{Inject, Singleton}

import conf.AppConf
import com.google.api.client.auth.oauth2.Credential
import com.google.api.client.auth.openidconnect.IdTokenResponse
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow.Builder
import com.google.api.client.googleapis.auth.oauth2.{GoogleAuthorizationCodeFlow, GoogleAuthorizationCodeTokenRequest, GoogleClientSecrets, GoogleTokenResponse}
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.util.store.AbstractDataStoreFactory
import com.google.api.services.gmail.Gmail
import com.google.api.services.gmail.GmailScopes._
import com.google.common.collect.Lists._
import common._

import scala.concurrent.{ExecutionContext, Future}

object GoogleAuthorization {
  val ApplicationName = "Connectus"
  val Scopes = newArrayList(GMAIL_COMPOSE, GMAIL_MODIFY)
  val transport = new NetHttpTransport
  val factory = new JacksonFactory
}

@Singleton
class GoogleAuthorization @Inject()(implicit exec: ExecutionContext, appConf: AppConf, dataStoreFactory: AbstractDataStoreFactory) {

  private def loadSecrets: GoogleClientSecrets =
    GoogleClientSecrets.load(GoogleAuthorization.factory, new StringReader(appConf.getGoogleClientSecret))

  private lazy val flow: GoogleAuthorizationCodeFlow = new Builder(GoogleAuthorization.transport, GoogleAuthorization.factory, loadSecrets, GoogleAuthorization.Scopes) //
    .setDataStoreFactory(dataStoreFactory)
    .setAccessType("offline") // So we can get a refresh and access the protected service while the user is gone
    .setApprovalPrompt("auto").build

  def addCredentials(userId: String, refreshToken: String) = {
    val tokenResponse: IdTokenResponse = new IdTokenResponse
    tokenResponse.setRefreshToken(refreshToken)
    flow.createAndStoreCredential(tokenResponse, userId)
  }

  def convert(authorisationCode: String): Future[GoogleTokenResponse] = {
    val request: GoogleAuthorizationCodeTokenRequest = flow.newTokenRequest(authorisationCode)
    // as specified in https://developers.google.com/identity/protocols/CrossClientAuth, the redirect_uri argument must be equal to null
    request.set("redirect_uri", null)
    Future {concurrent.blocking {request.execute()}}
  }

  def getService(accountId: String): Future[Gmail] =
    Future {concurrent.blocking {Option(flow.loadCredential(accountId))}}
      .flatMap(fromOption(_))
      .map(gmail(_))

  private def gmail(credential: Credential): Gmail =
    new Gmail.Builder(GoogleAuthorization.transport, GoogleAuthorization.factory, credential).setApplicationName(GoogleAuthorization.ApplicationName).build
} 
开发者ID:phdezann,项目名称:connectus,代码行数:60,代码来源:GoogleAuthorization.scala


示例4: BigQueryClient

//设置package包名称以及导入依赖的类
package com.example.prodspark.client

import java.io.IOException

import com.example.prodspark.util.RetryUtil
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.bigquery.{Bigquery, BigqueryScopes}
import com.google.api.services.bigquery.model._
import com.google.cloud.hadoop.io.bigquery.BigQueryStrings
import org.slf4j.LoggerFactory

import scala.collection.JavaConverters._

object BigQueryClient {
  private val SCOPES = List(BigqueryScopes.BIGQUERY).asJava

  private val bigquery: Bigquery = {
    val credential = GoogleCredential.getApplicationDefault.createScoped(SCOPES)
    new Bigquery.Builder(new NetHttpTransport, new JacksonFactory, credential)
      .setApplicationName("spark-bigquery")
      .build()
  }

  
  def streamingInsert(
    rows: Seq[TableDataInsertAllRequest.Rows],
    tableSpec: String,
    projectId: String
  ): Unit = {
    lazy val tableRef = BigQueryStrings.parseTableReference(tableSpec)

    val req = new TableDataInsertAllRequest()
      .setRows(rows.asJava)
      .setIgnoreUnknownValues(true)

    RetryUtil.retry(3) {
      val response = insertAll(tableRef, req)
      if (response.getInsertErrors != null) {
        log.error("Error inserting into BigQuery: " + response.getInsertErrors.toString)
        throw new IOException(response.getInsertErrors.toString)
      }
    }
  }

  private val log = LoggerFactory.getLogger(this.getClass)
} 
开发者ID:rvenkatesh25,项目名称:spark-streaming-gcp,代码行数:49,代码来源:BigQueryClient.scala


示例5: RealPaymentExpressIT

//设置package包名称以及导入依赖的类
package com.wix.pay.paymentexpress.it

import com.google.api.client.http.javanet.NetHttpTransport
import com.wix.pay.creditcard.{CreditCard, CreditCardOptionalFields, PublicCreditCardOptionalFields, YearMonth}
import com.wix.pay.model.{CurrencyAmount, Payment}
import com.wix.pay.paymentexpress.PaymentexpressGateway
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope

class RealPaymentExpressIT extends SpecWithJUnit {
  skipAll

  "Reat Payment Express" should {
    "create purchase" in new ctx {
      gateway.sale(credentials, creditCard, payment, None, None) must beSuccessfulTry
    }
  }

  trait ctx extends Scope {
    val credentials = """{"username":"******","password":"******"}"""

    val creditCard = CreditCard("4000000000000002", YearMonth(2025,2), Some(CreditCardOptionalFields(csc = Some("123"),
      Some(PublicCreditCardOptionalFields(holderId = Some("John Doe"), holderName = Some("John Doe"))))))
    val payment = Payment(CurrencyAmount("AUD", 202))
    val gateway = new PaymentexpressGateway(new NetHttpTransport().createRequestFactory())
  }
} 
开发者ID:wix,项目名称:libpay-paymentexpress,代码行数:28,代码来源:RealPaymentExpressIT.scala



注:本文中的com.google.api.client.http.javanet.NetHttpTransport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Route类代码示例发布时间:2022-05-23
下一篇:
Scala DefaultEnv类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap