bitcoin-client

bitcoin client library for price ticker and wallet

git clone https://9o.is/git/bitcoin-client.git

HttpService.scala

(940B)


      1 package inc.pyc.bitcoin
      2 package service
      3 
      4 import dispatch._
      5 import Defaults._
      6 import net.liftweb.json.JsonAST.JValue
      7 import akka.actor._
      8 
      9 /**
     10  * Bitcoin service over HTTP communications.
     11  */
     12 private[bitcoin] trait HttpService {
     13   this: Actor with ActorLogging =>
     14 
     15   	/**
     16   	 *  Service's API
     17   	 */
     18 	protected val api: Req
     19 
     20 	/**
     21 	 *  Request headers
     22 	 */
     23 	protected val headers: Map[String, String] = Map()
     24 
     25 	/**
     26 	 *  Pretend to be another browser.
     27 	 *  Some API's like BitStamp will block connection otherwise.
     28 	 */
     29 	protected val userAgent = "Windows / Chrome 34: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36"
     30 
     31 	/**
     32 	 *  Request and get a json response.
     33 	 */
     34 	protected def request(req: Req): JValue = {
     35 	  val promise = retry.Backoff(max = 10) {
     36 	    () => Http.configure(_.setUserAgent(userAgent))(req <:< headers > as.lift.Json).either
     37 	  }
     38 	  promise().right.get
     39     }
     40 }