citibike-nyc 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70b46019ab97f1e97c545e0976dce7f908a92fc2
4
+ data.tar.gz: 682d567d32f38341595523c6bf67d0e90fa1dc39
5
+ SHA512:
6
+ metadata.gz: 283c9ed07d020f7a2f6e769fcdbb96dad5ae68c6d1010a36568483f7aef0243102d5abd61b603f02d25d92f6e60a2e68ee37d2ab69f939eed411bad8a99929cd
7
+ data.tar.gz: 9193c5d07fed572a113d28c1c9c720b34856b5b06b04d0ff3300b15a30152f3c8812f7a5476587bafca03b15e583f68f23f5b4edaab40cc7215db178ceb2111d
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'citibikenyc'
4
+
5
+ Citibikenyc.new
@@ -0,0 +1 @@
1
+ require_relative './citibikenyc/api'
@@ -0,0 +1,57 @@
1
+ require 'Faraday'
2
+ require 'json'
3
+ require_relative 'feeds'
4
+ require_relative 'station_information'
5
+ require_relative 'station_status'
6
+ require_relative 'region'
7
+ require_relative 'constants'
8
+
9
+ module Citibikenyc
10
+ class Api
11
+
12
+ attr_reader :client, :response, :feeds, :station_status, :station_information, :system_regions, :system_information, :system_alerts
13
+
14
+ def initialize()
15
+ @client = Faraday.new(url: Constants[:service_name])
16
+ @lang = "en"
17
+ get_feeds
18
+ end
19
+
20
+ def get_feeds
21
+ @feeds = response_to_json("/gbfs/gbfs.json")[@lang]["feeds"].map { |feed| Feed.new( feed["name"], feed["url"] ) }
22
+ end
23
+
24
+ def get_station_status
25
+ feed = @feeds.find{ |f| f.name == "station_status"}
26
+ @station_status = response_to_json(feed.url)["stations"].map { |station_status| StationStatus.new(station_status) }
27
+ end
28
+
29
+ def get_station_information
30
+ feed = @feeds.find{ |f| f.name == "station_information"}
31
+ @station_information = response_to_json(feed.url)["stations"].map { |station_information| StationInformation.new(station_information) }
32
+ end
33
+
34
+ def get_system_regions
35
+ feed = @feeds.find{ |f| f.name == "system_regions"}
36
+ @system_regions = response_to_json(feed.url)["regions"].map { |station_status| Region.new(station_status) }
37
+ end
38
+
39
+ def get_system_information
40
+ feed = @feeds.find{ |f| f.name == "station_information"}
41
+ @system_information = response_to_json(feed.url)
42
+ end
43
+
44
+ def get_system_alerts
45
+ feed = @feeds.find{ |f| f.name == "system_alerts"}
46
+ @system_alerts = response_to_json(feed.url)["alertsa"]
47
+ end
48
+
49
+ private
50
+
51
+ def response_to_json(url)
52
+ @response = @client.get(url).body
53
+ JSON.parse(@response)["data"]
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module Citibikenyc
2
+ Constants = {
3
+ service_name: 'https://gbfs.citibikenyc.com'
4
+ }
5
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'constants'
2
+
3
+ class Feed
4
+ attr_reader :name, :url
5
+
6
+ def initialize
7
+ @name = @url = ""
8
+ end
9
+
10
+ def initialize(name, url)
11
+ @name = name
12
+ @url = url
13
+ @url.slice!(Citibikenyc::Constants[:service_name])
14
+ end
15
+
16
+ end
@@ -0,0 +1,12 @@
1
+ class Region
2
+ attr_reader :region_id, :name
3
+
4
+ def initialize
5
+ @region_id = @name = ""
6
+ end
7
+
8
+ def initialize(args)
9
+ @region_id = args["region_id"]
10
+ @name = args["name"]
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ class StationInformation
2
+ attr_reader :station_id, :name, :short_name, :lat, :lon, :region_id, :rental_methods, :capacity, :rental_url, :eightd_has_key_dispenser, :has_kiosk
3
+
4
+ def initialize()
5
+ @station_id = @name = @short_name = @lat = @lon = @region_id = @rental_methods = @capacity = @rental_url = @eightd_has_key_dispenser = @has_kiosk = ""
6
+ end
7
+
8
+ def initialize(args)
9
+ @station_id = args["station_id"]
10
+ @name = args["name"]
11
+ @short_name = args["short_name"]
12
+ @lat = args["lat"]
13
+ @lon = args["lon"]
14
+ @region_id = args["region_id"]
15
+ @rental_methods = args["rental_methods"]
16
+ @capacity = args["capacity"]
17
+ @rental_url = args["rental_url"]
18
+ @eightd_has_key_dispenser = args["eightd_has_key_dispenser"]
19
+ @has_kiosk = args["has_kiosk"]
20
+ end
21
+
22
+ end
@@ -0,0 +1,24 @@
1
+ class StationStatus
2
+ attr_reader :station_id, :name, :short_name, :lat, :lon, :region_id, :rental_methods, :capacity, :rental_url,
3
+ :eightd_has_key_dispenser, :eightd_station_services, :has_kiosk
4
+
5
+ def initialize()
6
+ @station_id = @name = @short_name = @lat = @lon = @region_id = @rental_methods =
7
+ @capacity = @rental_url = @eightd_has_key_dispenser = @eightd_station_services = @has_kiosk = ""
8
+ end
9
+
10
+ def initialize(args)
11
+ @station_id = args["station_id"]
12
+ @name = args["name"]
13
+ @short_name = args["short_name"]
14
+ @lat = args["lat"]
15
+ @lon = args["lon"]
16
+ @region_id = args["region_id"]
17
+ @rental_methods = args["rental_methods"]
18
+ @capacity = args["capacity"]
19
+ @rental_url = args["rental_url"]
20
+ @eightd_has_key_dispenser = args["eightd_has_key_dispenser"]
21
+ @eightd_station_services = args["eightd_station_services"]
22
+ @has_kiosk = args["has_kiosk"]
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citibike-nyc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - mfq
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.0
41
+ description: Citibikenyc is an API Client
42
+ email: softmfq@gmail.com
43
+ executables:
44
+ - citibikenyc
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/citibikenyc
49
+ - lib/citibikenyc.rb
50
+ - lib/citibikenyc/api.rb
51
+ - lib/citibikenyc/constants.rb
52
+ - lib/citibikenyc/feeds.rb
53
+ - lib/citibikenyc/region.rb
54
+ - lib/citibikenyc/station_information.rb
55
+ - lib/citibikenyc/station_status.rb
56
+ homepage: http://rubygems.org/gems/citibikenyc
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.12
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Citibikenyc!
80
+ test_files: []