class OneBusAway

Main class defines the way to interact with everything

Defining the version for this gem

Constants

VERSION

Version for one_bus_away gem

Attributes

api_method[RW]
client[R]
data[R]
http_response[R]
parameters[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/one_bus_away.rb, line 12
def initialize(options = {})
  @api_method = options[:api_method]
  @parameters = options[:parameters]
end

Public Instance Methods

arrivals_and_departures_for_stop(stop) click to toggle source

get arrivales and departunes for a stop with one arguement

# File lib/one_bus_away.rb, line 26
def arrivals_and_departures_for_stop(stop)
  @client = OneBusAway::Client.new(
    api_method: ['arrivals-and-departures-for-stop', "1_#{stop}"]
  )
  call_api
end
assign_data() click to toggle source

Assigns the http data to the @data instance variable

# File lib/one_bus_away.rb, line 34
def assign_data
  @data = client.http_response.data
end
call_api() click to toggle source

Short hand for building the URL, calling the API, and assigning the data to @data

# File lib/one_bus_away.rb, line 40
def call_api
  @client.build_url
  @client.get
  assign_data
end
current_time() click to toggle source

Returns the current time from the One Bus Away System

# File lib/one_bus_away.rb, line 18
def current_time
  @client = OneBusAway::Client.new(
    api_method: ['current-time']
  )
  call_api
end
filter_by_route() click to toggle source

filter the route by a specific route

# File lib/one_bus_away.rb, line 47
def filter_by_route
  array = []
  data.entry.arrivalsAndDepartures.each do |bus|
    time = OneBusAway::Utilities.convert_time bus.scheduledDepartureTime
    array << { bus.routeShortName => time }
  end
  array
end
get_location(loc) click to toggle source

Uses the google API to git the long and lat of a given location

# File lib/one_bus_away.rb, line 57
def get_location(loc)
  geo = Geocoder.search("#{loc} seattle")
  lat = geo[0].latitude
  lon = geo[0].longitude
  [lon, lat]
end