smarta_api_client 0.1.0

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CHANGELOG.md +0 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +71 -0
  8. data/LICENSE +674 -0
  9. data/README.md +78 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/lib/common/data/location/stations.csv +2 -0
  14. data/lib/common/data/schedules/rail/saturday/blue/eastbound.csv +61 -0
  15. data/lib/common/data/schedules/rail/saturday/blue/westbound.csv +60 -0
  16. data/lib/common/data/schedules/rail/saturday/gold/northbound.csv +59 -0
  17. data/lib/common/data/schedules/rail/saturday/gold/southbound.csv +60 -0
  18. data/lib/common/data/schedules/rail/saturday/green/eastbound.csv +59 -0
  19. data/lib/common/data/schedules/rail/saturday/green/westbound.csv +60 -0
  20. data/lib/common/data/schedules/rail/saturday/red/northbound.csv +98 -0
  21. data/lib/common/data/schedules/rail/saturday/red/southbound.csv +59 -0
  22. data/lib/common/data/schedules/rail/sunday/blue/eastbound.csv +61 -0
  23. data/lib/common/data/schedules/rail/sunday/blue/westbound.csv +60 -0
  24. data/lib/common/data/schedules/rail/sunday/gold/northbound.csv +59 -0
  25. data/lib/common/data/schedules/rail/sunday/gold/southbound.csv +60 -0
  26. data/lib/common/data/schedules/rail/sunday/green/eastbound.csv +59 -0
  27. data/lib/common/data/schedules/rail/sunday/green/westbound.csv +60 -0
  28. data/lib/common/data/schedules/rail/sunday/red/northbound.csv +60 -0
  29. data/lib/common/data/schedules/rail/sunday/red/southbound.csv +59 -0
  30. data/lib/common/data/schedules/rail/weekday/blue/eastbound.csv +98 -0
  31. data/lib/common/data/schedules/rail/weekday/blue/westbound.csv +99 -0
  32. data/lib/common/data/schedules/rail/weekday/gold/northbound.csv +99 -0
  33. data/lib/common/data/schedules/rail/weekday/gold/southbound.csv +99 -0
  34. data/lib/common/data/schedules/rail/weekday/green/eastbound.csv +95 -0
  35. data/lib/common/data/schedules/rail/weekday/green/westbound.csv +96 -0
  36. data/lib/common/data/schedules/rail/weekday/red/northbound.csv +99 -0
  37. data/lib/common/data/schedules/rail/weekday/red/southbound.csv +99 -0
  38. data/lib/common/enum.rb +0 -0
  39. data/lib/common/station.rb +25 -0
  40. data/lib/common/stop.rb +25 -0
  41. data/lib/common/train.rb +27 -0
  42. data/lib/marta_api/client.rb +13 -0
  43. data/lib/marta_api/error.rb +6 -0
  44. data/lib/marta_api/rest/api.rb +12 -0
  45. data/lib/marta_api/rest/bus.rb +32 -0
  46. data/lib/marta_api/rest/rail.rb +28 -0
  47. data/lib/marta_api/utils.rb +16 -0
  48. data/lib/smarta_api_client.rb +4 -0
  49. data/lib/smarta_api_client/version.rb +5 -0
  50. data/smarta_api_client.gemspec +47 -0
  51. metadata +208 -0
File without changes
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+
3
+ class Station
4
+ attr_accessor :id, :location, :lines, :last_updated
5
+
6
+ def initialize(system_event)
7
+ @id = system_event[]
8
+ @location = ''
9
+ @lines = system_event[]
10
+ @last_updated = system_event[]
11
+ end
12
+
13
+ def as_json(options={})
14
+ {
15
+ id: @id,
16
+ location: @location,
17
+ lines: @lines,
18
+ last_updated: @last_updated
19
+ }
20
+ end
21
+
22
+ def to_json(*options)
23
+ as_json(*options).to_json(*options)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+
3
+ class Stop
4
+ attr_accessor :id, :location, :routes, :last_updated
5
+
6
+ def initialize(system_event)
7
+ @id = system_event[]
8
+ @location = ''
9
+ @routes = system_event[]
10
+ @last_updated = system_event[]
11
+ end
12
+
13
+ def as_json(options={})
14
+ {
15
+ id: @id,
16
+ location: @location,
17
+ routes: @lines,
18
+ last_updated: @last_updated
19
+ }
20
+ end
21
+
22
+ def to_json(*options)
23
+ as_json(*options).to_json(*options)
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ class Train
4
+ attr_accessor :id, :direction, :line, :destination, :last_updated
5
+
6
+ def initialize(system_event)
7
+ @id = system_event[]
8
+ @direction = system_event[]
9
+ @line = system_event[]
10
+ @destination = system_event[]
11
+ @last_updated = system_event[]
12
+ end
13
+
14
+ def as_json(options={})
15
+ {
16
+ id: @id,
17
+ direction: @direction,
18
+ line: @line,
19
+ destination: @destination,
20
+ last_updated: @last_updated
21
+ }
22
+ end
23
+
24
+ def to_json(*options)
25
+ as_json(*options).to_json(*options)
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require 'marta_api/rest/api'
3
+ require 'dotenv'
4
+
5
+ module MartaApi
6
+ class Client
7
+ include MartaApi::Rest::API
8
+
9
+ def initialize
10
+ Dotenv.load
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MartaApi
4
+ class MartaApiError
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'marta_api/rest/rail'
3
+ require 'marta_api/rest/bus'
4
+
5
+ module MartaApi
6
+ module Rest
7
+ module API
8
+ include MartaApi::Rest::Rail
9
+ include MartaApi::Rest::Bus
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+
6
+ module MartaApi
7
+ module Rest
8
+ module Bus
9
+ include MartaApi::Utils
10
+ def get_bus_schedule
11
+ url = MARTA_API_ROOT + GET_ALL_BUS_SCHEDULES_ENDPOINT + api_key_param
12
+ response = RestClient.get url
13
+ handle_response(response)
14
+ end
15
+
16
+ def get_bus_schedule_by_route(route_id)
17
+ url = MARTA_API_ROOT + (GET_BUS_SCHEDULE_BY_ROUTE_ENDPOINT % route_id) + api_key_param
18
+ response = RestClient.get url
19
+ handle_response(response)
20
+ end
21
+
22
+ def handle_response(response)
23
+ status_code = response.code
24
+ unless (status_code > 199) && (status_code < 299)
25
+ raise MartaApiError, "Unexpected response code (#{status_code}) received from MARTA API."
26
+ end
27
+
28
+ JSON.parse(response.body) unless response.body.empty?
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'marta_api/utils'
6
+
7
+ module MartaApi
8
+ module Rest
9
+ module Rail
10
+ include MartaApi::Utils
11
+
12
+ def get_rail_schedule
13
+ url = MARTA_API_ROOT + GET_RAIL_SCHEDULE_ENDPOINT + api_key_param
14
+ response = RestClient.get url
15
+ handle_response(response)
16
+ end
17
+
18
+ def handle_response(response)
19
+ status_code = response.code
20
+ unless (status_code > 199) && (status_code < 299)
21
+ raise MartaApiError, "Unexpected response code (#{status_code}) received from MARTA API."
22
+ end
23
+
24
+ JSON.parse(response.body) unless response.body.empty?
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MartaApi
4
+ module Utils
5
+ MARTA_API_ROOT = ENV['MARTA_API_ROOT'] || 'http://developer.itsmarta.com'
6
+ MARTA_API_KEY = ENV['MARTA_API_KEY'] || 'test-api-key'
7
+ API_KEY_SUFFIX = '?apiKey=%s'
8
+ GET_RAIL_SCHEDULE_ENDPOINT = '/RealtimeTrain/RestServiceNextTrain/GetRealtimeArrivals'
9
+ GET_ALL_BUS_SCHEDULES_ENDPOINT = '/BRDRestService/RestBusRealTimeService/GetAllBus'
10
+ GET_BUS_SCHEDULE_BY_ROUTE_ENDPOINT = '/BRDRestService/RestBusRealTimeService/GetBusByRoute/%s'
11
+
12
+ def api_key_param
13
+ (API_KEY_SUFFIX % MARTA_API_KEY)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'smarta_api_client/version'
4
+ require 'marta_api/client'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartaApiClient
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'smarta_api_client/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'smarta_api_client'
9
+ spec.version = SmartaApiClient::VERSION
10
+ spec.authors = ['smartatransit']
11
+ spec.email = ['smartatransit@gmail.com']
12
+
13
+ spec.summary = 'A dual client for the MARTA and SMARTA APIs.'
14
+ spec.description = 'A combination basic client for the MARTA RESTful API and an enhanced,
15
+ supplemental client for the SMARTA RESTful API.'
16
+ spec.homepage = 'https://github.com/smartatransit'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/smartatransit/smarta-api-client'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/smartatransit/smarta-api-client/CHANGELOG.md'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.required_ruby_version = '>= 2.5'
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'simplecov', '~> 0.17.1'
43
+ spec.add_development_dependency 'codecov', '~> 0.1.16'
44
+ spec.add_development_dependency 'awesome_print', '~> 1.8'
45
+ spec.add_runtime_dependency 'dotenv', '~> 2.7'
46
+ spec.add_runtime_dependency 'rest-client', '~> 2.1'
47
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smarta_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - smartatransit
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.17.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.17.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.16
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.16
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dotenv
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.7'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
125
+ description: |-
126
+ A combination basic client for the MARTA RESTful API and an enhanced,
127
+ supplemental client for the SMARTA RESTful API.
128
+ email:
129
+ - smartatransit@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".travis.yml"
137
+ - CHANGELOG.md
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - lib/common/data/location/stations.csv
146
+ - lib/common/data/schedules/rail/saturday/blue/eastbound.csv
147
+ - lib/common/data/schedules/rail/saturday/blue/westbound.csv
148
+ - lib/common/data/schedules/rail/saturday/gold/northbound.csv
149
+ - lib/common/data/schedules/rail/saturday/gold/southbound.csv
150
+ - lib/common/data/schedules/rail/saturday/green/eastbound.csv
151
+ - lib/common/data/schedules/rail/saturday/green/westbound.csv
152
+ - lib/common/data/schedules/rail/saturday/red/northbound.csv
153
+ - lib/common/data/schedules/rail/saturday/red/southbound.csv
154
+ - lib/common/data/schedules/rail/sunday/blue/eastbound.csv
155
+ - lib/common/data/schedules/rail/sunday/blue/westbound.csv
156
+ - lib/common/data/schedules/rail/sunday/gold/northbound.csv
157
+ - lib/common/data/schedules/rail/sunday/gold/southbound.csv
158
+ - lib/common/data/schedules/rail/sunday/green/eastbound.csv
159
+ - lib/common/data/schedules/rail/sunday/green/westbound.csv
160
+ - lib/common/data/schedules/rail/sunday/red/northbound.csv
161
+ - lib/common/data/schedules/rail/sunday/red/southbound.csv
162
+ - lib/common/data/schedules/rail/weekday/blue/eastbound.csv
163
+ - lib/common/data/schedules/rail/weekday/blue/westbound.csv
164
+ - lib/common/data/schedules/rail/weekday/gold/northbound.csv
165
+ - lib/common/data/schedules/rail/weekday/gold/southbound.csv
166
+ - lib/common/data/schedules/rail/weekday/green/eastbound.csv
167
+ - lib/common/data/schedules/rail/weekday/green/westbound.csv
168
+ - lib/common/data/schedules/rail/weekday/red/northbound.csv
169
+ - lib/common/data/schedules/rail/weekday/red/southbound.csv
170
+ - lib/common/enum.rb
171
+ - lib/common/station.rb
172
+ - lib/common/stop.rb
173
+ - lib/common/train.rb
174
+ - lib/marta_api/client.rb
175
+ - lib/marta_api/error.rb
176
+ - lib/marta_api/rest/api.rb
177
+ - lib/marta_api/rest/bus.rb
178
+ - lib/marta_api/rest/rail.rb
179
+ - lib/marta_api/utils.rb
180
+ - lib/smarta_api_client.rb
181
+ - lib/smarta_api_client/version.rb
182
+ - smarta_api_client.gemspec
183
+ homepage: https://github.com/smartatransit
184
+ licenses: []
185
+ metadata:
186
+ homepage_uri: https://github.com/smartatransit
187
+ source_code_uri: https://github.com/smartatransit/smarta-api-client
188
+ changelog_uri: https://github.com/smartatransit/smarta-api-client/CHANGELOG.md
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '2.5'
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubygems_version: 3.0.3
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: A dual client for the MARTA and SMARTA APIs.
208
+ test_files: []