Class: OneBusAway
- Inherits:
-
Object
- Object
- OneBusAway
- Defined in:
- lib/one_bus_away.rb,
lib/one_bus_away/client.rb,
lib/one_bus_away/version.rb,
lib/one_bus_away/utilities.rb
Overview
Defining the version for this gem
Defined Under Namespace
Constant Summary collapse
- VERSION =
Version for one_bus_away gem
'0.0.4'
Instance Attribute Summary collapse
-
#api_method ⇒ Object
Returns the value of attribute api_method.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#arrivals_and_departures_for_stop(stop) ⇒ Object
get arrivales and departunes for a stop with one arguement.
-
#assign_data ⇒ Object
Assigns the http data to the @data instance variable.
-
#call_api ⇒ Object
Short hand for building the URL, calling the API, and assigning the data to @data.
-
#current_time ⇒ Object
Returns the current time from the One Bus Away System.
-
#filter_by_route ⇒ Object
filter the route by a specific route.
-
#get_location(loc) ⇒ Object
Uses the google API to git the long and lat of a given location.
-
#initialize(options = {}) ⇒ OneBusAway
constructor
A new instance of OneBusAway.
Constructor Details
#initialize(options = {}) ⇒ OneBusAway
Returns a new instance of OneBusAway.
12 13 14 15 |
# File 'lib/one_bus_away.rb', line 12 def initialize( = {}) @api_method = [:api_method] @parameters = [:parameters] end |
Instance Attribute Details
#api_method ⇒ Object
Returns the value of attribute api_method.
9 10 11 |
# File 'lib/one_bus_away.rb', line 9 def api_method @api_method end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/one_bus_away.rb', line 10 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/one_bus_away.rb', line 10 def data @data end |
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
10 11 12 |
# File 'lib/one_bus_away.rb', line 10 def http_response @http_response end |
#parameters ⇒ Object
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/one_bus_away.rb', line 9 def parameters @parameters end |
Instance Method Details
#arrivals_and_departures_for_stop(stop) ⇒ Object
get arrivales and departunes for a stop with one arguement
26 27 28 29 30 31 |
# 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 ⇒ Object
Assigns the http data to the @data instance variable
34 35 36 |
# File 'lib/one_bus_away.rb', line 34 def assign_data @data = client.http_response.data end |
#call_api ⇒ Object
Short hand for building the URL, calling the API, and assigning the data to @data
40 41 42 43 44 |
# File 'lib/one_bus_away.rb', line 40 def call_api @client.build_url @client.get assign_data end |
#current_time ⇒ Object
Returns the current time from the One Bus Away System
18 19 20 21 22 23 |
# 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 ⇒ Object
filter the route by a specific route
47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
Uses the google API to git the long and lat of a given location
57 58 59 60 61 62 |
# 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 |