Class: Citibikenyc::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/citibikenyc/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



14
15
16
17
18
# File 'lib/citibikenyc/api.rb', line 14

def initialize()
  @client = Faraday.new(url: Constants[:service_name])
  @lang = "en"
  get_feeds
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def client
  @client
end

#feedsObject (readonly)

Returns the value of attribute feeds.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def feeds
  @feeds
end

#responseObject (readonly)

Returns the value of attribute response.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def response
  @response
end

#station_informationObject (readonly)

Returns the value of attribute station_information.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def station_information
  @station_information
end

#station_statusObject (readonly)

Returns the value of attribute station_status.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def station_status
  @station_status
end

#system_alertsObject (readonly)

Returns the value of attribute system_alerts.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def system_alerts
  @system_alerts
end

#system_informationObject (readonly)

Returns the value of attribute system_information.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def system_information
  @system_information
end

#system_regionsObject (readonly)

Returns the value of attribute system_regions.



12
13
14
# File 'lib/citibikenyc/api.rb', line 12

def system_regions
  @system_regions
end

Instance Method Details

#get_feedsObject



20
21
22
# File 'lib/citibikenyc/api.rb', line 20

def get_feeds
  @feeds = response_to_json("/gbfs/gbfs.json")[@lang]["feeds"].map { |feed| Feed.new( feed["name"], feed["url"] ) }
end

#get_station_informationObject



29
30
31
32
# File 'lib/citibikenyc/api.rb', line 29

def get_station_information
  feed = @feeds.find{ |f| f.name == "station_information"}
  @station_information = response_to_json(feed.url)["stations"].map { |station_information| StationInformation.new(station_information)  }
end

#get_station_statusObject



24
25
26
27
# File 'lib/citibikenyc/api.rb', line 24

def get_station_status
  feed = @feeds.find{ |f| f.name == "station_status"}
  @station_status = response_to_json(feed.url)["stations"].map { |station_status| StationStatus.new(station_status)  }
end

#get_system_alertsObject



44
45
46
47
# File 'lib/citibikenyc/api.rb', line 44

def get_system_alerts
  feed = @feeds.find{ |f| f.name == "system_alerts"}
  @system_alerts = response_to_json(feed.url)["alertsa"]
end

#get_system_informationObject



39
40
41
42
# File 'lib/citibikenyc/api.rb', line 39

def get_system_information
  feed = @feeds.find{ |f| f.name == "station_information"}
  @system_information = response_to_json(feed.url)
end

#get_system_regionsObject



34
35
36
37
# File 'lib/citibikenyc/api.rb', line 34

def get_system_regions
  feed = @feeds.find{ |f| f.name == "system_regions"}
  @system_regions = response_to_json(feed.url)["regions"].map { |station_status| Region.new(station_status)  }
end