Class: OneBusAway

Inherits:
Object
  • Object
show all
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

Classes: Client, Utilities

Constant Summary collapse

VERSION =

Version for one_bus_away gem

'0.0.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @api_method = options[:api_method]
  @parameters = options[:parameters]
end

Instance Attribute Details

#api_methodObject

Returns the value of attribute api_method.



9
10
11
# File 'lib/one_bus_away.rb', line 9

def api_method
  @api_method
end

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/one_bus_away.rb', line 10

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/one_bus_away.rb', line 10

def data
  @data
end

#http_responseObject (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

#parametersObject

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_dataObject

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_apiObject

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_timeObject

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_routeObject

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