cta 0.0.1

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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cta.rb +61 -0
  3. metadata +65 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c4266881df811a1d9befd0f66a39c8a834f949e
4
+ data.tar.gz: 5ade72b26a49c4f5a6070183adde7a64e1cbf667
5
+ SHA512:
6
+ metadata.gz: c30285965d7c7146c87a32059be0c15d1e78493a228aadd6bb348255296300e1e6394273509e4ee453aac5e4cfcf6224c0de7deaf71ef4184af77d974929d217
7
+ data.tar.gz: ed7c696cc18c11e325249c67d472709aeebcc89f7cd306b3e31e8e7975731eabae180d89b126cc43b25e0d081369f66c7e874c6ca6d37de4ca89b280bd18211e
data/lib/cta.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'httparty'
2
+
3
+ class Cta
4
+ include HTTParty
5
+ @key = nil
6
+ base_uri 'http://www.ctabustracker.com/bustime/api/v1/'
7
+
8
+ # The current system time for the CTA API
9
+ def self.get_time(params = {})
10
+ response = Cta.send('/gettime')
11
+ return response[:error] ? response : (Time.parse response[:response]['tm'])
12
+ end
13
+
14
+ # A list of all bus routes
15
+ def self.get_routes(params = {})
16
+ response = Cta.send('/getroutes', params)
17
+ return response[:error] ? response : response[:response]['route']
18
+ end
19
+
20
+ # A list of cardinal directions for a given route
21
+ def self.get_directions(params = {})
22
+ response = Cta.send('/getdirections', params)
23
+ return response[:error] ? response : response[:response]['dir']
24
+ end
25
+
26
+ # A list of stops for a given route
27
+ def self.get_stops(params = {})
28
+ response = Cta.send('/getstops', params)
29
+ return response[:error] ? response : response[:response]['stop']
30
+ end
31
+
32
+ # A list of predicted times for a stop
33
+ def self.get_predictions(params = {})
34
+ response = Cta.send('/getpredictions', params)
35
+ return response[:error] ? response : response[:response]['prd']
36
+ end
37
+
38
+ # Next time for a stop
39
+ def self.get_next(params = {})
40
+ response = Cta.get_predictions(params)
41
+ newest = response.kind_of?(Array) ? response.first : response
42
+ (((Time.parse newest['prdtm']) - (Cta.get_time)) / 60).ceil
43
+ end
44
+
45
+ def self.send(route, params = {})
46
+ return { :success => false, :error => "No API key provided." } if @key.nil?
47
+
48
+ params.merge!({ :key => @key })
49
+ response = get(route, { :query => params })
50
+
51
+ return { :success => false, :error => "Could not reach CTA servers." } if response.code != 200
52
+
53
+ return { :success => false, :error => response['bustime_response']['error']['msg'] } if response['bustime_response']['error']
54
+
55
+ { :success => true, :response => response['bustime_response'] }
56
+ end
57
+
58
+ def self.set_key(key)
59
+ @key = key
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Patterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.13.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.13'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.13.1
33
+ description: This gem turns the existing API endpoints of the CTA Tracker into a ruby
34
+ library for getting routes and times.
35
+ email: tom@pattersons.org
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/cta.rb
41
+ homepage: https://rubygems.org/gems/cta
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.3.0
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A gem to access the CTA API.
65
+ test_files: []