<commit_before>package com.elliottsj.ftw.protobus

import android.content.Context
import com.android.volley.Response.{ErrorListener, Listener}
import com.android.volley.toolbox.Volley
import com.android.volley.{Request, RequestQueue, VolleyError}
import com.elliottsj.ftw.network.ByteRequest
import com.elliottsj.ftw.util.AsyncTaskContext
import com.elliottsj.protobus.{Agency, FeedMessage}

import scala.concurrent.{Future, Promise}

class Protobus(context: Context) extends AsyncTaskContext {
  final val API_HOST = "http://protobus.fasterthanwalking.com"

  // Instantiate the RequestQueue
  val queue: RequestQueue = Volley.newRequestQueue(context)

  private def get(path: String): Future[FeedMessage] = {
    val p = Promise[FeedMessage]()

    // Add a byte request to the RequestQueue
    queue.add(new ByteRequest(Request.Method.GET, API_HOST + path, new Listener[Array[Byte]] {
      override def onResponse(response: Array[Byte]): Unit = p success FeedMessage.parseFrom(response)
    }, new ErrorListener {
      override def onErrorResponse(err: VolleyError): Unit = throw err
    }))

    p.future
  }

  def getAgencies: Future[Array[Agency]] = for(message <- get("/agencies")) yield message.entities.map(_.getAgency).toArray
}

object Protobus {
  def apply(context: Context) = new Protobus(context)
}<commit_msg>Add getStops method<commit_after>package com.elliottsj.ftw.protobus

import android.content.Context
import com.android.volley.Response.{ErrorListener, Listener}
import com.android.volley.toolbox.Volley
import com.android.volley.{Request, RequestQueue, VolleyError}
import com.elliottsj.ftw.network.ByteRequest
import com.elliottsj.ftw.util.AsyncTaskContext
import com.elliottsj.protobus.{Stop, Agency, FeedMessage}

import scala.concurrent.{Future, Promise}

/**
 * A lightweight wrapper for calling the Protobus HTTP API
 *
 * @param context a context from which to construct a request queue
 */
class Protobus(context: Context) extends AsyncTaskContext {
  final val API_HOST = "http://protobus.fasterthanwalking.com"

  // Instantiate the RequestQueue
  val queue: RequestQueue = Volley.newRequestQueue(context)

  private def get(path: String): Future[FeedMessage] = {
    val p = Promise[FeedMessage]()

    // Add a byte request to the RequestQueue
    queue.add(new ByteRequest(Request.Method.GET, API_HOST + path, new Listener[Array[Byte]] {
      override def onResponse(response: Array[Byte]): Unit = p success FeedMessage.parseFrom(response)
    }, new ErrorListener {
      override def onErrorResponse(err: VolleyError): Unit = throw err
    }))

    p.future
  }

  def getAgencies: Future[Array[Agency]] =
    for(message <- get("/agencies")) yield
      message.entities.map(_.getAgency).toArray

  def getStops(agency: Agency): Future[Array[Stop]] =
    for(message <- get(s"/agencies/${agency.getNextbusFields.agencyTag}")) yield
      message.entities.map(_.getStop).toArray
}

object Protobus {
  def apply(context: Context) = new Protobus(context)
}
{'fraction_non_alphanumeric': 0.11007338225483655, 'fraction_numerical': 0.0, 'mean_word_length': 4.7784200385356455, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6439167', 'n_tokens_mistral': 939, 'n_tokens_neox': 910, 'n_words': 215}